public void ConfigureContainer(ServiceConfigurationContext context)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            context.Services.AddSingleton <IContentSerializer, JsonContentSerializer>();
            context.Services.AddSingleton <IPropertyManager, PropertyManager>();
            context.Services.AddSingleton <IPropertyNameStrategy, PropertyNameStrategy>();
            context.Services.AddSingleton <IPropertyResolver, PropertyResolver>();
            context.Services.AddSingleton <IUrlHelper, UrlHelperAdapter>();
            context.Services.AddSingleton <IContentJsonSerializer, JsonContentSerializer>();
            context.Services.AddSingleton <IPropertyHandlerService, PropertyHandlerService>();
            context.Services.AddSingleton <IContentSerializerSettings, ContentSerializerSettings>();

            context.Services.AddSingleton <IPropertyHandler <int>, IntPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <bool>, BoolPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <double>, DoublePropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <DateTime>, DateTimePropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <ContentArea>, ContentAreaPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <ContentReference>, ContentReferencePropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <PageReference>, PageReferencePropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <IEnumerable <ContentReference> >, ContentReferenceListPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <LinkItemCollection>, LinkItemCollectionPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <PageType>, PageTypePropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <string>, StringPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <Url>, UrlPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <XhtmlString>, XhtmlStringPropertyHandler>();
            context.Services.AddSingleton <IPropertyHandler <BlockData>, BlockDataPropertyHandler>();

            var stringListPropertyHandler = new StringListPropertyHandler();

            context.Services.AddSingleton <IPropertyHandler <IEnumerable <string> > >(stringListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <ICollection <string> > >(stringListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <IList <string> > >(stringListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <string[]> >(stringListPropertyHandler);
            var intListPropertyHandler = new IntListPropertyHandler();

            context.Services.AddSingleton <IPropertyHandler <IEnumerable <int> > >(intListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <ICollection <int> > >(intListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <IList <int> > >(intListPropertyHandler);
            var dateTimeListPropertyHandler = new DateTimeListPropertyHandler();

            context.Services.AddSingleton <IPropertyHandler <IEnumerable <DateTime> > >(dateTimeListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <ICollection <DateTime> > >(dateTimeListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <IList <DateTime> > >(dateTimeListPropertyHandler);
            var doubleListPropertyHandler = new DoubleListPropertyHandler();

            context.Services.AddSingleton <IPropertyHandler <IEnumerable <double> > >(doubleListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <ICollection <double> > >(doubleListPropertyHandler);
            context.Services.AddSingleton <IPropertyHandler <IList <double> > >(doubleListPropertyHandler);

            var defaultSelectStrategy = new DefaultSelectStrategy();

            context.Services.AddSingleton <ISelectOneStrategy>(defaultSelectStrategy);
            context.Services.AddSingleton <ISelectManyStrategy>(defaultSelectStrategy);

            stopwatch.Stop();
            Trace.WriteLine($"{nameof(ContentSerializerInitalizationModule)} took {stopwatch.ElapsedMilliseconds}ms");
        }
        public void GivenDoubleListProperty_WhenGetStructuredData_ThenReturnsCorrectValue()
        {
            var doubles = new List <double> {
                1000, 2000.50
            };
            var page           = new StandardPageBuilder().WithDoubles(doubles).Build();
            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.TryGetExistingInstance(typeof(IPropertyHandler <IEnumerable <double> >), out var _).Returns(x =>
            {
                x[1] = new DoubleListPropertyHandler(_contentSerializerSettings);
                return(true);
            });
            ServiceLocator.SetLocator(serviceLocator);

            var result = this._sut.GetStructuredData(page, this._contentSerializerSettings);

            result.ShouldContain(x => x.Key.Equals(nameof(StandardPage.Doubles)) && x.Value.Equals(doubles));
        }
 public DoubleListPropertyHandlerTests()
 {
     this._sut = new DoubleListPropertyHandler();
 }
Example #4
0
 public DoubleListPropertyHandlerTests()
 {
     this._sut = new DoubleListPropertyHandler(new ContentSerializerSettings());
 }