Example #1
0
        public async Task get_measurements_with_existing_id()
        {
            var repository    = MeasurementContextMocker.GetInMemoryMeasurementsRepository(nameof(get_measurements_with_existing_id));
            var controller    = new MeasurementController(repository);
            var expectedValue = 0.05m;

            var response = await controller.Get(1) as ObjectResult;

            var measurement = response.Value as Measurement;

            Assert.Equal(200, response.StatusCode);
            Assert.Equal(expectedValue, measurement.Value);
        }
Example #2
0
        public async Task get_measurement_with_not_existing_id()
        {
            // Arrange
            var repository      = MeasurementContextMocker.GetInMemoryMeasurementsRepository(nameof(get_measurement_with_not_existing_id));
            var controller      = new MeasurementController(repository);
            var expectedMessage = "The Measurment record couldn't be found";

            // Act
            var response = await controller.Get(10) as ObjectResult;

            // Assert
            Assert.Equal(404, response.StatusCode);
            Assert.Equal(expectedMessage, response.Value);
        }
Example #3
0
        public void GetSuccess()
        {
            //Setup
            var measurementServiceMock = new Mock <IMeasurementService>();
            var measurementServiceList = new List <Measurement>
            {
                new Measurement
                {
                    MeasurementId = 1 //What the query is looking for.
                }
            };
            IQueryable <Measurement> measurementQueryable = measurementServiceList.AsQueryable();

            measurementServiceMock.Setup(x => x.Read()).Returns(measurementQueryable);
            var dataModelMock = new Mock <IDataModel>();

            //Execute
            var target  = new MeasurementController(measurementServiceMock.Object, dataModelMock.Object);
            var results = target.Get();

            //Evalute
            Assert.IsInstanceOf <IQueryable <Measurement> >(results);
        }
Example #4
0
        public void GetSuccess_WithNoRecord()
        {
            //Setup
            var measurementServiceMock = new Mock <IMeasurementService>();
            var measurementServiceList = new List <Measurement>
            {
                new Measurement
                {
                    MeasurementId = 2
                }
            };
            IQueryable <Measurement> measurementQueryable = measurementServiceList.AsQueryable();

            measurementServiceMock.Setup(x => x.Read()).Returns(measurementQueryable);
            var dataModelMock = new Mock <IDataModel>();

            //Execute
            var target  = new MeasurementController(measurementServiceMock.Object, dataModelMock.Object);
            var results = target.Get(1);

            //Evalute
            Assert.IsInstanceOf <SingleResult <Measurement> >(results);
            Assert.IsFalse(results.Queryable.Any());
        }