public void GetJsonResult_should_return_valid_json_result()
        {
            // Arrange
            var content = new TestContent
            {
                SomeText          = "Some test string containing text.",
                SomeDateTime      = new DateTime(2017, 10, 9, 10, 30, 30),
                SomeListOfStrings = new List <string>
                {
                    "Test string number 1",
                    "Some other test string",
                    "And yet another test string"
                },
                CouldBeNull = null
            };

            // Act
            var result = JsonResultHelper.GetJsonResult(content);

            // Assert
            Assert.NotNull(result);
            Assert.IsInstanceOf <JsonNetResult>(result);
            Assert.NotNull(result.Data);
            Assert.IsInstanceOf <TestContent>(result.Data);
            Assert.AreEqual("application/json", result.ContentType);
            Assert.AreEqual(Encoding.UTF8, result.ContentEncoding);
            Assert.AreEqual(NullValueHandling.Ignore, result.SerializerSettings.NullValueHandling);
            Assert.AreEqual(DateFormatHandling.IsoDateFormat, result.SerializerSettings.DateFormatHandling);
            Assert.IsInstanceOf <CamelCasePropertyNamesContractResolver>(result.SerializerSettings.ContractResolver);
        }
        public async Task <JsonNetResult> GetAll()
        {
            var response = await GetProductCategoriesFromHybrisOcc <HybrisOccProductCategoryApiResponse>();

            if (response == null || response.Error != null)
            {
                if (response != null)
                {
                    LogHybrisOccError("Hybris/OCC error getting product categories", response.Error);
                }

                return(JsonResultHelper.GetJsonResult(GetCustomErrorResponse()));
            }

            if (response.Result == null && response.Error == null)
            {
                return(JsonResultHelper.GetJsonResult(GetCustomErrorResponse()));
            }

            try
            {
                // ReSharper disable once PossibleNullReferenceException
                var list = response.Result?.Facets?.FirstOrDefault(facet => facet.Category == true).Values.Select(productCategory => productCategory.Name).ToList();

                return(JsonResultHelper.GetJsonResult(list));
            }
            catch (ArgumentNullException exception)
            {
                LogHelper.Error <HybrisProductCategoryApiController>("The response from hybris was not as expected.", exception);
                return(JsonResultHelper.GetJsonResult(GetCustomErrorResponse()));
            }
        }
        public ActionResult NotFound()
        {
            Response.StatusCode = 404;
            var response = new ErrorResponse
            {
                StatusCode   = HttpStatusCode.NotFound,
                ErrorMessage = "Not able to find content"
            };

            return(JsonResultHelper.GetJsonResult(response));
        }
示例#4
0
        public ActionResult SettingsMap(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            var publishedContent = model.As <SettingsMapItem>();

            var result = JsonResultHelper.GetJsonResult(publishedContent);

            return(result);
        }
示例#5
0
        public ActionResult LayoutsMap(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var publishedContent = model.As <IPublishedContent>();

            var content = GetLayoutsMap(publishedContent);

            var result = JsonResultHelper.GetJsonResult(content);

            return(result);
        }
示例#6
0
        public ActionResult OccasionsMap(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            var publishedContent = model.As <IPublishedContent>();

            var content = GetOccasionsMap(publishedContent);

            var result = JsonResultHelper.GetJsonResult(content);

            return(result);
        }
示例#7
0
        public ActionResult PagesMap(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            var publishedContent = model.As <IPublishedContent>();

            var checkoutPages = !string.IsNullOrWhiteSpace(Request.QueryString["checkout"]);

            var content = GetPagesMap(publishedContent, checkoutPages);

            var result = JsonResultHelper.GetJsonResult(content);

            return(result);
        }
示例#8
0
        public override ActionResult Index(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            var content = model.As <Layout>();

            if (content.DocumentTypeAlias != "layout")
            {
                return(new HttpNotFoundResult());
            }

            var result = JsonResultHelper.GetJsonResult(content);

            return(result);
        }
        public override ActionResult Index(RenderModel model)
        {
            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            var publishedContent = model.As <IPublishedContent>();

            var content = ResolveComponentContent(publishedContent);

            if (content == null)
            {
                return(new HttpNotFoundResult());
            }

            var result = JsonResultHelper.GetJsonResult(content);

            return(result);
        }
示例#10
0
        public ActionResult All(string rootKey, string languageIsoCode)
        {
            var dictionaryRoot = ApplicationContext.Services.LocalizationService.GetRootDictionaryItems()
                                 .FirstOrDefault(d => string.Equals(d.ItemKey, rootKey, StringComparison.InvariantCultureIgnoreCase));

            if (dictionaryRoot == null)
            {
                return(new HttpNotFoundResult());
            }

            var dictionaryItems =
                ApplicationContext.Services.LocalizationService.GetDictionaryItemChildren(dictionaryRoot.Key);

            var dictionary = dictionaryItems.ToDictionary(
                item => item.ItemKey.Substring(0, item.ItemKey.IndexOf("-", StringComparison.Ordinal)),
                item => item.Translations.Where(x => x.Language.IsoCode == languageIsoCode).Select(x => x.Value).FirstOrDefault()
                );

            return(JsonResultHelper.GetJsonResult(dictionary));
        }