public void SaveMeasurementsForTime_BadRequest_ForWrongTimeStamp()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var           metricDataList  = MockData.PrepareMetricDataCollection();
            MeasurementVM measurementdata = new MeasurementVM
            {
                TimeStampStr      = "7878",
                MeasurementValues = metricDataList
            };
            var response       = measurementController.SaveMeasurementsForTime(measurementdata);
            var actualResponse = response as BadRequestErrorMessageResult;


            //Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(actualResponse.Message, "Measurement cannot be added with invalid values");
        }
        public void GetMeasurementStatistic_fromtimeValue_RestNullValues()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            var fromtimeValue = DateTime.UtcNow;

            MockData.SaveMeasurement(fromtimeValue.ToString());

            var totimeValue = DateTime.UtcNow.AddSeconds(3);

            MockData.SaveMeasurement(totimeValue.ToString());

            var response       = measurementController.GetMeasurementStatistics(null, null, fromtimeValue.ToString(), null);
            var actualResponse = response as BadRequestErrorMessageResult;


            //Assert
            Assert.IsNotNull(actualResponse);
            Assert.AreEqual(actualResponse.Message, "Parameters are not valid");
        }
        public void SaveMeasurementsForTime_Created()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var           metricDataList  = MockData.PrepareMetricDataCollection();
            var           timeValue       = DateTime.UtcNow.ToString();
            MeasurementVM measurementdata = new MeasurementVM
            {
                TimeStampStr      = timeValue,
                MeasurementValues = MockData.PrepareMetricDataCollection()
            };
            var response       = measurementController.SaveMeasurementsForTime(measurementdata);
            var actualResponse = response as CreatedNegotiatedContentResult <string>;

            //Assert
            Assert.IsNotNull(actualResponse);
            Assert.IsInstanceOfType(response, typeof(CreatedNegotiatedContentResult <string>));
            Assert.AreEqual(actualResponse.Location, "api/Measurements", "Route should be api/Measurements");
            Assert.AreEqual(actualResponse.Content, timeValue, $"Measurement should be save for {timeValue}");
        }
        public void GetMeasurementsForTime_InRange_ForDate()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var fromtimeValue = DateTime.UtcNow;

            MockData.SaveMeasurement(fromtimeValue.ToString());

            var totimeValue = DateTime.UtcNow.AddSeconds(3);

            MockData.SaveMeasurement(totimeValue.ToString());

            var response       = measurementController.GetMeasurementsForTime(fromtimeValue.ToString(), null);
            var actualResponse = response as OkNegotiatedContentResult <IList <Measurement> >;
            var returnValue    = actualResponse.Content as IList <Measurement>;

            //Assert
            Assert.IsNotNull(actualResponse);
            Assert.IsTrue(returnValue.Count == 2, "Return value should be 2 because Added 2 measurement with in time range");
        }
        public void GetMeasurementsForTime_NoValue_ForDate()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var fromtimeValue = DateTime.UtcNow;

            MockData.SaveMeasurement(fromtimeValue.ToString());



            var totimeValue = DateTime.UtcNow.AddSeconds(3);

            MockData.SaveMeasurement(totimeValue.ToString());

            var response       = measurementController.GetMeasurementsForTime(fromtimeValue.ToString(), totimeValue.AddHours(1).ToString());
            var actualResponse = response as NotFoundResult;

            //Assert
            Assert.IsNotNull(actualResponse);
        }
        public void GetMeasurementStatistic_Statistics()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var fromtimeValue = DateTime.UtcNow;

            MockData.SaveMeasurement(fromtimeValue.ToString());

            var totimeValue = DateTime.UtcNow.AddSeconds(3);

            MockData.SaveMeasurement(totimeValue.ToString());

            var response       = measurementController.GetMeasurementStatistics(MockData.PrepareMetricData(), MockData.PrepareStatsData(), fromtimeValue.ToString(), totimeValue.ToString());
            var actualResponse = response as OkNegotiatedContentResult <IList <Statistic> >;

            var returnResponse = (IList <Statistic>)actualResponse.Content;

            //Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(returnResponse.Count > 1, "It should contain statistics ");
        }
        public void GetMeasurementStatistic_NoData_Statistics()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var fromtimeValue = DateTime.UtcNow;

            MockData.SaveMeasurement(fromtimeValue.ToString());

            var totimeValue = DateTime.UtcNow.AddSeconds(3);

            MockData.SaveMeasurement(totimeValue.ToString());

            var response       = measurementController.GetMeasurementStatistics(MockData.PrepareMetricData(), MockData.PrepareStatsData(), fromtimeValue.AddDays(1).ToString(), totimeValue.AddDays(3).ToString());
            var actualResponse = response as OkNegotiatedContentResult <String>;



            //Assert
            Assert.IsNotNull(actualResponse);
            Assert.AreEqual(actualResponse.Content, "No Data available");
        }