public void InitializingContentTypesShouldYieldCorrectResult() { //Arrange var types = ContentTypeBuilder.LoadTypes("CodeFirst.Tests").ToList(); //Act var contentTypes = ContentTypeBuilder.InitializeContentTypes(types); //Assert Assert.Collection(contentTypes, (f) => { Assert.Equal("Person", f.ContentType.Name); Assert.Equal("Person", f.ContentType.SystemProperties.Id); Assert.Null(f.ContentType.DisplayField); Assert.Null(f.ContentType.Description); Assert.Equal(3, f.ContentType.Fields.Count); }, (f) => { Assert.Equal("SomethingElse", f.ContentType.Name); Assert.Equal("something", f.ContentType.SystemProperties.Id); Assert.Equal("field1", f.ContentType.DisplayField); Assert.Equal("Some description", f.ContentType.Description); Assert.Equal(6, f.ContentType.Fields.Count); } ); }
public static void RegisterContentTypes() { var configuration = GetConfig(); IEnumerable <IContentType> registeredContentTypes = ServiceLocator.Current.GetAllInstances <IContentType>(); var types = registeredContentTypes.Select(ct => ct.GetType()).Where(c => c.GetTypeInfo().IsClass&& c.GetTypeInfo().GetCustomAttribute <ContentTypeAttribute>() != null).ToList(); var contentTypesToCreate = ContentTypeBuilder.InitializeContentTypes(types, configuration.CamelcaseFieldIdsAutomatically); var createdContentTypes = ContentTypeBuilder.CreateContentTypes(contentTypesToCreate, configuration, ServiceLocator.Current.GetInstance <IContentManagementClient>().Instance).Result; }
public void CreatingContentTypeWithFieldValidationsShouldYieldCorrectResult() { //Arrange var type = typeof(TestClasses.ClassWithAttributes); //Act var contentTypes = ContentTypeBuilder.InitializeContentTypes(new[] { type }); var first = contentTypes.First(); //Assert Assert.Single(contentTypes); Assert.Equal(6, first.ContentType.Fields.Count); Assert.Single(first.ContentType.Fields[2].Validations); Assert.Single(first.ContentType.Fields[2].Items.Validations); Assert.IsType <SizeValidator>(first.ContentType.Fields[2].Validations[0]); Assert.IsType <LinkContentTypeValidator>(first.ContentType.Fields[2].Items.Validations[0]); Assert.Equal("Array", first.ContentType.Fields[2].Type); Assert.Equal("Entry", first.ContentType.Fields[2].Items.LinkType); Assert.Equal("Link", first.ContentType.Fields[2].Items.Type); Assert.Equal("Person", string.Join(",", (first.ContentType.Fields[2].Items.Validations[0] as LinkContentTypeValidator).ContentTypeIds)); Assert.Equal("Text", first.ContentType.Fields[1].Type); Assert.Equal(4, first.ContentType.Fields[1].Validations.Count); Assert.Single(first.ContentType.Fields[4].Validations); Assert.IsType <DateRangeValidator>(first.ContentType.Fields[4].Validations[0]); Assert.Equal(3, first.ContentType.Fields[3].Validations.Count); Assert.IsType <FileSizeValidator>(first.ContentType.Fields[3].Validations[1]); Assert.Null((first.ContentType.Fields[3].Validations[1] as FileSizeValidator).Max); Assert.Equal(1048576, (first.ContentType.Fields[3].Validations[1] as FileSizeValidator).Min); Assert.IsType <ImageSizeValidator>(first.ContentType.Fields[3].Validations[2]); Assert.Null((first.ContentType.Fields[3].Validations[2] as ImageSizeValidator).MaxWidth); Assert.Null((first.ContentType.Fields[3].Validations[2] as ImageSizeValidator).MaxHeight); Assert.Equal(200, (first.ContentType.Fields[3].Validations[2] as ImageSizeValidator).MinWidth); Assert.Equal(200, (first.ContentType.Fields[3].Validations[2] as ImageSizeValidator).MinWidth); Assert.Empty(first.ContentType.Fields[5].Validations); Assert.Single(first.ContentType.Fields[5].Items.Validations); Assert.IsType <LinkContentTypeValidator>(first.ContentType.Fields[5].Items.Validations[0]); Assert.Equal("Array", first.ContentType.Fields[5].Type); Assert.Equal("Entry", first.ContentType.Fields[5].Items.LinkType); Assert.Equal("Link", first.ContentType.Fields[5].Items.Type); Assert.Equal("Person", string.Join(",", (first.ContentType.Fields[5].Items.Validations[0] as LinkContentTypeValidator).ContentTypeIds)); Assert.Collection(first.ContentType.Fields[1].Validations, (f) => { Assert.IsType <UniqueValidator>(f); }, (f) => { Assert.IsType <RangeValidator>(f); }, (f) => { Assert.IsType <InValuesValidator>(f); }, (f) => { Assert.IsType <RegexValidator>(f); } ); }
public void CreatingAContentTypeShouldYieldCorrectAppearances() { //Arrange var type = typeof(TestClasses.ClassWithAttributes); //Act var contentTypes = ContentTypeBuilder.InitializeContentTypes(new[] { type }); var first = contentTypes.First(); //Assert Assert.Single(contentTypes); Assert.Collection(first.InterfaceControls, (i) => { Assert.Equal("rating", i.WidgetId); }, (i) => { Assert.Equal("singleLine", i.WidgetId); } ); }
public void CreatingContentTypeWithValuesShouldYieldCorrectResult() { //Arrange var type = typeof(TestClasses.ClassWithAttributes); //Act var contentTypes = ContentTypeBuilder.InitializeContentTypes(new[] { type }); var first = contentTypes.First(); var firstField = first.ContentType.Fields.First(); var secondField = first.ContentType.Fields.Skip(1).First(); //Assert Assert.Equal("Symbol", firstField.Type); Assert.Equal("Text", secondField.Type); Assert.True(firstField.Omitted); Assert.False(secondField.Omitted); Assert.True(firstField.Disabled); Assert.False(secondField.Disabled); Assert.Equal("fieldOne", firstField.Id); Assert.Equal("Field2", secondField.Id); Assert.Equal("First field", firstField.Name); Assert.Equal("Field2", secondField.Name); }