Example #1
0
        public void UT_M_04_Given_ValidMeasurement_When_PostThisMeasurement_Then_ShouldReturnOkCode()
        {
            //Arrange
            var measurement = TestMeasurements.DefaultMeasurement().Build();

            _mockService.Setup(x => x.AddMeasurement(It.IsAny <string>(), measurement));

            //Act
            var response = _controller.PostMeasurement(measurement);


            //Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Example #2
0
        public Measurement CreateMeasurement(string temperature, string light, string moisture)
        {
            Measurement m = new Measurement();

            m.Light       = Double.Parse(light, CultureInfo.InvariantCulture);
            m.Moisture    = Int32.Parse(moisture);
            m.Time        = DateTime.Now;
            m.Temperature = Double.Parse(temperature, CultureInfo.InvariantCulture);

            controller.PostMeasurement(m);

            return(m);
        }
Example #3
0
        public void TestPostMeasurement()
        {
            //Arrange
            var MeasurementRepoMockClass = new Mock <IMeasurementRepo>();
            var measurement = new Measurement {
                Systolic = 131, Diastolic = 85, Category = "Hypertension stage1"
            };

            MeasurementRepoMockClass.Setup(x => x.AddNew(measurement)).Returns(measurement);
            var measurementController = new MeasurementsController(MeasurementRepoMockClass.Object);

            //Act
            Measurement result = measurementController.PostMeasurement(measurement);

            //Assert
            Assert.AreEqual(result.Systolic, 131);
            Assert.AreEqual(result.Diastolic, 85);
            Assert.AreEqual(result.Category, "Hypertension stage1");
        }
        public void MeasurementsController_Post_CreatesMeasurement()
        {
            // arrange isolation
            var id = default(long);

            using (var context = new Context("BlacksmithPress.Diabetes"))
            {
                id = context.Measurements.Any() ? context.Measurements.Max(m => m.Id) + 1 : 1;
            }

            // arrange test
            var controller = new MeasurementsController();
            var expected   = new Measurement
            {
                Timestamp = SystemClock.Instance.Now,
                Subject   = new Person {
                    Id = 2, Name = "Ethan"
                },
                Attribute     = MeasuredAttribute.Glucose,
                Amount        = 150M,
                UnitOfMeasure = UnitOfMeasure.mgdL,
            };

            // act
            var result = controller.PostMeasurement(expected);

            // assert
            using (var context = new Context("BlacksmithPress.Diabetes"))
            {
                var actual = context.Measurements.Find(id);
                expected.Id = id;
                actual.ShouldBe(expected);
            }

            // clean-up
        }