Kanekotic/Unit Test CheatSheet

Created Wed, 02 Mar 2016 09:56:49 +0200 Modified Sun, 05 Dec 2021 10:26:06 +0000

##mstest

links:

##Nunit

links:

##MOQ Example

public interface IFoo {
   public bool DoSomething(string);
}

int calls;
var mock = new Mock<IFoo>();
mock.Setup(foo => foo.DoSomething(It.IsAny<string>())).
         Returns((string s) => s.ToLower())
         .Callback(() => ++calls);

mock.SetupProperty(f => f.Name, "foo");
mock.VerifySet(foo => foo.Name = "foo");

mock.Verify(foo => foo.DoSomething(It.IsAny<string>()), Times.Never());

##Test internal Classes

In assembly info to test internal classes you will need to know the name of the file

[assembly: InternalsVisibleToAttribute("<Project Name>")]