public async Task Then_The_Endpoint_Is_Called_And_Cached_If_Not_In_Cache( string accountType, GetAvailableApiProductsResponse apiResponse, [Frozen] Mock <IApimDeveloperApiClient <ApimDeveloperApiConfiguration> > apimDeveloperApiClient, [Frozen] Mock <ICacheStorageService> cacheStorageService, ApimApiService apimApiService) { //Arrange var expectedGet = new GetAvailableApiProductsRequest(accountType); cacheStorageService .Setup(x => x.RetrieveFromCache <GetAvailableApiProductsResponse>( $"{accountType}-{nameof(GetAvailableApiProductsResponse)}")) .ReturnsAsync((GetAvailableApiProductsResponse)null); apimDeveloperApiClient .Setup(x => x.Get <GetAvailableApiProductsResponse>( It.Is <GetAvailableApiProductsRequest>(c => c.GetUrl.Equals(expectedGet.GetUrl)))) .ReturnsAsync(apiResponse); //Act var actual = await apimApiService.GetAvailableProducts(accountType); //Assert actual.Should().BeEquivalentTo(apiResponse); cacheStorageService.Verify(x => x.SaveToCache($"{accountType}-{nameof(GetAvailableApiProductsResponse)}", apiResponse, 1)); }
public async Task Then_The_Service_Is_Called_And_Data_Returned( GetApiProductQuery query, GetAvailableApiProductsResponse serviceResponse, [Frozen] Mock <IApimApiService> apimApiService, GetApiProductQueryHandler handler) { //Arrange serviceResponse.Products.First().Name = query.ProductName.ToLower(); apimApiService.Setup(x => x.GetAvailableProducts("Documentation")).ReturnsAsync(serviceResponse); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.Product.Should().BeEquivalentTo(serviceResponse.Products.First()); }
public async Task Then_The_Api_Is_Called_And_Data_Returned( GetApiProductSubscriptionsQuery query, GetAvailableApiProductsResponse serviceResponse, GetApiProductSubscriptionsResponse apiSubscriptionsResponse, [Frozen] Mock <IApimApiService> apimApiService, [Frozen] Mock <IApimDeveloperApiClient <ApimDeveloperApiConfiguration> > apiClient, GetApiProductSubscriptionsQueryHandler handler) { apimApiService.Setup(x => x.GetAvailableProducts(query.AccountType)).ReturnsAsync(serviceResponse); apiClient.Setup(x => x.Get <GetApiProductSubscriptionsResponse>( It.Is <GetApiProductSubscriptionsRequest>(c => c.GetUrl.EndsWith($"/{query.AccountIdentifier}")))) .ReturnsAsync(apiSubscriptionsResponse); var actual = await handler.Handle(query, CancellationToken.None); actual.Products.Should().BeEquivalentTo(serviceResponse.Products); actual.Subscriptions.Should().BeEquivalentTo(apiSubscriptionsResponse.Subscriptions); }
public async Task Then_The_Product_And_Subscription_Is_Returned_For_The_Account( GetApiProductSubscriptionQuery subscriptionQuery, GetAvailableApiProductsResponse serviceResponse, GetApiProductSubscriptionsResponse apiSubscriptionsResponse, [Frozen] Mock <IApimApiService> apimApiService, [Frozen] Mock <IApimDeveloperApiClient <ApimDeveloperApiConfiguration> > client, GetApiProductSubscriptionQueryHandler handler) { serviceResponse.Products.First().Id = subscriptionQuery.ProductId; apiSubscriptionsResponse.Subscriptions.First().Name = subscriptionQuery.ProductId; apimApiService.Setup(x => x.GetAvailableProducts(subscriptionQuery.AccountType)).ReturnsAsync(serviceResponse); client.Setup(x => x.Get <GetApiProductSubscriptionsResponse>( It.Is <GetApiProductSubscriptionsRequest>(c => c.GetUrl.EndsWith($"/{subscriptionQuery.AccountIdentifier}")))) .ReturnsAsync(apiSubscriptionsResponse); var actual = await handler.Handle(subscriptionQuery, CancellationToken.None); actual.Product.Should().BeEquivalentTo(serviceResponse.Products.First()); actual.Subscription.Should().BeEquivalentTo(apiSubscriptionsResponse.Subscriptions.First()); }
public async Task Then_The_Item_Is_Retrieved_From_Cache_If_Available_And_Api_Not_Called( string accountType, GetAvailableApiProductsResponse cacheResponse, [Frozen] Mock <IApimDeveloperApiClient <ApimDeveloperApiConfiguration> > apimDeveloperApiClient, [Frozen] Mock <ICacheStorageService> cacheStorageService, ApimApiService apimApiService) { //Arrange cacheStorageService .Setup(x => x.RetrieveFromCache <GetAvailableApiProductsResponse>( $"{accountType}-{nameof(GetAvailableApiProductsResponse)}")) .ReturnsAsync(cacheResponse); //Act var actual = await apimApiService.GetAvailableProducts(accountType); //Assert actual.Should().BeEquivalentTo(cacheResponse); apimDeveloperApiClient .Verify(x => x.Get <GetAvailableApiProductsResponse>( It.IsAny <GetAvailableApiProductsRequest>()), Times.Never); }