コード例 #1
0
        public async Task Get_timeout_initially_then_nothing_from_calling_endpoint_expecting_a_complete_failure()
        {
            // arrange
            handlerMock.Protected()
            .SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .Throws <TimeoutException>()
            .Throws <TimeoutException>()
            .Throws <TimeoutException>();
            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };
            var azure = new AzureIPv4Ranges(httpClient, _mockGenerateFilename.Object);

            // act
            var jsonFile = await azure.GetJsonFile();

            // assert
            Assert.True(jsonFile.IsFailure);
            Assert.Equal("Failed to get a response", AzureIPv4Ranges.FailureToGetAResponseMessage);
            _mockGenerateFilename.Verify(x => x.Create(), Times.Exactly(3));
        }
コード例 #2
0
        public async Task Get_error_code_on_first_attempt_on_calling_endpoint()
        {
            // arrange
            handlerMock.Protected()
            .SetupSequence <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadGateway,
                Content    = new StringContent("[{'id':1,'value':'1'}]"),
            })
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("[{'id':1,'value':'1'}]"),
            });
            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };
            var azure = new AzureIPv4Ranges(httpClient, _mockGenerateFilename.Object);

            // act
            var jsonFile = await azure.GetJsonFile();

            // assert
            Assert.NotEmpty(jsonFile.Value);
            Assert.True(jsonFile.IsSuccess);
            _mockGenerateFilename.Verify(x => x.Create(), Times.Exactly(2));
        }
コード例 #3
0
        public async Task Get_something_back_from_request()
        {
            // arrange
            var azure = new AzureIPv4Ranges(_httpClient, _mockGenerateFilename.Object);

            // act
            var jsonFile = await azure.GetJsonFile();

            // assert
            Assert.NotEmpty(jsonFile.Value);
            Assert.True(jsonFile.IsSuccess);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: garrardkitchen/allow-list
        //https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519

        static async Task Main(string[] args)
        {
            AzureIPv4Ranges iPv4Ranges = new AzureIPv4Ranges(new HttpClient(), new GenerateFilename(DateTime.Now));
            var             ranges     = await iPv4Ranges.GetJsonFile();

            if (ranges.IsSuccess)
            {
                AzureIPv4Parser parser     = new AzureIPv4Parser(ranges.Value);
                NginxConfString confString = new NginxConfString(await parser.Parse());

                var directoryInfo = Directory.CreateDirectory(Output);
                using (var output = new StreamWriter(OutputGithubActionsRunnersConf, false, Encoding.UTF8))
                {
                    await output.WriteAsync(await confString.Create());

                    await output.FlushAsync();
                }
            }
        }