예제 #1
0
        public async Task Create_custom_domain_should_response_OK_when_ConsultHttpClient_do_not_fail()
        {
            // Arrange
            var fixture = new Fixture();

            var domainName          = fixture.Create <string>();
            var domainConfiguration = new
            {
                service  = "relay-tracking",
                ruleType = "HttpsOnly"
            };

            var consulHttpClientMock = new Mock <IConsulHttpClient>();

            consulHttpClientMock.Setup(x => x.PutStringAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            using var appFactory = _factory.WithBypassAuthorization();

            var client = appFactory.WithWebHostBuilder((e) => e.ConfigureTestServices(services =>
            {
                services.RemoveAll <IConsulHttpClient>();
                services.AddSingleton(consulHttpClientMock.Object);
            })).CreateClient();

            var request = new HttpRequestMessage(HttpMethod.Put, $"http://localhost/{domainName}");

            request.Content = new StringContent(JsonSerializer.Serialize(domainConfiguration), Encoding.UTF8, "application/json");

            var response = await client.SendAsync(request);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GET_taxinfo_by_cuit_with_a_valid_CUIT_should_not_call_backend_when_UseDummyData_is_true()
        {
            // Arrange
            using var appFactory = _factory.WithBypassAuthorization()
                                   .AddConfiguration(new Dictionary <string, string>()
            {
                ["TaxInfoProvider:UseDummyData"] = "true"
            });
            appFactory.Server.PreserveExecutionContext = true;
            var client = appFactory.CreateClient();

            var request = new HttpRequestMessage(HttpMethod.Get, $"https://custom.domain.com/taxinfo/by-cuit/20-31111111-7");

            // Act
            var response = await client.SendAsync(request);

            // Assert
            _httpTest.ShouldNotHaveMadeACall();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
예제 #3
0
        public async Task GET_taxinfo_by_cuit_with_an_invalid_verification_digit_should_return_400_BadRequest(string cuit)
        {
            // Arrange
            var appFactory = _factory.WithBypassAuthorization();

            appFactory.Server.PreserveExecutionContext = true;
            var client = appFactory.CreateClient();

            // Act
            var response = await client.GetAsync($"https://custom.domain.com/taxinfo/by-cuit/{cuit}");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            _httpTest.ShouldNotHaveMadeACall();

            var content = await response.Content.ReadAsStringAsync();

            var problemDetail = JsonSerializer.Deserialize <JsonElement>(content);

            Assert.Equal("One or more validation errors occurred.", problemDetail.GetProperty("title").GetString());
            Assert.Collection(problemDetail.GetProperty("errors").EnumerateObject(),
                              item =>
            {
                Assert.Equal("cuit", item.Name);
                Assert.Equal(1, item.Value.GetArrayLength());
                Assert.Equal("The CUIT's verification digit is wrong.", item.Value.EnumerateArray().First().GetString());
            });
        }
        public async Task GetInvoices_InexistentClient_ReturnsNotFound(string origin, int clientId)
        {
            // Arrange
            var appFactory = _factory.WithBypassAuthorization();
            var client     = appFactory.CreateClient();

            // Act
            var response = await client.GetAsync($"https://custom.domain.com/accounts/{origin}/{clientId}/invoices");

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            _httpTest.ShouldNotHaveMadeACall();
        }
예제 #5
0
        public async Task GET_taxinfo_by_cuit_with_an_invalid_verification_digit_should_return_400_BadRequest(string cuit)
        {
            // Arrange
            var appFactory = _factory.WithBypassAuthorization();

            appFactory.Server.PreserveExecutionContext = true;
            var client = appFactory.CreateClient();

            // Act
            var response = await client.GetAsync($"https://custom.domain.com/taxinfo/by-cuit/{cuit}");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            _httpTest.ShouldNotHaveMadeACall();

            await AssertCuitErrorMessage("The CUIT's verification digit is wrong.", response);
        }
예제 #6
0
        public async Task GetInvoices_WhenDummyDataIsTrue_ShouldNotCallBackend_ReturnsOk()
        {
            // Arrange
            using (var appFactory = _factory.WithBypassAuthorization())
            {
                appFactory.AddConfiguration(new Dictionary <string, string>
                {
                    ["Invoice:UseDummyData"] = "true"
                });

                var client = appFactory.CreateClient();

                var request = new HttpRequestMessage(HttpMethod.Get, $"https://custom.domain.com/accounts/doppler/1/invoices");

                // Act
                var response = await client.SendAsync(request);

                // Assert
                _httpTest.ShouldNotHaveMadeACall();

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }