public void Return_CorrectMinMaxValues_WhenPassedBooleansAsString(string description)
        {
            var result = ApiDataHelper.GetMinAndMaxRange(description);

            Assert.AreEqual(0, result.MinRange);
            Assert.AreEqual(1, result.MaxRange);
        }
Ejemplo n.º 2
0
        public async Task AddSensors(IReadOnlyList <ApiSensorDetailsDTO> lastApiSensors)
        {
            bool shouldCallSaveChanges = false;

            foreach (var newSensor in lastApiSensors)
            {
                var measureType = await this.Context
                                  .MeasureTypes
                                  .FirstOrDefaultAsync(mt => mt.MeasureUnit == newSensor.MeasureType && !mt.IsDeleted);

                if (measureType != null)
                {
                    var(MinRange, MaxRange) = ApiDataHelper
                                              .GetMinAndMaxRange(newSensor.Description);

                    var icbSensorToAdd = new IcbSensor
                    {
                        Id              = newSensor.ApiSensorId,
                        Description     = newSensor.Description,
                        Tag             = newSensor.Tag,
                        MeasureTypeId   = measureType.Id,
                        PollingInterval = newSensor.MinPollingIntervalInSeconds,
                        MinRangeValue   = MinRange,
                        MaxRangeValue   = MaxRange,
                        CreatedOn       = DateTime.Now
                    };

                    await this.Context.IcbSensors.AddAsync(icbSensorToAdd);

                    if (!shouldCallSaveChanges)
                    {
                        shouldCallSaveChanges = true;
                    }
                }
            }

            if (shouldCallSaveChanges)
            {
                await this.Context.SaveChangesAsync();
            }
        }