I'm doing lots of unit tests lately and I've discovered the Mock.Of<T>
method from Moq
library. After reading this and ultimately that I've found out that Mock.Of
is great option for creating mocked interface instance, but what about regular classes which I can make object myself by new
keyword? Some Nunit
tutorials uses that approach and it's confusing for me because I don't find it useful in any way.
Person newPerson = new Person() { Name = "David", Surname = "Smith" };
Person mockedPerson = Mock.Of<Person>(o => o.Name == "David" && o.Surname == "Smith");
Is there any difference between those two objects? In this case Mock.Of
have any advantage or should I use regular new
keyword to create new instance of class?