public void IMediaType_To_MediaTypeDisplay() { // Arrange var mediaType = MediaTypeBuilder.CreateImageMediaType(); MediaTypeBuilder.EnsureAllIds(mediaType, 8888); // Act var result = _sut.Map <MediaTypeDisplay>(mediaType); // Assert Assert.AreEqual(mediaType.Alias, result.Alias); Assert.AreEqual(mediaType.Description, result.Description); Assert.AreEqual(mediaType.Icon, result.Icon); Assert.AreEqual(mediaType.Id, result.Id); Assert.AreEqual(mediaType.Name, result.Name); Assert.AreEqual(mediaType.ParentId, result.ParentId); Assert.AreEqual(mediaType.Path, result.Path); Assert.AreEqual(mediaType.Thumbnail, result.Thumbnail); Assert.AreEqual(mediaType.IsContainer, result.IsContainer); Assert.AreEqual(mediaType.CreateDate, result.CreateDate); Assert.AreEqual(mediaType.UpdateDate, result.UpdateDate); Assert.AreEqual(mediaType.PropertyGroups.Count(), result.Groups.Count()); for (var i = 0; i < mediaType.PropertyGroups.Count(); i++) { Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id); Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name); var propTypes = mediaType.PropertyGroups.ElementAt(i).PropertyTypes; Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count()); for (var j = 0; j < propTypes.Count(); j++) { Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id); Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId); } } Assert.AreEqual(mediaType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); for (var i = 0; i < mediaType.AllowedContentTypes.Count(); i++) { Assert.AreEqual(mediaType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i)); } }
public void IMediaTypeComposition_To_MediaTypeDisplay() { // Arrange var ctMain = MediaTypeBuilder.CreateSimpleMediaType("parent", "Parent"); // not assigned to tab ctMain.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlName", Name = "Slug", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); MediaTypeBuilder.EnsureAllIds(ctMain, 8888); var ctChild1 = MediaTypeBuilder.CreateSimpleMediaType("child1", "Child 1", ctMain, true); ctChild1.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "someProperty", Name = "Some Property", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }, "anotherTab", "Another tab"); MediaTypeBuilder.EnsureAllIds(ctChild1, 7777); var contentType = MediaTypeBuilder.CreateSimpleMediaType("child2", "Child 2", ctChild1, true, "customGroup", "CustomGroup"); // not assigned to tab contentType.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlAlias", Name = "AltUrl", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); MediaTypeBuilder.EnsureAllIds(contentType, 6666); // Act var result = _sut.Map <MediaTypeDisplay>(contentType); // Assert Assert.AreEqual(contentType.Alias, result.Alias); Assert.AreEqual(contentType.Description, result.Description); Assert.AreEqual(contentType.Icon, result.Icon); Assert.AreEqual(contentType.Id, result.Id); Assert.AreEqual(contentType.Name, result.Name); Assert.AreEqual(contentType.ParentId, result.ParentId); Assert.AreEqual(contentType.Path, result.Path); Assert.AreEqual(contentType.Thumbnail, result.Thumbnail); Assert.AreEqual(contentType.IsContainer, result.IsContainer); Assert.AreEqual(contentType.CreateDate, result.CreateDate); Assert.AreEqual(contentType.UpdateDate, result.UpdateDate); Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false)); Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties)); Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false)); var allPropertiesMapped = result.Groups.SelectMany(x => x.Properties).ToArray(); var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray(); var allSourcePropertyIds = contentType.CompositionPropertyTypes.Select(x => x.Id).ToArray(); Assert.AreEqual(contentType.PropertyTypes.Count(), allPropertiesMapped.Count(x => x.Inherited == false)); Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count()); Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds)); Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any())); Assert.IsTrue( result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] { ctMain.Id, ctChild1.Id })); Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); for (var i = 0; i < contentType.AllowedContentTypes.Count(); i++) { Assert.AreEqual(contentType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i)); } }