public void Get_Paged_Items() { IScopeProvider sp = ScopeProvider; using (IScope scope = sp.CreateScope()) { var repo = new AuditRepository((IScopeAccessor)sp, _logger); for (int i = 0; i < 100; i++) { repo.Save(new AuditItem(i, AuditType.New, -1, UmbracoObjectTypes.Document.GetName(), $"Content {i} created")); repo.Save(new AuditItem(i, AuditType.Publish, -1, UmbracoObjectTypes.Document.GetName(), $"Content {i} published")); } scope.Complete(); } using (IScope scope = sp.CreateScope()) { var repo = new AuditRepository((IScopeAccessor)sp, _logger); IEnumerable <IAuditItem> page = repo.GetPagedResultsByQuery(sp.CreateQuery <IAuditItem>(), 0, 10, out long total, Direction.Descending, null, null); Assert.AreEqual(10, page.Count()); Assert.AreEqual(200, total); } }
public void Can_Perform_Query_On_ContentTypeRepository_Sort_By_Name() { IContentType contentType; // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; contentType = repository.Get(_textpageContentType.Id); ContentType child1 = ContentTypeBuilder.CreateSimpleContentType("abc", "abc", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child1); ContentType child3 = ContentTypeBuilder.CreateSimpleContentType("zyx", "zyx", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child3); ContentType child2 = ContentTypeBuilder.CreateSimpleContentType("a123", "a123", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child2); scope.Complete(); } using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IEnumerable <IContentType> contentTypes = repository.Get(provider.CreateQuery <IContentType>().Where(x => x.ParentId == contentType.Id)); // Assert Assert.That(contentTypes.Count(), Is.EqualTo(3)); Assert.AreEqual("a123", contentTypes.ElementAt(0).Name); Assert.AreEqual("abc", contentTypes.ElementAt(1).Name); Assert.AreEqual("zyx", contentTypes.ElementAt(2).Name); } }
public void SingleShadow() { var taskHelper = new TaskHelper(Mock.Of <ILogger <TaskHelper> >()); IScopeProvider scopeProvider = ScopeProvider; bool isThrown = false; using (IScope scope = scopeProvider.CreateScope(scopeFileSystems: true)) { // This is testing when another thread concurrently tries to create a scoped file system // because at the moment we don't support concurrent scoped filesystems. Task t = taskHelper.ExecuteBackgroundTask(() => { // ok to create a 'normal' other scope using (IScope other = scopeProvider.CreateScope()) { other.Complete(); } // not ok to create a 'scoped filesystems' other scope // we will get a "Already shadowing." exception. Assert.Throws <InvalidOperationException>(() => { using IScope other = scopeProvider.CreateScope(scopeFileSystems: true); }); isThrown = true; return(Task.CompletedTask); }); Task.WaitAll(t); } Assert.IsTrue(isThrown); }
public void CanSaveAndGet() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { IRedirectUrlRepository repo = CreateRepository(provider); var rurl = new RedirectUrl { ContentKey = _textpage.Key, Url = "blah" }; repo.Save(rurl); scope.Complete(); Assert.AreNotEqual(0, rurl.Id); } using (IScope scope = provider.CreateScope()) { IRedirectUrlRepository repo = CreateRepository(provider); IRedirectUrl rurl = repo.GetMostRecentUrl("blah"); scope.Complete(); Assert.IsNotNull(rurl); Assert.AreEqual(_textpage.Id, rurl.ContentId); } }
public void Get_Paged_Items_By_User_Id_With_Query_And_Filter() { IScopeProvider sp = ScopeProvider; using (IScope scope = sp.CreateScope()) { var repo = new AuditRepository((IScopeAccessor)sp, _logger); for (int i = 0; i < 100; i++) { repo.Save(new AuditItem(i, AuditType.New, -1, UmbracoObjectTypes.Document.GetName(), $"Content {i} created")); repo.Save(new AuditItem(i, AuditType.Publish, -1, UmbracoObjectTypes.Document.GetName(), $"Content {i} published")); } scope.Complete(); } using (IScope scope = sp.CreateScope()) { var repo = new AuditRepository((IScopeAccessor)sp, _logger); IQuery <IAuditItem> query = sp.CreateQuery <IAuditItem>().Where(x => x.UserId == -1); try { ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; IEnumerable <IAuditItem> page = repo.GetPagedResultsByQuery( query, 0, 10, out long total, Direction.Descending, new[] { AuditType.Publish }, sp.CreateQuery <IAuditItem>() .Where(x => x.UserId > -2)); Assert.AreEqual(10, page.Count()); Assert.AreEqual(100, total); } finally { ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } }
public void Can_Perform_Update_On_MediaTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaTypeRepository repository = CreateRepository(provider); MediaType videoMediaType = MediaTypeBuilder.CreateNewMediaType(); repository.Save(videoMediaType); // Act IMediaType mediaType = repository.Get(videoMediaType.Id); mediaType.Thumbnail = "Doc2.png"; mediaType.PropertyGroups["media"].PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "subtitle") { Name = "Subtitle", Description = "Optional Subtitle", Mandatory = false, SortOrder = 1, DataTypeId = -88 }); repository.Save(mediaType); bool dirty = ((MediaType)mediaType).IsDirty(); // Assert Assert.That(mediaType.HasIdentity, Is.True); Assert.That(dirty, Is.False); Assert.That(mediaType.Thumbnail, Is.EqualTo("Doc2.png")); Assert.That(mediaType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True); } }
public void Can_Perform_Get_By_Iso_Code_On_LanguageRepository() { IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { LanguageRepository repository = CreateRepository(provider); var au = CultureInfo.GetCultureInfo("en-AU"); ILanguage language = new Language(au.Name, au.EnglishName) { FallbackLanguageId = 1 }; repository.Save(language); // re-get language = repository.GetByIsoCode(au.Name); // Assert Assert.That(language, Is.Not.Null); Assert.That(language.HasIdentity, Is.True); Assert.That(language.CultureName, Is.EqualTo(au.EnglishName)); Assert.That(language.IsoCode, Is.EqualTo(au.Name)); Assert.That(language.FallbackLanguageId, Is.EqualTo(1)); } }
public void Can_Perform_Add_On_LanguageRepository_With_New_Default() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { LanguageRepository repository = CreateRepository(provider); ILanguage languageBR = new Language("pt-BR", "Portuguese (Brazil)") { IsDefault = true, IsMandatory = true }; repository.Save(languageBR); var languageEN = new Language("en-AU", "English (Australia)"); repository.Save(languageEN); Assert.IsTrue(languageBR.IsDefault); Assert.IsTrue(languageBR.IsMandatory); // Act var languageNZ = new Language("en-NZ", "English (New Zealand)") { IsDefault = true, IsMandatory = true }; repository.Save(languageNZ); languageBR = repository.Get(languageBR.Id); // Assert Assert.IsFalse(languageBR.IsDefault); Assert.IsTrue(languageNZ.IsDefault); } }
public void GetEntityNotifications() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var repo = new NotificationsRepository((IScopeAccessor)provider); var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; ScopeAccessor.AmbientScope.Database.Insert(node1); IEntity entity1 = Mock.Of <IEntity>(e => e.Id == node1.NodeId); var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; ScopeAccessor.AmbientScope.Database.Insert(node2); IEntity entity2 = Mock.Of <IEntity>(e => e.Id == node2.NodeId); for (int i = 0; i < 10; i++) { var userDto = new UserDto { Email = "test" + i, Login = "******" + i, Password = "******", UserName = "******" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of <IUser>(e => e.Id == userDto.Id); Notification notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture)); } IEnumerable <Notification> notifications = repo.GetEntityNotifications(entity1); Assert.AreEqual(5, notifications.Count()); } }
public void Delete_By_User() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var repo = new NotificationsRepository((IScopeAccessor)provider); var userDto = new UserDto { Email = "test", Login = "******", Password = "******", UserName = "******", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of <IUser>(e => e.Id == userDto.Id); IUser userAdmin = Mock.Of <IUser>(e => e.Id == Constants.Security.SuperUserId); for (int i = 0; i < 10; i++) { var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of <IEntity>(e => e.Id == node.NodeId); Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture)); } int delCount = repo.DeleteNotifications(userAdmin); Assert.AreEqual(5, delCount); } }
public void QueryMedia_ContentTypeAliasFilter() { // we could support this, but it would require an extra join on the query, // and we don't absolutely need it now, so leaving it out for now // Arrange IMediaType folderMediaType = MediaTypeService.Get(1031); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act for (int i = 0; i < 10; i++) { Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); repository.Save(folder); } string[] types = new[] { "Folder" }; IQuery <IMedia> query = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentType.Alias)); IEnumerable <IMedia> result = repository.Get(query); // Assert Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11)); } }
public void Get_By_Name() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); ILanguage lang = LanguageRepository.GetByIsoCode("en-AU"); IContent content = DocumentRepository.Get(contentId); for (int i = 0; i < 10; i++) { var domain = (IDomain) new UmbracoDomain("test" + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id }; repo.Save(domain); } IDomain found = repo.GetByName("test1.com"); Assert.IsNotNull(found); } }
public void Can_Delete() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); ILanguage lang = LanguageRepository.GetByIsoCode("en-AU"); IContent content = DocumentRepository.Get(contentId); var domain = (IDomain) new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id }; repo.Save(domain); repo.Delete(domain); // re-get domain = repo.Get(domain.Id); Assert.IsNull(domain); } }
public void Cant_Create_Duplicate_Domain_Name() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); ILanguage lang = LanguageRepository.GetByIsoCode("en-AU"); IContent content = DocumentRepository.Get(contentId); var domain1 = (IDomain) new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id }; repo.Save(domain1); var domain2 = (IDomain) new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id }; Assert.Throws <DuplicateNameException>(() => repo.Save(domain2)); } }
public void Can_Verify_Usage_Of_New_PropertyType_On_Content() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; IContentType contentType = repository.Get(_textpageContentType.Id); Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id); DocumentRepository.Save(subpage); PropertyGroup propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta"); propertyGroup.PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "metaAuthor") { Name = "Meta Author", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); repository.Save(contentType); // Act IContent content = DocumentRepository.Get(subpage.Id); content.SetValue("metaAuthor", "John Doe"); DocumentRepository.Save(content); // Assert IContent updated = DocumentRepository.Get(subpage.Id); Assert.That(updated.GetValue("metaAuthor").ToString(), Is.EqualTo("John Doe")); Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5)); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True); } }
public void GetMedia() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act IMedia media = repository.Get(_testImage.Id); // Assert Assert.That(media.Id, Is.EqualTo(_testImage.Id)); Assert.That(media.CreateDate, Is.GreaterThan(DateTime.MinValue)); Assert.That(media.UpdateDate, Is.GreaterThan(DateTime.MinValue)); Assert.That(media.ParentId, Is.Not.EqualTo(0)); Assert.That(media.Name, Is.EqualTo("Test Image")); Assert.That(media.SortOrder, Is.EqualTo(0)); Assert.That(media.VersionId, Is.Not.EqualTo(0)); Assert.That(media.ContentTypeId, Is.EqualTo(1032)); Assert.That(media.Path, Is.Not.Empty); Assert.That(media.Properties.Any(), Is.True); } }
public void QueryMedia_ContentTypeIdFilter() { // Arrange IMediaType folderMediaType = MediaTypeService.Get(1031); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act for (int i = 0; i < 10; i++) { Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); repository.Save(folder); } int[] types = new[] { 1031 }; IQuery <IMedia> query = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentTypeId)); IEnumerable <IMedia> result = repository.Get(query); // Assert Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11)); } }
public void Get_All_Ids() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); ILanguage lang = LanguageRepository.GetByIsoCode("en-AU"); IContent content = DocumentRepository.Get(contentId); var ids = new List <int>(); for (int i = 0; i < 10; i++) { var domain = (IDomain) new UmbracoDomain("test " + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id }; repo.Save(domain); ids.Add(domain.Id); } IEnumerable <IDomain> all = repo.GetMany(ids.Take(8).ToArray()); Assert.AreEqual(8, all.Count()); } }
public void GetAllMedia() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act IEnumerable <IMedia> medias = repository.GetMany(); // Assert Assert.That(medias, Is.Not.Null); Assert.That(medias.Any(), Is.True); Assert.That(medias.Count(), Is.GreaterThanOrEqualTo(3)); medias = repository.GetMany(medias.Select(x => x.Id).ToArray()); Assert.That(medias, Is.Not.Null); Assert.That(medias.Any(), Is.True); Assert.That(medias.Count(), Is.GreaterThanOrEqualTo(3)); medias = ((IReadRepository <Guid, IMedia>)repository).GetMany(medias.Select(x => x.Key).ToArray()); Assert.That(medias, Is.Not.Null); Assert.That(medias.Any(), Is.True); Assert.That(medias.Count(), Is.GreaterThanOrEqualTo(3)); } }
public void Get_All_Without_Wildcards() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); ILanguage lang = LanguageRepository.GetByIsoCode("en-AU"); IContent content = DocumentRepository.Get(contentId); for (int i = 0; i < 10; i++) { var domain = (IDomain) new UmbracoDomain((i % 2 == 0) ? "test " + i + ".com" : ("*" + i)) { RootContentId = content.Id, LanguageId = lang.Id }; repo.Save(domain); } IEnumerable <IDomain> all = repo.GetAll(false); Assert.AreEqual(5, all.Count()); } }
public void CreateNotification() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var repo = new NotificationsRepository((IScopeAccessor)provider); var node = new NodeDto // create bogus item so we can add a notification { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,123", SortOrder = 1, Text = "hello", Trashed = false, UniqueId = Guid.NewGuid(), UserId = Constants.Security.SuperUserId }; object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of <IEntity>(e => e.Id == node.NodeId); IUser user = Mock.Of <IUser>(e => e.Id == node.UserId); Notification notification = repo.CreateNotification(user, entity, "A"); Assert.AreEqual("A", notification.Action); Assert.AreEqual(node.NodeId, notification.EntityId); Assert.AreEqual(node.NodeObjectType, notification.EntityType); Assert.AreEqual(node.UserId, notification.UserId); } }
public void Can_Create_And_Get_By_Id_Empty_lang() { int contentId = CreateTestData("en-AU", out ContentType ct); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { DomainRepository repo = CreateRepository(provider); IContent content = DocumentRepository.Get(contentId); var domain = (IDomain) new UmbracoDomain("test.com") { RootContentId = content.Id }; repo.Save(domain); // re-get domain = repo.Get(domain.Id); Assert.NotNull(domain); Assert.IsTrue(domain.HasIdentity); Assert.Greater(domain.Id, 0); Assert.AreEqual("test.com", domain.DomainName); Assert.AreEqual(content.Id, domain.RootContentId); Assert.IsFalse(domain.LanguageId.HasValue); } }
public void Can_Perform_Add_On_LanguageRepository_With_Boolean_Properties() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { LanguageRepository repository = CreateRepository(provider); // Act var languageBR = new Language("pt-BR", "Portuguese (Brazil)") { IsDefault = true, IsMandatory = true }; repository.Save(languageBR); // Assert Assert.That(languageBR.HasIdentity, Is.True); Assert.That(languageBR.Id, Is.EqualTo(6)); // With 5 existing entries the Id should be 6 Assert.IsTrue(languageBR.IsDefault); Assert.IsTrue(languageBR.IsMandatory); Assert.IsNull(languageBR.FallbackLanguageId); } }
public void Built_In_Member_Type_Properties_Missing_Are_Automatically_Added_When_Creating() { Dictionary <string, PropertyType> stubs = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper); IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { MemberTypeRepository repository = CreateRepository(provider); IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); // created without the stub properties Assert.AreEqual(1, memberType.PropertyGroups.Count); Assert.AreEqual(3, memberType.PropertyTypes.Count()); // add one stub property, others are still missing memberType.AddPropertyType(stubs.First().Value, Constants.Conventions.Member.StandardPropertiesGroupAlias, Constants.Conventions.Member.StandardPropertiesGroupName); // saving *new* member type adds the (missing) stub properties repository.Save(memberType); // saving has added (and saved) the (missing) stub properties Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); // getting with stub properties memberType = repository.Get(memberType.Id); Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); } }
public void Can_Perform_Update_On_LanguageRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { LanguageRepository repository = CreateRepository(provider); // Act ILanguage language = repository.Get(5); language.IsoCode = "pt-BR"; language.CultureName = "Portuguese (Brazil)"; language.FallbackLanguageId = 1; repository.Save(language); ILanguage languageUpdated = repository.Get(5); // Assert Assert.That(languageUpdated, Is.Not.Null); Assert.That(languageUpdated.IsoCode, Is.EqualTo("pt-BR")); Assert.That(languageUpdated.CultureName, Is.EqualTo("Portuguese (Brazil)")); Assert.That(languageUpdated.FallbackLanguageId, Is.EqualTo(1)); } }
public void Can_Persist_Member_Type() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MemberTypeRepository repository = CreateRepository(provider); var memberType = (IMemberType)MemberTypeBuilder.CreateSimpleMemberType(); repository.Save(memberType); IMemberType sut = repository.Get(memberType.Id); Dictionary <string, PropertyType> standardProps = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper); Assert.That(sut, Is.Not.Null); Assert.That(sut.PropertyGroups.Count, Is.EqualTo(2)); Assert.That(sut.PropertyTypes.Count(), Is.EqualTo(3 + standardProps.Count)); Assert.That(sut.PropertyGroups.Any(x => x.HasIdentity == false || x.Id == 0), Is.False); Assert.That(sut.PropertyTypes.Any(x => x.HasIdentity == false || x.Id == 0), Is.False); TestHelper.AssertPropertyValuesAreEqual(sut, memberType); } }
public void Can_Delete_Container_Containing_Media_Types() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { EntityContainerRepository containerRepository = CreateContainerRepository(provider); MediaTypeRepository repository = CreateRepository(provider); var container = new EntityContainer(Constants.ObjectTypes.MediaType) { Name = "blah" }; containerRepository.Save(container); IMediaType contentType = MediaTypeBuilder.CreateSimpleMediaType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup"); contentType.ParentId = container.Id; repository.Save(contentType); // Act containerRepository.Delete(container); EntityContainer found = containerRepository.Get(container.Id); Assert.IsNull(found); contentType = repository.Get(contentType.Id); Assert.IsNotNull(contentType); Assert.AreEqual(-1, contentType.ParentId); } }
public void SaveMedia() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); IMediaType mediaType = mediaTypeRepository.Get(1032); Media image = MediaBuilder.CreateMediaImage(mediaType, -1); // Act mediaTypeRepository.Save(mediaType); repository.Save(image); IMedia fetched = repository.Get(image.Id); // Assert Assert.That(mediaType.HasIdentity, Is.True); Assert.That(image.HasIdentity, Is.True); TestHelper.AssertPropertyValuesAreEqual(image, fetched); } }
public void Can_Update_MediaType_With_PropertyType_Removed() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaTypeRepository repository = CreateRepository(provider); MediaType mediaType = MediaTypeBuilder.CreateNewMediaType(); repository.Save(mediaType); // Act IMediaType mediaTypeV2 = repository.Get(mediaType.Id); mediaTypeV2.PropertyGroups["media"].PropertyTypes.Remove("title"); repository.Save(mediaTypeV2); IMediaType mediaTypeV3 = repository.Get(mediaType.Id); // Assert Assert.That(mediaTypeV3.PropertyTypes.Any(x => x.Alias == "title"), Is.False); Assert.That(mediaTypeV2.PropertyGroups.Count, Is.EqualTo(mediaTypeV3.PropertyGroups.Count)); Assert.That(mediaTypeV2.PropertyTypes.Count(), Is.EqualTo(mediaTypeV3.PropertyTypes.Count())); } }
public void SaveMediaMultiple() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); IMediaType mediaType = mediaTypeRepository.Get(1032); Media file = MediaBuilder.CreateMediaFile(mediaType, -1); // Act repository.Save(file); Media image = MediaBuilder.CreateMediaImage(mediaType, -1); repository.Save(image); // Assert Assert.That(file.HasIdentity, Is.True); Assert.That(image.HasIdentity, Is.True); Assert.That(file.Name, Is.EqualTo("Test File")); Assert.That(image.Name, Is.EqualTo("Test Image")); Assert.That(file.ContentTypeId, Is.EqualTo(mediaType.Id)); Assert.That(image.ContentTypeId, Is.EqualTo(mediaType.Id)); } }