コード例 #1
0
        public async Task GetJson500Error()
        {
            var mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.GetStatusCode(It.IsAny <WebResponse>())).Returns(HttpStatusCode.InternalServerError);
            mock.Setup(m => m.GetResponseMessage(It.IsAny <WebResponse>())).Returns("Internal server error");
            mock.Setup(m => m.DownloadStringAsync(It.IsAny <string>(), It.IsAny <NameValueCollection>())).Returns(TestUtils.GetExceptionTask <string>(new WebException("Hello")));

            var api = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            await api.GetJsonAsync("Test/Get");
        }
コード例 #2
0
        public async Task GetJson()
        {
            string json = "{\"Test\": \"Result\"}";
            var    mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.DownloadStringAsync(It.IsAny <string>(), It.IsAny <NameValueCollection>())).Returns(TestUtils.GetCompletedTask(json));

            var    api    = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            string result = await api.GetJsonAsync("Test/Get");

            mock.Verify(m => m.DownloadStringAsync($"{BaseUrl}Test/Get", It.Is <NameValueCollection>(c => c.VerifyContains("AuthToken", "ABC"))));
            mock.Verify(m => m.DownloadStringAsync($"{BaseUrl}Test/Get", It.Is <NameValueCollection>(c => c.VerifyContains("TenantId", "123"))));
            Assert.AreEqual(json, result);
        }