protected override void Compose()
        {
            base.Compose();

            var complexEditorConfig = new NestedContentConfiguration
            {
                ContentTypes = new[]
                {
                    new NestedContentConfiguration.ContentType {
                        Alias = "feature"
                    }
                }
            };
            var dataTypeService = new Mock <IDataTypeService>();

            dataTypeService.Setup(x => x.GetDataType(It.IsAny <int>()))
            .Returns((int id) => id == ComplexDataTypeId
                        ? Mock.Of <IDataType>(x => x.Configuration == complexEditorConfig)
                        : Mock.Of <IDataType>());

            var contentTypeService = new Mock <IContentTypeService>();

            contentTypeService.Setup(x => x.GetAll(It.IsAny <int[]>()))
            .Returns(() => new List <IContentType>
            {
                _contentType
            });

            var textService = new Mock <ILocalizedTextService>();

            textService.Setup(x => x.Localize("validation/invalidPattern", It.IsAny <CultureInfo>(), It.IsAny <IDictionary <string, string> >())).Returns(() => "invalidPattern");
            textService.Setup(x => x.Localize("validation/invalidNull", It.IsAny <CultureInfo>(), It.IsAny <IDictionary <string, string> >())).Returns("invalidNull");
            textService.Setup(x => x.Localize("validation/invalidEmpty", It.IsAny <CultureInfo>(), It.IsAny <IDictionary <string, string> >())).Returns("invalidEmpty");

            Composition.RegisterUnique(x => Mock.Of <IDataTypeService>(x => x.GetDataType(It.IsAny <int>()) == Mock.Of <IDataType>()));
            Composition.RegisterUnique(x => dataTypeService.Object);
            Composition.RegisterUnique(x => contentTypeService.Object);
            Composition.RegisterUnique(x => textService.Object);

            Composition.WithCollectionBuilder <DataEditorCollectionBuilder>()
            .Add <TestEditor>()
            .Add <ComplexTestEditor>();
        }
Example #2
0
        public void SetUp()
        {
            var complexEditorConfig = new NestedContentConfiguration
            {
                ContentTypes = new[]
                {
                    new NestedContentConfiguration.ContentType {
                        Alias = "feature"
                    }
                }
            };

            ComplexTestEditor complexTestEditor           = Services.GetRequiredService <ComplexTestEditor>();
            TestEditor        testEditor                  = Services.GetRequiredService <TestEditor>();
            IDataTypeService  dataTypeService             = Services.GetRequiredService <IDataTypeService>();
            IConfigurationEditorJsonSerializer serializer = Services.GetRequiredService <IConfigurationEditorJsonSerializer>();

            var complexDataType = new DataType(complexTestEditor, serializer)
            {
                Name          = "ComplexTest",
                Configuration = complexEditorConfig
            };

            var testDataType = new DataType(testEditor, serializer)
            {
                Name = "Test",
            };

            dataTypeService.Save(complexDataType);
            dataTypeService.Save(testDataType);

            IFileService fileService = Services.GetRequiredService <IFileService>();
            Template     template    = TemplateBuilder.CreateTextPageTemplate();

            fileService.SaveTemplate(template);

            _contentType = ContentTypeBuilder.CreateTextPageContentType(ContentTypeAlias, defaultTemplateId: template.Id);

            // add complex editor
            foreach (IPropertyType pt in _contentType.PropertyTypes)
            {
                pt.DataTypeId = testDataType.Id;
            }

            _contentType.AddPropertyType(
                new PropertyType(_shortStringHelper, "complexTest", ValueStorageType.Ntext)
            {
                Alias = "complex", Name = "Complex", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = complexDataType.Id
            },
                "content", "Content");

            // make them all validate with a regex rule that will not pass
            foreach (IPropertyType prop in _contentType.PropertyTypes)
            {
                prop.ValidationRegExp        = "^donotmatch$";
                prop.ValidationRegExpMessage = "Does not match!";
            }

            IContentTypeService contentTypeService = Services.GetRequiredService <IContentTypeService>();

            contentTypeService.Save(_contentType);
        }