public void PersonControllerTest_Get_IsValidListReturned_OK() { List <Person> persons = new List <Person> { new Person { GivenName = "GName1", FamilyName = "FName1", Age = 45, Address = "Address1" }, new Person { GivenName = "GName2", FamilyName = "FName2", Age = 44, Address = "Address2" } }; Mock <IDatabase> mockDatabase = new Mock <IDatabase>(); mockDatabase.Setup(m => m.GetData()).Returns(persons); var sut = new PersonController(mockDatabase.Object); // ACT var results = sut.GetAsync().Result; var resultsList = results.Value.ToList(); // Verify mockDatabase.Verify(m => m.GetData(), Times.Once); Assert.AreEqual(2, resultsList.Count(), "Should have 2 items"); Assert.IsTrue(CompareListsIsSameContent(persons, resultsList), "Did not return correct list"); }
public void PersonControllerTest_Get_NoListReturned_OK() { List <Person> persons = null; Mock <IDatabase> mockDatabase = new Mock <IDatabase>(); mockDatabase.Setup(m => m.GetData()).Returns(persons); var sut = new PersonController(mockDatabase.Object); // ACT var results = sut.GetAsync().Result; // Verify mockDatabase.Verify(m => m.GetData(), Times.Once); Assert.IsNull(results.Value, "A null list should be returned"); }