public void TestMoveToNewFolder( ) { Folder f1 = null; Folder f2 = null; Resource r = null; try { // Create two folders f1 = new Folder( ); f1.Save( ); f2 = new Folder( ); f2.Save( ); // Create resource in first folder r = new Resource(); r.ResourceInFolder.Add(f1.As <NavContainer>()); r.Save( ); // Move resource into second folder r = Entity.Get <Resource>(r.Id).AsWritable <Resource>( ); r.ResourceInFolder.Remove(f1.As <NavContainer>()); r.ResourceInFolder.Add(f2.As <NavContainer>()); r.Save( ); // Verify that resource is in second folder f2 = Entity.Get <Folder>(f2.Id); Assert.AreEqual(1, f2.FolderContents.Count); // Verify that resource is not in first folder f1 = Entity.Get <Folder>(f1.Id); Assert.AreEqual(0, f1.FolderContents.Count); } finally { if (r != null) { r.Delete( ); } if (f1 != null) { f1.AsWritable( ).Delete( ); } if (f2 != null) { f2.AsWritable( ).Delete( ); } } }
public void TestClearRelationship( ) { Folder f1 = null; Resource r = null; try { // Create a folders f1 = new Folder( ); f1.Save( ); // Create resource in folder r = new Resource(); r.ResourceInFolder.Add(f1.As <NavContainer>()); r.Save( ); long id = r.Id; // Get entity again. r = Entity.Get <Resource>(id); Assert.IsNotNull(r.ResourceInFolder); // Clear the relationship r = r.AsWritable <Resource>( ); r.ResourceInFolder.Clear(); r.Save( ); // Ensure folder was removed r = Entity.Get <Resource>(id); Assert.AreEqual(0, r.ResourceInFolder.Count); f1 = Entity.Get <Folder>(f1.Id); Assert.AreEqual(0, f1.FolderContents.Count); } finally { if (f1 != null) { if (r != null) { r.AsWritable( ).Delete( ); } } if (r != null) { r.AsWritable( ).Delete( ); } } }
/// <summary> /// Get the default display report for the given <see cref="EntityType" />. /// If there is no display report, do a breadth-first recursion through /// the inherited types to find a suitable display report. /// </summary> /// <param name="securableEntity"> /// The type (or other <see cref="SecurableEntity" /> the report will be for. /// Note that the current implementation requires this to be an <see cref="EntityType" />. /// </param> /// <param name="structuredQuery"> /// An optional <see cref="StructuredQuery" /> to use for the report.. /// </param> /// <returns> /// A <see cref="ReadiNow.Model.Report" /> or null, if not report is found. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="securableEntity" /> cannot be null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="securableEntity" /> must be an <see cref="EntityType" />. /// </exception> public Report GetDisplayReportForSecurableEntity(SecurableEntity securableEntity, StructuredQuery structuredQuery = null) { if (securableEntity == null) { throw new ArgumentNullException("securableEntity"); } // TODO: Test the RootEntity of structuredQuery to ensure it is the correct ype. var entityType = securableEntity.As <EntityType>( ); if (entityType == null) { throw new ArgumentException(@"securableEntity is not an EntityType", "securableEntity"); } // Place in separate, uniquely named folder to ensure (1) security reports // do not appear inthe UI elsewhere and (2) the report name resource key // does not block the saving of the report. Folder folder = Model.Entity.Create <Folder>( ); folder.Name = string.Format("{0}{1}", Guid.NewGuid( ), DateTime.Now); folder.Save( ); // The report creation code is hardly the most efficient but // it has been working reliably in automated tests. This operation // also occurs rarely. if (structuredQuery == null) { string typeName = entityType.Name ?? "Name"; structuredQuery = CreateEntitiesQuery(entityType, typeName); } Report result = ToReport(structuredQuery); result.Name = entityType.Name ?? DefaultReportName; result.Description = string.Empty; result.ResourceInFolder.Add(folder.As <NavContainer>( )); // For cascading deletes result.Save( ); return(result); }
public void TestEntity_Constructor_Type_Null( ) { // Create parent and child folders var parent = new Folder { Name = "Parent" }; parent.Save( ); var child = new Folder { Name = "Child" }; child.Save( ); // Link them together via child child.ResourceInFolder.Add(parent.As <NavContainer>( )); child.Save( ); // Assert that the parent has the relationship parent = Entity.Get <Folder>(parent.Id); Assert.AreEqual(1, parent.FolderContents.Count); // Get writeable copy, modify and save parent = parent.AsWritable <Folder>( ); parent.Name = "Name2"; parent.Save( ); // Assert that the parent still has the relationship parent = Entity.Get <Folder>(parent.Id); Assert.AreEqual(1, parent.FolderContents.Count); child.Delete( ); parent.AsWritable( ).Delete( ); }