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

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

            Record expectedRecord = new Record()
            {
                record_id = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedRecord.record_id))
            .Returns(expectedRecord);
            var repository = new TestRecordRepository(mockContext.Object);

            //Act
            var actualStreet = repository.Get(expectedRecord.record_id);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedRecord.record_id
                    ), Times.Once());
            Assert.Equal(expectedRecord, actualStreet);
        }
Ejemplo n.º 2
0
        public void Create_InputStreetInstance_CalledAddMethodOfDBSetWithStreetInstance()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <TimesheetContext>()
                                   .Options;
            var mockContext = new Mock <TimesheetContext>(opt);
            var mockDbSet   = new Mock <DbSet <Record> >();

            mockContext
            .Setup(context =>
                   context.Set <Record>(
                       ))
            .Returns(mockDbSet.Object);
            //EFUnitOfWork uow = new EFUnitOfWork(mockContext.Object);
            var repository = new TestRecordRepository(mockContext.Object);

            Record expectedStreet = new Mock <Record>().Object;

            //Act
            repository.Create(expectedStreet);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Add(
                    expectedStreet
                    ), Times.Once());
        }
Ejemplo n.º 3
0
        public void Delete_InputId_CalledFindAndRemoveMethodsOfDBSetWithCorrectArg()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <TimesheetContext>()
                                   .Options;
            var mockContext = new Mock <TimesheetContext>(opt);
            var mockDbSet   = new Mock <DbSet <Record> >();

            mockContext
            .Setup(context =>
                   context.Set <Record>(
                       ))
            .Returns(mockDbSet.Object);
            //EFUnitOfWork uow = new EFUnitOfWork(mockContext.Object);
            //IStreetRepository repository = uow.Streets;
            var repository = new TestRecordRepository(mockContext.Object);

            Record expectedRecord = new Record()
            {
                record_id = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedRecord.record_id)).Returns(expectedRecord);

            //Act
            repository.Delete(expectedRecord.record_id);

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