Exemplo n.º 1
0
        public void TestRepositoryBaseGetById()
        {
            using (var testDbInfo = SetupUtil.CreateFakeDb())
            {
                //Arrange
                Mock <ILog> log = new Mock <ILog>();

                List <Mock <FakeDto> > mockDtos = new List <Mock <FakeDto> >();
                var repo = new FakeRepositoryBase(testDbInfo.ConnectionString, log.Object);
                for (int i = 0; i < 10; i++)
                {
                    Mock <FakeDto> mockDto = new Mock <FakeDto>();
                    mockDto.SetupGet(d => d.Name).Returns("Test Data " + (i + 1));
                    mockDto.SetupProperty(d => d.Id);

                    mockDtos.Add(mockDto);

                    repo.InsertProxy(mockDto.Object);
                }


                //Act
                FakeDto id6 = repo.GetById(6);

                //Assert
                Assert.Equal(6, id6.Id);
                Assert.Equal("Test Data 6", id6.Name);
            }
        }
Exemplo n.º 2
0
        public void TestRepositoryBaseRemoveById()
        {
            using (var testDbInfo = SetupUtil.CreateFakeDb())
            {
                //Arrange
                Mock <ILog> log = new Mock <ILog>();

                List <Mock <FakeDto> > mockDtos = new List <Mock <FakeDto> >();
                var repo = new FakeRepositoryBase(testDbInfo.ConnectionString, log.Object);
                for (int i = 0; i < 10; i++)
                {
                    Mock <FakeDto> mockDto = new Mock <FakeDto>();
                    mockDto.SetupGet(d => d.Name).Returns("Test Data " + (i + 1));
                    mockDto.SetupProperty(d => d.Id);

                    mockDtos.Add(mockDto);

                    repo.InsertProxy(mockDto.Object);
                }


                //Act
                Mock <FakeDto> toRemove   = mockDtos[5];
                bool           success    = repo.RemoveById(toRemove.Object.Id.Value);
                FakeDto        removedDto = repo.GetById(toRemove.Object.Id.Value);

                //Assert

                //Ensure row was actually removed
                Assert.True(success);
                Assert.Null(removedDto);

                //Ensure get removed dto failure was logged
                log.Verify(l => l.WriteLine(It.IsAny <string>(), LogLevel.Error));
            }
        }