public void SetUp() { MockedDatabaseContext = new Mock <IDatabaseContext>(); MockedMapper = new Mock <IMapper>(); FakeStringRepository = new FakeStringRepository(MockedDatabaseContext.Object, MockedMapper.Object); }
public void SetUp() { MockedDatabaseContext = new Mock<IDatabaseContext>(); MockedMapper = new Mock<IMapper>(); FakeStringRepository = new FakeStringRepository(MockedDatabaseContext.Object, MockedMapper.Object); }
public void ShouldAddItemToDbSet() { const string stringToAdd = "foo"; FakeStringRepository.Create(stringToAdd); CollectionAssert.Contains(FakeStringRepository.FakeSet.Collection, stringToAdd, "String was not added."); }
public void ShouldRemoveStringFromDbSetWhenItIsTheOnlyInstanceInDbSet() { const string stringToDelete = "foot"; FakeStringRepository.FakeSet.Collection = new List <string> { stringToDelete, "hand" }; FakeStringRepository.DeleteSingle(s => s == stringToDelete); Assert.IsTrue(FakeStringRepository.FakeSet.RemoveWasCalled, "Remove should have been called."); }
public void ShouldNotRemoveStringFromDbSetWhenMultipleInstancesExist() { const string stringToDelete = "foot"; FakeStringRepository.FakeSet.Collection = new List <string> { stringToDelete, stringToDelete, "shoulder" }; FakeStringRepository.DeleteSingle(s => s == stringToDelete); Assert.IsFalse(FakeStringRepository.FakeSet.RemoveWasCalled, "Remove should not have been called."); }
public void ShouldNotRemoveStringFromDbSetWhenItDoesNotExist() { const string stringToDelete = "foot"; FakeStringRepository.FakeSet.Collection = new List <string> { "hand", "shoulder", "arm" }; FakeStringRepository.DeleteSingle(s => s == stringToDelete); Assert.IsFalse(FakeStringRepository.FakeSet.RemoveWasCalled, "Remove should not have been called."); }
public void ShouldRemoveItemFromSetAndRethrowWhenSaveChangesThrows() { const string stringToAdd = "foobar"; MockedDatabaseContext.Setup(dc => dc.SaveChanges()).Throws(new Exception()); TestDelegate methodThatShouldThrow = () => FakeStringRepository.Create(stringToAdd); Assert.Throws <Exception>(methodThatShouldThrow, "Create did not rethrow exception."); CollectionAssert.DoesNotContain(FakeStringRepository.FakeSet.Collection, stringToAdd, "String should not have been added."); Assert.IsTrue(FakeStringRepository.FakeSet.RemoveWasCalled, "Object was not removed from the set on exception."); }