Esempio n. 1
0
        public void GetReturnsEmptyList()
        {
            var mockMappingService = new Mock <IMappingService>();

            mockMappingService.Setup(m => m.GetSymbols()).Returns(new List <string>());

            var controller = new AbsolutesController(mockMappingService.Object);
            var response   = controller.Get();

            Assert.False(response.Any());
        }
Esempio n. 2
0
        public void PatchWithBadRequestBecauseOfNullValue()
        {
            var mapping = "TEST";
            Dictionary <string, object> value = null;
            var mockMappingService            = new Mock <IMappingService>();

            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Patch(mapping, value);

            Assert.IsType <BadRequestResult>(response);
        }
Esempio n. 3
0
        public void GetReturnsListWithItems()
        {
            var mockMappingService = new Mock <IMappingService>();
            var list = new List <string> {
                "DB1", "DB2"
            };

            mockMappingService.Setup(m => m.GetDataBlocks()).Returns(list);
            var controller = new AbsolutesController(mockMappingService.Object);
            var response   = controller.Get();

            Assert.False(list.Except(response).Any());
        }
Esempio n. 4
0
        public void GetWithParamsWithNotFoundRequestResult2()
        {
            var area = "XYZ";
            Dictionary <string, object> expected = null;
            var mockMappingService = new Mock <IMappingService>();

            mockMappingService.Setup(m => m.ReadAbs(It.IsAny <string>(), It.IsAny <string>())).Returns(expected);
            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Get(area, new string[] { "W0" });

            Assert.IsType <NotFoundResult>(response);
        }
Esempio n. 5
0
        public void GetWithParamsWithBadRequestResult()
        {
            var area     = "";
            var expected = new Dictionary <string, object> {
                { area, 0 }
            };
            var mockMappingService = new Mock <IMappingService>();

            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Get(area, new string[] { });

            Assert.IsType <BadRequestResult>(response);
        }
Esempio n. 6
0
        public void PatchOkWrite()
        {
            var mapping            = "TEST";
            var variable           = "Test";
            var value              = 0;
            var mockMappingService = new Mock <IMappingService>();

            mockMappingService.Setup(m => m.WriteAbs(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(true);
            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Patch(mapping, variable, value);

            Assert.IsType <NoContentResult>(response);
        }
Esempio n. 7
0
        public void PatchWithBadRequestBecauseOfEmptyMapping()
        {
            var area    = "";
            var toWrite = new Dictionary <string, object> {
                { "W0", 0 }
            };
            var mockMappingService = new Mock <IMappingService>();

            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Patch(area, toWrite);

            Assert.IsType <BadRequestResult>(response);
        }
Esempio n. 8
0
        public void PatchNOkWrite()
        {
            var mapping = "TEST";
            var value   = new Dictionary <string, object> {
                { "Test", 0 }
            };
            var mockMappingService = new Mock <IMappingService>();

            mockMappingService.Setup(m => m.WriteAbs(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(false);
            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Patch(mapping, value);

            Assert.IsType <StatusCodeResult>(response);
            Assert.Equal((int)HttpStatusCode.NotModified, (response as StatusCodeResult).StatusCode);
        }
Esempio n. 9
0
        public void GetWithParamsWithCorrectObjectRequestResult()
        {
            var area     = "Test";
            var expected = new Dictionary <string, object> {
                { area, 0 }
            };
            var mockMappingService = new Mock <IMappingService>();

            mockMappingService.Setup(m => m.ReadAbs(It.IsAny <string>(), It.IsAny <string>())).Returns(expected);
            var controller = new AbsolutesController(mockMappingService.Object);

            var response = controller.Get(area, new string[] { "W0" });

            Assert.IsType <ObjectResult>(response);
            var or = response as ObjectResult;

            Assert.Equal(expected, or.Value);
        }