예제 #1
0
        public void TestDeleteMeasurement_RepositoryReturnsNull_ShouldNotCallRepositoryDelete(int id, string userId)
        {
            // Arrange
            var mockedMeasurementRepository = new Mock <IRepository <Measurement> >();
            var mockedUnitOfWork            = new Mock <IUnitOfWork>();
            var mockedFactory = new Mock <IMeasurementFactory>();

            var service = new MeasurementService(mockedMeasurementRepository.Object,
                                                 mockedUnitOfWork.Object,
                                                 mockedFactory.Object);

            // Act
            service.DeleteMeasurement(id, userId);

            // Assert
            mockedMeasurementRepository.Verify(r => r.Delete(It.IsAny <Measurement>()), Times.Never);
        }
예제 #2
0
        public void TestDeleteMeasurement_RepositoryReturnsNull_ShouldReturnFalse(int id, string userId)
        {
            // Arrange
            var mockedMeasurementRepository = new Mock <IRepository <Measurement> >();
            var mockedUnitOfWork            = new Mock <IUnitOfWork>();
            var mockedFactory = new Mock <IMeasurementFactory>();

            var service = new MeasurementService(mockedMeasurementRepository.Object,
                                                 mockedUnitOfWork.Object,
                                                 mockedFactory.Object);

            // Act
            var result = service.DeleteMeasurement(id, userId);

            // Assert
            Assert.IsFalse(result);
        }
예제 #3
0
        public void TestDeleteMeasurement_ShouldCallRepositoryGetById(int id, string userId)
        {
            // Arrange
            var mockedMeasurementRepository = new Mock <IRepository <Measurement> >();
            var mockedUnitOfWork            = new Mock <IUnitOfWork>();
            var mockedFactory = new Mock <IMeasurementFactory>();

            var service = new MeasurementService(mockedMeasurementRepository.Object,
                                                 mockedUnitOfWork.Object,
                                                 mockedFactory.Object);

            // Act
            service.DeleteMeasurement(id, userId);

            // Assert
            mockedMeasurementRepository.Verify(r => r.GetById(id), Times.Once);
        }
예제 #4
0
        public void TestDeleteMeasurement_RepositoryReturnsMeasurementWithDifferentUserId_ShouldReturnFalse(int id, string userId)
        {
            // Arrange
            var mockedMeasurementRepository = new Mock <IRepository <Measurement> >();

            mockedMeasurementRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(new Measurement());

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedFactory    = new Mock <IMeasurementFactory>();

            var service = new MeasurementService(mockedMeasurementRepository.Object,
                                                 mockedUnitOfWork.Object,
                                                 mockedFactory.Object);

            // Act
            var result = service.DeleteMeasurement(id, userId);

            // Assert
            Assert.IsFalse(result);
        }
예제 #5
0
        public void TestDeleteMeasurement_RepositoryReturnsMeasurementWithCorrectUserId_ShouldCallUnitOfWorkCommit(int id, string userId)
        {
            // Arrange
            var measurement = new Measurement {
                UserId = userId
            };

            var mockedMeasurementRepository = new Mock <IRepository <Measurement> >();

            mockedMeasurementRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(measurement);

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedFactory    = new Mock <IMeasurementFactory>();

            var service = new MeasurementService(mockedMeasurementRepository.Object,
                                                 mockedUnitOfWork.Object,
                                                 mockedFactory.Object);

            // Act
            service.DeleteMeasurement(id, userId);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Once);
        }