public void WhenInsertCalled_ThenAddsSuperPerson() { // Arrange var superPerson = new SuperPerson() { Id = 1, Allegiance = "A" }; // Note: Moq example marking a call as verifiable, then verifying all at the end var mockEntitySet = new Mock <IEntitySet <SuperPerson> >(); mockEntitySet.Setup(x => x.Add(superPerson)).Verifiable(); var mockContext = new Mock <ISuperDatabaseContext>(); mockContext.Setup(x => x.SuperPeople).Returns(mockEntitySet.Object); ISuperDatabaseContext context = mockContext.Object; SuperRepository target = new SuperRepository(context); // Act target.Insert(superPerson); // Assert mockEntitySet.VerifyAll(); }
public void WhenInsertCalledWithNull_ThenThrows() { // Arrange var mockContext = new Mock <ISuperDatabaseContext>(); ISuperDatabaseContext context = mockContext.Object; SuperRepository target = new SuperRepository(context); // Act target.Insert(null); // Assert }