예제 #1
0
        public async Task <List <DeviceData> > HandleGetDeviceDailyData(string deviceName, DateTime date)
        {
            var humidityTask    = Read(deviceName, date, _parserProvider.GetParser(SensorTypesConsts.Humidity));
            var rainfallTask    = Read(deviceName, date, _parserProvider.GetParser(SensorTypesConsts.Rainfall));
            var temperatureTask = Read(deviceName, date, _parserProvider.GetParser(SensorTypesConsts.Temperature));
            var tasks           = new Task[]
            {
                humidityTask,
                rainfallTask,
                temperatureTask
            };

            await Task.WhenAll(tasks);

            var humidities   = humidityTask.Result;
            var rainfalls    = rainfallTask.Result;
            var temperatures = temperatureTask.Result;

            var result = _deviceDataBuilder.BuildDeviceData(humidities, rainfalls, temperatures);

            if (!result.Any())
            {
                throw new DataNotFoundException();
            }
            return(result);
        }
 private void SetUpDeviceDataBuilder()
 {
     _deviceDataBuilder = Substitute.For <IDeviceDataBuilder>();
     _deviceDataBuilder.BuildDeviceData(_humidityParsedData, _rainfallParsedData, _temperatureParsedData).Returns(_deviceData);
     _deviceDataBuilder.BuildDeviceData(_humidityHistoricalParsedData, _rainfallHistoricalParsedData, _temperatureHistoricalParsedData).Returns(_historicalDeviceData);
 }