Exemple #1
0
        public void TestGetByDate_ThereIsEntry_ShouldReturnCorrectly(string userId, int day, int month, int year)
        {
            // Arrange
            var date        = new DateTime(year, month, day);
            var measurement = new Measurement {
                Date = date, UserId = userId
            };

            var results = new List <Measurement> {
                measurement
            };

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

            mockedMeasurementRepository.Setup(r => r.All).Returns(results.AsQueryable());

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

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

            // Act
            var result = service.GetByDate(userId, date);

            // Assert
            Assert.AreSame(measurement, result);
        }
Exemple #2
0
        public void TestGetByDate_ShouldCallRepositoryAll(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.GetByDate(userId, new DateTime());

            // Assert
            mockedMeasurementRepository.Verify(r => r.All, Times.Once);
        }