Beispiel #1
0
        public ArticleWrapper Convert(ArticleResponseWrapper articleResponseWrapper)
        {
            var articleWrapper = new ArticleWrapper();

            if (articleResponseWrapper.ArticleResponse.Articles.Count > 0)
            {
                var article = articleResponseWrapper.ArticleResponse.Articles[0];
                articleWrapper.ArticleRef = article.ArticleRef;

                if (articleResponseWrapper.CompanySubscription != null)
                {
                    foreach (var subscriptionPreferenceWrapper in articleResponseWrapper.CompanySubscription.SubscriptionPreferences)
                    {
                        if (article.MetadataCodes != null)
                        {
                            if (article.MetadataCodes.GetCompanyCodes().ContainsKey(subscriptionPreferenceWrapper.EntityCode.ToUpper()) ||
                                article.MetadataCodes.GetCompanyCodes()
                                .ContainsKey(subscriptionPreferenceWrapper.EntityCode.ToLower()))
                            {
                                articleWrapper.Companies.Add(subscriptionPreferenceWrapper.EntityName);
                                articleWrapper.EntityCodes.Add(subscriptionPreferenceWrapper.EntityCode.ToUpper());
                            }
                        }
                    }
                }
            }
            return(articleWrapper);
        }
        public void should_convert_article_response_wrapper_to_article_wrapper()
        {
            var articleResponseWrapper = new ArticleResponseWrapper();

            var articleResponse = MockRepository.GenerateStub <ArticleResponse>();

            articleResponse.Articles = new List <Article> {
                GetArticle()
            };

            var subscriptionPreferenceWrapper = MockRepository.GenerateStub <SubscriptionPreferenceWrapper>();

            subscriptionPreferenceWrapper.EntityCode = "code";
            subscriptionPreferenceWrapper.EntityName = "company";

            var subscriptionWrapper = MockRepository.GenerateStub <SubscriptionWrapper>();

            subscriptionWrapper.SubscriptionPreferences = new List <SubscriptionPreferenceWrapper> {
                subscriptionPreferenceWrapper
            };

            articleResponseWrapper.ArticleResponse     = articleResponse;
            articleResponseWrapper.CompanySubscription = subscriptionWrapper;

            var converter      = new ArticleWrapperConverter();
            var articleWrapper = converter.Convert(articleResponseWrapper);

            Assert.AreEqual(articleWrapper.Companies[0], "company");
            Assert.AreEqual(articleWrapper.EntityCodes[0], "CODE");
            Assert.AreEqual(articleWrapper.ArticleRef, "articleRef");
        }
        public void should_return_empty_article_wrapper_when_there_are_no_articles()
        {
            var articleResponse = new ArticleResponse();
            ArticleResponseWrapper articleResponseWrapper =
                new ArticleResponseWrapper {
                ArticleResponse = articleResponse
            };
            var converter      = new ArticleWrapperConverter();
            var articleWrapper = converter.Convert(articleResponseWrapper);

            Assert.True(articleWrapper.Companies.Count == 0);
            Assert.True(articleWrapper.EntityCodes.Count == 0);
            Assert.IsNull(articleWrapper.ArticleRef);
        }
        public void should_return_article_ref_when_company_subscription_is_not_available()
        {
            var articleResponse = new ArticleResponse();
            var articles        = new List <Article> {
                GetArticle()
            };

            articleResponse.Articles = articles;
            var articleResponseWrapper = new ArticleResponseWrapper {
                ArticleResponse = articleResponse
            };
            var converter = new ArticleWrapperConverter();

            var articleWrapper = converter.Convert(articleResponseWrapper);

            Assert.True(articleWrapper.Companies.Count == 0);
            Assert.True(articleWrapper.EntityCodes.Count == 0);
            Assert.AreEqual(articleWrapper.ArticleRef, "articleRef");
        }
        public void should_return_article_ref_when_metadata_codes_is_not_available()
        {
            var articleResponse = new ArticleResponse();
            var articles        = new List <Article>();
            var article         = GetArticle();

            article.MetadataCodes = null;
            articles.Add(article);
            articleResponse.Articles = articles;
            var articleResponseWrapper = new ArticleResponseWrapper {
                ArticleResponse = articleResponse
            };
            var converter = new ArticleWrapperConverter();

            var articleWrapper = converter.Convert(articleResponseWrapper);

            Assert.True(articleWrapper.Companies.Count == 0);
            Assert.True(articleWrapper.EntityCodes.Count == 0);
            Assert.AreEqual(articleWrapper.ArticleRef, "articleRef");
        }