Example #1
0
        public ImgurDetectorTest()
        {
            Logger.SetLoggingEnabled(false);
            mMockClient = DefaultMockClient();

            var detectorBuildTask = ImgurDetector.BuildAsync(ClientId, mMockClient);

            detectorBuildTask.Wait();
            mDetector = detectorBuildTask.Result;
        }
Example #2
0
        public void BadStart()
        {
            var httpClient = MockHttpClient.Build("https://api.imgur.com/3")
                             .ExpectHeaderPattern(".*", HttpRequestHeader.Authorization, $"Client-ID {ClientId}")
                             .SetResponse("/credit", new MockHttpResponse {
                StatusCode = HttpStatusCode.GatewayTimeout
            });

            var detectorTask = ImgurDetector.BuildAsync(ClientId, httpClient);

            detectorTask.Wait();
            var detector = detectorTask.Result;

            Assert.Equal(expected: ImageDetectorState.BadNetwork, actual: detector.State);

            Thread.Sleep(4);
            httpClient.SetResponse("/credit", new MockHttpResponse {
                Content = DefaultCreditReponse
            });
            mDetector.CheckStateAsync().Wait();
            Assert.Equal(expected: ImageDetectorState.Good, actual: mDetector.State);
        }