Unit Test CheatSheet

##mstest

links: * assert * collection assert

##Nunit

links: * Attributes * Assertion

##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>")]
Avatar
Code dreamer, Creator of random stuff & sharing wizard

Related

comments powered by Disqus