コード例 #1
0
        public static void Register(HttpConfiguration config)
        {
            config.DependencyResolver = new NinjectResolver();

            //config.Services.Replace(typeof(IContentNegotiator),
            //  new CustomNegotiator());

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "Api with extension",
                routeTemplate: "api/{controller}.{ext}/{id}",
                defaults: new {
                id  = RouteParameter.Optional,
                ext = RouteParameter.Optional
            }
                );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            MediaTypeFormatter prodFormatter = new ProductFormatter();

            prodFormatter.AddQueryStringMapping("format", "product",
                                                "application/x.product");
            prodFormatter.AddRequestHeaderMapping("X-UseProductFormat", "true",
                                                  StringComparison.InvariantCultureIgnoreCase, false,
                                                  "application/x.product");
            prodFormatter.AddUriPathExtensionMapping("custom", "application/x.product");
            config.Formatters.Add(prodFormatter);
        }
コード例 #2
0
        [TestCase(PropertyDataType.Boolean, "not a boolean", "Default Localized Text Format")] //Fallback to text
        public void WHEN_Passing_Unknown_PropertyName_For_Boolean_SHOULD_Format_Using_BasePropertyTypeKey(PropertyDataType dataType, object value, string expectedFormatted)
        {
            //Arrange
            ProductFormatter          productFormatter = _container.CreateInstance <ProductFormatter>();
            ProductPropertyDefinition ppd = new ProductPropertyDefinition
            {
                PropertyName = GetRandom.String(32),
                DataType     = PropertyDataType.Boolean
            };

            //Act
            string formatted = productFormatter.FormatValue(ppd, value, GetRandomCulture());

            //Assert
            formatted.Should().BeEquivalentTo(expectedFormatted);
        }
コード例 #3
0
        public void WHEN_Passing_Unknown_PropertyName_For_Unknown_DataType_SHOULD_Fallback_To_BasePropertyTypeKey_For_Text()
        {
            //Arrange
            ProductFormatter          productFormatter = _container.CreateInstance <ProductFormatter>();
            ProductPropertyDefinition ppd = new ProductPropertyDefinition
            {
                PropertyName = GetRandom.String(32),
                DataType     = (PropertyDataType)int.MinValue
            };
            object value = new object();

            //Act
            string formatted = productFormatter.FormatValue(ppd, value, GetRandomCulture());

            //Assert
            formatted.Should().BeEquivalentTo("Default Localized Text Format", "This is the default fallback for unknown DataTypes");
        }
コード例 #4
0
        public void WHEN_Passing_Known_PropertyName_SHOULD_Use_Known_Format(PropertyDataType dataType, string expectedFormatted)
        {
            //Arrange
            ProductFormatter          productFormatter = _container.CreateInstance <ProductFormatter>();
            ProductPropertyDefinition ppd = new ProductPropertyDefinition
            {
                PropertyName = "KnownPropertyName",
                DataType     = dataType
            };
            object value = new object();

            //Act
            string formatted = productFormatter.FormatValue(ppd, value, GetRandomCulture());

            //Assert
            formatted.Should().BeEquivalentTo(expectedFormatted);
        }
コード例 #5
0
ファイル: Tester.cs プロジェクト: perl-easj/OOProg
        public void Run()
        {
            DomainModel dm = new DomainModel();

            // Test of existing report generator
            IReportGenerator irg = new ReportGenerator();

            dm.GenerateReports(irg);

            // Test of new report generator
            ITextElementFormatterFactory teff      = new TextElementFormatterFactoryPadRight();
            IEnumerableCollectionFactory ecf       = new EnumerableCollectionFactorySimple();
            IItemFormatter <Customer>    ifc       = new CustomerFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IItemFormatter <Product>     ifp       = new ProductFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IItemFormatter <ShippingBox> ifsb      = new ShippingBoxFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IReportGenerator             irgBetter = new BetterReportGenerator(ifc, ifp, ifsb, ecf);

            dm.GenerateReports(irgBetter);
        }
コード例 #6
0
        /// <summary>
        /// Generates the kva items that will be used to display the product properties values.  Basically, this
        /// method generates a flat list of key value properties and their possible values.
        /// </summary>
        /// <param name="kvaParam">The GenerateKvaItemsParam</param>
        protected virtual List <KeyVariantAttributeItem> CreateKvaItems(GenerateKvaItemsParam kvaParam)
        {
            var kvas = new List <KeyVariantAttributeItem>();

            if (kvaParam.Product.Variants == null)
            {
                return(kvas);
            }

            var productFormatter = new ProductFormatter(LocalizationProvider, LookupService);

            var properties = kvaParam.ProductDefinition.VariantProperties
                             .Where(v => v.IsKeyVariant)
                             .OrderBy(v => v.KeyVariantOrder)
                             .ThenBy(v => v.DisplayOrder)
                             .ToList();

            foreach (var property in properties)
            {
                //Get Values
                var items = kvaParam.Product.Variants
                            .Where(v => v.Active.GetValueOrDefault())
                            .SelectMany(v => v.PropertyBag.Select(pb => new { Variant = v, PB = pb }))
                            .Where(o => o.PB.Key == property.PropertyName)
                            .GroupBy(o => o.PB.Value)
                            .Select(g => new KeyVariantAttributeItemValue
                {
                    Title = productFormatter.FormatValue(property, g.Key, kvaParam.CultureInfo)
                            ?? (g.Key ?? string.Empty).ToString(),
                    Value             = g.Key,
                    Selected          = false,
                    Disabled          = false,
                    RelatedVariantIds = g.Select(o => o.Variant.Id).ToList()
                })
                            .ToList();

                //Sort
                if (property.DataType == PropertyDataType.Boolean ||
                    property.DataType == PropertyDataType.Text)
                {
                    //Localised Alphabetic Order
                    items = items.OrderBy(i => i.Title)
                            .ThenBy(i => i.Value)
                            .ToList();
                }
                else if (property.DataType == PropertyDataType.Lookup)
                {
                    var lookupValues = kvaParam.ProductLookups
                                       .Where(l => l.LookupName == property.LookupDefinition.LookupName)
                                       .Select(l => l.Values)
                                       .FirstOrDefault() ?? new List <LookupValue>();

                    //Weight Defined SortOrder (with fallback to Alphabetic)
                    items = items.Join(lookupValues, i => i.Value, lv => lv.Value, (i, lv) => new
                    {
                        Item        = i,
                        LookupValue = lv
                    })
                            .OrderBy(o => o.LookupValue.SortOrder)
                            .ThenBy(o => o.Item.Title)
                            .ThenBy(o => o.Item.Value)
                            .Select(o => o.Item)
                            .ToList();
                }
                else
                {
                    //Semantic Order (Numerical or Chronological)
                    items = items.OrderBy(i => i.Value).ToList();
                }

                //Bind Images from LookupValues
                if (property.LookupDefinition != null)
                {
                    string lookupName = property.LookupDefinition.LookupName;
                    items.ForEach(item =>
                                  item.ImageUrl = GetLookupImageUrl(lookupName, item.Value)
                                  );
                }

                //BindSelected
                if (kvaParam.SelectedKvas.TryGetValue(property.PropertyName, out object selectedValue))
                {
                    var item = items.FirstOrDefault(i => i.Value.Equals(selectedValue));
                    if (item != null)
                    {
                        item.Selected = true;
                        item.Disabled = false;
                    }
                }

                //Stock
                kvas.Add(new KeyVariantAttributeItem
                {
                    DisplayName      = property.DisplayName.GetLocalizedValue(kvaParam.CultureInfo.Name) ?? property.PropertyName,
                    PropertyName     = property.PropertyName,
                    PropertyDataType = property.DataType.ToString("g"),
                    Values           = items
                });
            }

            kvas = DisableMissingKvas(kvaParam, kvas);

            return(EnableKvasInStock(kvaParam, kvas));
        }