コード例 #1
0
        public void SetUp()
        {
            MockedDatabaseContext = new Mock <IDatabaseContext>();
            MockedMapper          = new Mock <IMapper>();

            FakeStringRepository = new FakeStringRepository(MockedDatabaseContext.Object, MockedMapper.Object);
        }
コード例 #2
0
ファイル: RepositoryBaseTester.cs プロジェクト: dioptre/nkd
        public void SetUp()
        {
            MockedDatabaseContext = new Mock<IDatabaseContext>();
            MockedMapper = new Mock<IMapper>();

            FakeStringRepository = new FakeStringRepository(MockedDatabaseContext.Object, MockedMapper.Object);
        }
コード例 #3
0
        public void ShouldAddItemToDbSet()
        {
            const string stringToAdd = "foo";

            FakeStringRepository.Create(stringToAdd);

            CollectionAssert.Contains(FakeStringRepository.FakeSet.Collection, stringToAdd, "String was not added.");
        }
コード例 #4
0
        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.");
        }
コード例 #5
0
        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.");
        }
コード例 #6
0
        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.");
        }
コード例 #7
0
        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.");
        }