示例#1
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());
            });
        }
示例#2
0
        public async void UpdateOrderAsyncFail()
        {
            _httpTest
            .RespondWithJson("Status QUEUED is deprecated, use AWAITING_PAYMENT instead", 400);

            await Assert.ThrowsAsync <EcwidConfigException>(() => _client.UpdateOrderAsync(new OrderEntry {
                Email = "*****@*****.**"
            }));

            _httpTest.ShouldNotHaveMadeACall();
        }
示例#3
0
        public async void UpdateOrderAsync_Exception()
        {
            _httpTest
            .RespondWithJson("Status QUEUED is deprecated, use AWAITING_PAYMENT instead", 400);

            var exception = await Assert.ThrowsAsync <ArgumentException>(() =>
                                                                         _client.UpdateOrderAsync(new OrderEntry {
                Email = "*****@*****.**"
            }));

            Assert.Contains("Order number is 0.", exception.Message);

            _httpTest.ShouldNotHaveMadeACall();
        }
示例#4
0
        public async Task can_setup_multiple_responses()
        {
            HttpTest
            .RespondWith("one")
            .RespondWith("two")
            .RespondWith("three");

            HttpTest.ShouldNotHaveMadeACall();

            await "http://www.api.com/1".GetAsync();
            await "http://www.api.com/2".GetAsync();
            await "http://www.api.com/3".GetAsync();

            var calls = HttpTest.CallLog;

            Assert.AreEqual(3, calls.Count);
            Assert.AreEqual("one", await calls[0].Response.GetStringAsync());
            Assert.AreEqual("two", await calls[1].Response.GetStringAsync());
            Assert.AreEqual("three", await calls[2].Response.GetStringAsync());

            HttpTest.ShouldHaveMadeACall();
            HttpTest.ShouldHaveCalled("http://www.api.com/*").WithVerb(HttpMethod.Get).Times(3);
            HttpTest.ShouldNotHaveCalled("http://www.otherapi.com/*");

            // #323 make sure it's a full string match and not a "contains"
            Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveCalled("http://www.api.com/"));
            HttpTest.ShouldNotHaveCalled("http://www.api.com/");
        }
示例#5
0
        public async Task WhenTheRecordIsInDatabase_ItShouldReadFromDatabase()
        {
            // arrange
            using var httpTest = new HttpTest();
            WithDb(context =>
            {
                context.ProblemLabelMappings.Add(new ProblemLabelMapping
                {
                    ProblemId     = 1,
                    OnlineJudgeId = MappingOnlineJudge.UVA,
                    ProblemLabel  = "1001",
                });
                context.SaveChanges();
            });

            using var scope = Factory.Services.CreateScope();
            var manager = scope.ServiceProvider.GetService <ProblemLabelManager>();

            // act
            var res = await manager.ResolveProblemLabel(MappingOnlineJudge.UVA, 1);

            // assert
            res.Should().Be("1001");
            httpTest.ShouldNotHaveMadeACall();
        }
示例#6
0
        public async Task GetOneAsync_AllOk_NoReDownload()
        {
            //arrange

            var httpTest = new HttpTest();

            httpTest.RespondWith("some content");
            var apiCallResult = _fixture.Create <RoverResultModel>();

            foreach (var photo in apiCallResult.photos)
            {
                photo.img_src = "http://path.com/" + photo.img_src; //so the "lastIndexOf" works
            }
            //{"opportunity", "curiosity", "spirit"};
            var date = DateTime.Parse(_settings.Value.Dates[0]);

            _memoryCache.Set("opportunity-" + date, apiCallResult, TimeSpan.FromMinutes(5));
            _memoryCache.Set("curiosity-" + date, apiCallResult, TimeSpan.FromMinutes(5));
            _memoryCache.Set("spirit-" + date, apiCallResult, TimeSpan.FromMinutes(5));

            _proxy.Setup(p => p.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>())).ReturnsAsync(apiCallResult); //good api call
            _file.Setup(f => f.Exists(It.IsAny <string>())).Returns(true);                                                 //file DOEST

            //act
            var result = await _service.GetOneAsync();

            //assert
            Assert.NotNull(result);
            //we never called the api (because it was cached)
            _proxy.Verify(s => s.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never);
            //we checked if the file exists
            _file.Verify(f => f.Exists(It.Is <string>(s => s.EndsWith(result.Url.Split('/', StringSplitOptions.None).Last()))), Times.Once);
            //and since it did not, we downlaod it
            httpTest.ShouldNotHaveMadeACall();
        }
示例#7
0
        public async Task GetOneAsync_ApiCallFailed()
        {
            //arrange

            var httpTest = new HttpTest();

            httpTest.RespondWith("error", status: 500); //simulate failed download
            var apiCallResult = _fixture.Create <RoverResultModel>();

            foreach (var photo in apiCallResult.photos)
            {
                photo.img_src = "http://path.com/" + photo.img_src;                                                         //so the "lastIndexOf" works
            }
            _proxy.Setup(p => p.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>())).ThrowsAsync(new Exception()); //bad api call

            //act
            var result = await _service.GetOneAsync();

            //assert
            Assert.NotNull(result);
            //we called the api
            _proxy.Verify(s => s.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once());
            //we check if we have the file on storage before downloading it
            _file.Verify(f => f.Exists(It.IsAny <string>()), Times.Never);
            //we did a call to try and download
            httpTest.ShouldNotHaveMadeACall();
            Assert.Null(result.Url); //this will show "not found" in the ui
        }
示例#8
0
        public async Task Synchronize_InvalidCachingPreferences_HttpNotInvoked()
        {
            _thumbnailSynchronizer.Get <IPreferencesService>()
            .ThumbnailCachingStrategy
            .Returns(ThumbnailCachingStrategy.NeverCache);

            await _thumbnailSynchronizer.ClassUnderTest.Synchronize(new Set
            {
                Images = new List <Image>
                {
                    new Image
                    {
                        ThumbnailUrl = "THUMBNAIL_URL"
                    }
                }
            }).ConfigureAwait(false);

            _httpTest.ShouldNotHaveMadeACall();
        }
示例#9
0
        public async Task InstallAllMyBricksSeedDatabase_InvalidParameters_ResultIsFalse(string databaseSeedUrl, string targetFolderPath, bool directoryExists)
        {
            _assetManagementService.Get <IDirectory>()
            .Exists(Arg.Any <string>())
            .Returns(directoryExists);

            var result = await _assetManagementService.ClassUnderTest.InstallAllMyBricksSeedDatabase(databaseSeedUrl, targetFolderPath).ConfigureAwait(false);

            Check.That(result).IsFalse();
            _httpTest.ShouldNotHaveMadeACall();
            _assetManagementService.Get <IAssetUncompression>()
            .DidNotReceiveWithAnyArgs()
            .UncompressAsset(Arg.Any <Stream>(), Arg.Any <string>());
        }
        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();
        }
        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);
        }
示例#12
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);
        }
示例#13
0
        public async Task can_setup_multiple_responses()
        {
            HttpTest
            .RespondWith("one")
            .RespondWith("two")
            .RespondWith("three");

            HttpTest.ShouldNotHaveMadeACall();

            await "http://www.api.com/1".GetAsync();
            await "http://www.api.com/2".GetAsync();
            await "http://www.api.com/3".GetAsync();

            var calls = HttpTest.CallLog;

            Assert.AreEqual(3, calls.Count);
            Assert.AreEqual("one", await calls[0].Response.Content.ReadAsStringAsync());
            Assert.AreEqual("two", await calls[1].Response.Content.ReadAsStringAsync());
            Assert.AreEqual("three", await calls[2].Response.Content.ReadAsStringAsync());

            HttpTest.ShouldHaveMadeACall();
            HttpTest.ShouldHaveCalled("http://www.api.com/*").WithVerb(HttpMethod.Get).Times(3);
            HttpTest.ShouldNotHaveCalled("http://www.otherapi.com/*");
        }
示例#14
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);
            }
        }
示例#15
0
 public void ThenTheServiceIsNotContacted()
 {
     _httpClient.ShouldNotHaveMadeACall();
 }
示例#16
0
 public void No_Http_Calls_Were_Made()
 {
     HttpTest.ShouldNotHaveMadeACall();
 }