Example #1
0
        public static void SaveMeasurement(String timeValue)
        {
            MeasurementsController measurementController = new MeasurementsController();

            MeasurementVM measurementdata = new MeasurementVM
            {
                TimeStampStr      = timeValue,
                MeasurementValues = PrepareMetricDataCollection()
            };
            var response = measurementController.SaveMeasurementsForTime(measurementdata);
        }
        public void SaveMeasurementsForTime_BadRequest_ForNullObject()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act

            MeasurementVM measurementdata = null;
            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 SaveMeasurementsForTime_BadRequest_ForNullMetricData()
        {
            // Arrange
            MeasurementsController measurementController = new MeasurementsController();

            // Act
            MeasurementsRepository.ClearAllMeasurements();

            var           metricDataList  = MockData.PrepareMetricDataCollection();
            MeasurementVM measurementdata = new MeasurementVM
            {
                TimeStampStr      = DateTime.UtcNow.ToString(),
                MeasurementValues = null
            };
            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 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}");
        }