コード例 #1
0
        public async void LoadConfigTest()
        {
            FakeResponseHandler fakeConfig = new FakeResponseHandler();

            fakeConfig.AddFakeResponse(
                new Uri($"{ApplicationURLS.Backend}/api/configuration/TestingDevice"),
                new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(mockJsonData)
            });
            RestService restService = new RestService(new HttpClient(fakeConfig), mockTokenAcquisition,
                                                      mockConfiguration);
            DeviceConfigViewController deviceDetailViewController = new DeviceConfigViewController(restService);
            ViewResult viewResult = await deviceDetailViewController.Index("TestingDevice");

            DeviceConfigViewModel model = viewResult.Model as DeviceConfigViewModel;

            Assert.NotNull(model);
            Assert.Equal(1, model.NumberOfPrograms);
            Assert.Single(model.Programs);
            Assert.Equal("TestingDevice", viewResult.ViewData["DeviceID"]);
        }
コード例 #2
0
        public async void IncompleteJsonTest()
        {
            FakeResponseHandler fakeConfig = new FakeResponseHandler();

            fakeConfig.AddFakeResponse(
                new Uri($"{ApplicationURLS.Backend}/api/configuration/TestingDevice"),
                new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(mockIncompleteJsonData)
            });
            RestService restService = new RestService(new HttpClient(fakeConfig), mockTokenAcquisition,
                                                      mockConfiguration);
            DeviceConfigViewController deviceDetailViewController = new DeviceConfigViewController(restService);

            try
            {
                await deviceDetailViewController.Index("TestingDevice");
            }
            catch (Exception e)
            {
                Assert.IsType <JsonReaderException>(e);
            }
        }