private PromotionSearchResult MockPromotionSearchResult() { var result = new PromotionSearchResult(); result.Results = JsonConvert.DeserializeObject <DynamicPromotion[]>(File.OpenText("promotions_mock.json").ReadToEnd(), new ConditionJsonConverter(), new PolymorphJsonConverter()); result.TotalCount = result.Results.Count; return(result); }
private static IMarketingPromoEvaluator GetPromotionEvaluationPolicy(IEnumerable <Promotion> promotions) { var result = new PromotionSearchResult { Results = promotions.ToList() }; var promoSearchServiceMock = new Moq.Mock <IPromotionSearchService>(); promoSearchServiceMock.Setup(x => x.SearchPromotionsAsync(It.IsAny <PromotionSearchCriteria>())).ReturnsAsync(result); return(new BestRewardPromotionPolicy(promoSearchServiceMock.Object)); }
private static IMarketingPromoEvaluator GetPromotionEvaluationPolicy(IEnumerable <Promotion> promotions) { var result = new PromotionSearchResult { Results = promotions.ToList() }; var promoSearchServiceMock = new Mock <IPromotionSearchService>(); promoSearchServiceMock.Setup(x => x.SearchPromotionsAsync(It.IsAny <PromotionSearchCriteria>())).ReturnsAsync(result); var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var platformMemoryCache = new PlatformMemoryCache(memoryCache, Options.Create(new CachingOptions()), new Mock <ILogger <PlatformMemoryCache> >().Object); return(new BestRewardPromotionPolicy(promoSearchServiceMock.Object, platformMemoryCache)); }
private static IMarketingPromoEvaluator GetPromotionEvaluationPolicy(IEnumerable <Promotion> promotions, Mock <IPromotionRewardEvaluator> promotionRewardEvaluatorMock = null) { var result = new PromotionSearchResult { Results = promotions.ToList() }; var promoSearchServiceMock = new Moq.Mock <IPromotionSearchService>(); promoSearchServiceMock.Setup(x => x.SearchPromotionsAsync(It.IsAny <PromotionSearchCriteria>())).ReturnsAsync(result); if (promotionRewardEvaluatorMock == null) { promotionRewardEvaluatorMock = GetPromotionRewardEvaluatorMock(); } return(new CombineStackablePromotionPolicy(promoSearchServiceMock.Object, promotionRewardEvaluatorMock.Object)); }
public async Task PromotionsSearch_AuthorizationSuccess_ReturnPromotionSearchResult() { //Arrange var promotionSearchResult = new PromotionSearchResult { Results = TestPromotions.ToList() }; _mockAuthorization.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsAny <IEnumerable <IAuthorizationRequirement> >())).ReturnsAsync(AuthorizationResult.Success()); _mockPromotionSearch.Setup(x => x.SearchPromotionsAsync(It.IsAny <PromotionSearchCriteria>())).ReturnsAsync(promotionSearchResult); //Act var actual = await _controller.PromotionsSearch(new PromotionSearchCriteria()); var result = actual.ExtractFromOkResult(); //Assert result.Should().NotBeNull(); }