Unit Test CheatSheet





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

My research interests include distributed robotics, mobile computing and programmable matter.