예제 #1
0
        public void TestCreateMeasurement_ShouldCallRepositoryAll(int height,
                                                                  double weightKg,
                                                                  double bodyFatPercent,
                                                                  int chest,
                                                                  int shoulders,
                                                                  int forearm,
                                                                  int arm,
                                                                  int waist,
                                                                  int hips,
                                                                  int thighs,
                                                                  int calves,
                                                                  int neck,
                                                                  int wrist,
                                                                  int ankle,
                                                                  string userId)
        {
            // Arrange
            var date = new DateTime(2, 3, 4);

            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.CreateMeasurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                      calves, neck, wrist, ankle, userId, date);

            // Assert
            mockedMeasurementRepository.Verify(r => r.All, Times.Once);
        }
예제 #2
0
 public CommonController(
     MeasurementService measurementService,
     ConholdateService conholdateService,
     StorageService storageService,
     ILoggerFactory loggerFactory
     )
 {
     this.storageService    = storageService;
     this.conholdateService = conholdateService;
     error2forum            = measurementService.CreateMeasurement(ThreeDApp.Common);
     logger = loggerFactory.CreateLogger <CommonController>();
 }
        public AsposeAppControllerBase(MeasurementService measurementService,
                                       StorageService storageService,
                                       ILoggerFactory loggerFactory,
                                       ThreeDApp app,
                                       StatsService statsService
                                       )
        {
            this.app           = app;
            this.statsService  = statsService;
            measurement        = measurementService.CreateMeasurement(app);
            _storageRepository = storageService.GetRepository(app.ToString().ToLower());


            _logger = loggerFactory.CreateLogger(GetType());
        }
예제 #4
0
        public void TestCreateMeasurement_RepositoryReturnsMeasurement_ShouldNotCallFactoryCreateMeasurement(int height,
                                                                                                             double weightKg,
                                                                                                             double bodyFatPercent,
                                                                                                             int chest,
                                                                                                             int shoulders,
                                                                                                             int forearm,
                                                                                                             int arm,
                                                                                                             int waist,
                                                                                                             int hips,
                                                                                                             int thighs,
                                                                                                             int calves,
                                                                                                             int neck,
                                                                                                             int wrist,
                                                                                                             int ankle,
                                                                                                             string userId)
        {
            // Arrange
            var date = new DateTime(2, 3, 4);

            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
            service.CreateMeasurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                      calves, neck, wrist, ankle, userId, date);

            // Assert
            mockedFactory.Verify(f => f.CreateMeasurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                                          calves, neck, wrist, ankle, userId, date),
                                 Times.Never);
        }
예제 #5
0
        public async Task <IHttpActionResult> CreateMeasurement(CreateMeasurement model)
        {
            //check if model is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            MeasurementService service = CreateMeasurementService();

            if (await service.CreateMeasurement(model) == false)
            {
                return(InternalServerError());
            }

            return(Ok());
        }
예제 #6
0
        public void TestCreateMeasurement_ShouldReturnCorrectly(int height,
                                                                double weightKg,
                                                                double bodyFatPercent,
                                                                int chest,
                                                                int shoulders,
                                                                int forearm,
                                                                int arm,
                                                                int waist,
                                                                int hips,
                                                                int thighs,
                                                                int calves,
                                                                int neck,
                                                                int wrist,
                                                                int ankle,
                                                                string userId)
        {
            // Arrange,
            var date = new DateTime(2, 3, 4);

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

            var measurement = new Measurement();

            var mockedFactory = new Mock <IMeasurementFactory>();

            mockedFactory.Setup(f => f.CreateMeasurement(It.IsAny <int>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <int>(), It.IsAny <int>(),
                                                         It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(),
                                                         It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>()))
            .Returns(measurement);

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

            // Act
            var result = service.CreateMeasurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                                   calves, neck, wrist, ankle, userId, date);

            // Assert
            Assert.AreSame(measurement, result);
        }
 public Task Create([FromBody] CreateMeasurementDto dto)
 {
     return(_measurementService.CreateMeasurement(dto.DeviceUuid, dto.Temperature, dto.Humidity));
 }