Ejemplo n.º 1
0
        public void Get_InputId_CalledFindMethodOfDBSetWithCorrectId()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <postContext>()
                                   .Options;
            var mockContext = new Mock <postContext>(opt);
            var mockDbSet   = new Mock <DbSet <postoffice> >();

            mockContext
            .Setup(context =>
                   context.Set <postoffice>(
                       ))
            .Returns(mockDbSet.Object);

            postoffice expectedpostofffice = new postoffice()
            {
                id = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedpostofffice.id))
            .Returns(expectedpostofffice);
            var repository = new TestpostoffficeRepository(mockContext.Object);

            //Act
            var actualpostofffice = repository.Get(expectedpostofffice.id);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedpostofffice.id
                    ), Times.Once());
            Assert.Equal(expectedpostofffice, actualpostofffice);
        }
Ejemplo n.º 2
0
        IpostofficeService GetpostofficeService()
        {
            var mockContext        = new Mock <IUnitOfWork>();
            var expectedpostoffice = new postoffice()
            {
                id = 1, Name = "testN", Address = "testD"
            };
            var mockDbSet = new Mock <IpostofficeRepository>();

            mockDbSet.Setup(z =>
                            z.Find(
                                It.IsAny <Func <postoffice, bool> >(),
                                It.IsAny <int>(),
                                It.IsAny <int>()))
            .Returns(
                new List <postoffice>()
            {
                expectedpostoffice
            }
                );
            mockContext
            .Setup(context =>
                   context.postoffices)
            .Returns(mockDbSet.Object);

            IpostofficeService postofficeService = new postofficeService(mockContext.Object);

            return(postofficeService);
        }
Ejemplo n.º 3
0
        public void Delete_InputExistpostofficeId_Removed()
        {
            // Arrange
            int                   expectedListCount = 0;
            var                   context           = SqlLiteInMemoryContext();
            EFUnitOfWork          uow        = new EFUnitOfWork(context);
            IpostofficeRepository repository = uow.postoffices;
            postoffice            postoffice = new postoffice()
            {
                //Id = 1,
                id      = 5,
                Name    = "test",
                Address = "testD"
            };

            context.postoffices.Add(postoffice);
            context.SaveChanges();

            //Act
            repository.Delete(postoffice.id);
            uow.Save();
            var factpostofficeCount = context.postoffices.Count();

            // Assert
            Assert.Equal(expectedListCount, factpostofficeCount);
        }
Ejemplo n.º 4
0
        public void Get_InputExistpostofficeId_Returnpostoffice()
        {
            // Arrange
            var                   context            = SqlLiteInMemoryContext();
            EFUnitOfWork          uow                = new EFUnitOfWork(context);
            IpostofficeRepository repository         = uow.postoffices;
            postoffice            expectedpostoffice = new postoffice()
            {
                //Id = 1,
                id      = 5,
                Name    = "test",
                Address = "testD"
            };

            context.postoffices.Add(expectedpostoffice);
            context.SaveChanges();

            //Act
            var factpostoffice = repository.Get(expectedpostoffice.id);

            // Assert
            Assert.Equal(expectedpostoffice, factpostoffice);
        }
Ejemplo n.º 5
0
        public void Create_InputpostofficeWithId0_SetpostofficeId1()
        {
            // Arrange
            int                   expectedListCount = 1;
            var                   context           = SqlLiteInMemoryContext();
            EFUnitOfWork          uow        = new EFUnitOfWork(context);
            IpostofficeRepository repository = uow.postoffices;

            postoffice postoffice = new postoffice()
            {
                id      = 5,
                Name    = "test",
                Address = "testD"
            };

            //Act
            repository.Create(postoffice);
            uow.Save();
            var factListCount = context.postoffices.Count();

            // Assert
            Assert.Equal(expectedListCount, factListCount);
        }
Ejemplo n.º 6
0
        public void Delete_InputId_CalledFindAndRemoveMethodsOfDBSetWithCorrectArg()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <postContext>()
                                   .Options;
            var mockContext = new Mock <postContext>(opt);
            var mockDbSet   = new Mock <DbSet <postoffice> >();

            mockContext
            .Setup(context =>
                   context.Set <postoffice>(
                       ))
            .Returns(mockDbSet.Object);
            //EFUnitOfWork uow = new EFUnitOfWork(mockContext.Object);
            //IpostoffficeRepository repository = uow.postofffices;
            var repository = new TestpostoffficeRepository(mockContext.Object);

            postoffice expectedpostofffice = new postoffice()
            {
                id = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedpostofffice.id)).Returns(expectedpostofffice);

            //Act
            repository.Delete(expectedpostofffice.id);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedpostofffice.id
                    ), Times.Once());
            mockDbSet.Verify(
                dbSet => dbSet.Remove(
                    expectedpostofffice
                    ), Times.Once());
        }