public void Test_Execute_Reference() { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "-- First Name -- "; user.LastName = "-- Last Name --"; //user.Username = "******"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "-- Test Role --"; user.Roles = new TestRole[] {role}; string newTypeName = "TestAccount"; EntityReference reference = DataAccess.Data.Referencer.GetActiveReferences(user)[0]; XmlDocument document = XmlUtilities.SerializeToDocument(reference); RenameTypeCommand command = new RenameTypeCommand(); command.TypeName = user.ShortTypeName; command.NewTypeName = newTypeName; command.Execute(document); EntityReference updatedReference = (EntityReference)XmlUtilities.DeserializeFromDocument(document, typeof(EntityReference)); Assert.AreEqual(newTypeName, updatedReference.Type1Name, "The type name wasn't changed."); }
public void Test_Execute_Reference() { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "-- First Name -- "; user.LastName = "-- Last Name --"; //user.Username = "******"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "-- Test Role --"; user.Roles = new TestRole[] { role }; string newTypeName = "TestAccount"; EntityReference reference = DataAccess.Data.Referencer.GetActiveReferences(user)[0]; XmlDocument document = XmlUtilities.SerializeToDocument(reference); RenameTypeCommand command = new RenameTypeCommand(); command.TypeName = user.ShortTypeName; command.NewTypeName = newTypeName; command.Execute(document); EntityReference updatedReference = (EntityReference)XmlUtilities.DeserializeFromDocument(document, typeof(EntityReference)); Assert.AreEqual(newTypeName, updatedReference.Type1Name, "The type name wasn't changed."); }
public void Test_SaveCommands() { RenamePropertyCommand command1 = new RenamePropertyCommand(); command1.TypeName = "TestUser"; command1.PropertyName = "LastName"; command1.NewPropertyName = "Surname"; RenameTypeCommand command2 = new RenameTypeCommand(); command2.TypeName = "TestUser"; command2.NewTypeName = "TestAccount"; DataSchemaCommandCollection commands = new DataSchemaCommandCollection(); commands.Add(command1); commands.Add(command2); Version legacyVersion = new Version(1, 0, 0, 0); Version commandVersion = new Version(1, 1, 0, 0); Version currentVersion = new Version(1, 1, 0, 0); string groupName = "TestGroup"; string commandsPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + DataAccess.Data.Schema.SchemaDirectory; DataAccess.Data.Schema.SaveCommands(commandsPath, commands, groupName, commandVersion); int fileCount = Directory.GetFiles(commandsPath).Length; Assert.AreEqual(1, fileCount, "Incorrect number of files created."); }
public void Test_Execute_Entity() { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "-- First Name -- "; user.LastName = "-- Last Name --"; //user.Username = "******"; XmlDocument document = XmlUtilities.SerializeToDocument(user); RenameTypeCommand command = new RenameTypeCommand(); command.TypeName = user.ShortTypeName; command.NewTypeName = "TestAccount"; command.Execute(document); Assert.AreEqual("TestAccount", document.DocumentElement.Name, "The type name wasn't updated on the document element node."); TestAccount account = (TestAccount)XmlUtilities.DeserializeFromDocument(document, typeof(TestAccount)); Assert.AreEqual(user.FirstName, account.FirstName, "The properties don't match."); }
public void Test_CheckIsUpToDate_False() { RenamePropertyCommand command1 = new RenamePropertyCommand(); command1.TypeName = "TestUser"; command1.PropertyName = "LastName"; command1.NewPropertyName = "Surname"; RenameTypeCommand command2 = new RenameTypeCommand(); command2.TypeName = "TestUser"; command2.NewTypeName = "TestAccount"; DataSchemaCommandCollection commands = new DataSchemaCommandCollection(); commands.Add(command1); commands.Add(command2); Version legacyVersion = new Version(1, 0, 0, 0); Version commandVersion = new Version(1, 1, 0, 0); Version currentVersion = new Version(1, 1, 0, 0); string groupName = "TestGroup"; string commandsPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + DataAccess.Data.Schema.SchemaDirectory; DataSchema schema = (DataSchema)DataAccess.Data.InitializeDataSchema(); schema.SchemaDirectory = "Testing" + Path.DirectorySeparatorChar + "Schema"; schema.LegacyVersion = legacyVersion; schema.ApplicationVersion = currentVersion; schema.SaveCommands(commandsPath, commands, groupName, commandVersion); bool isUpToDate = schema.CheckIsUpToDate(); }
public void Test_GetCommands() { RenamePropertyCommand command1 = new RenamePropertyCommand(); command1.TypeName = "TestUser"; command1.PropertyName = "LastName"; command1.NewPropertyName = "Surname"; RenameTypeCommand command2 = new RenameTypeCommand(); command2.TypeName = "TestUser"; command2.NewTypeName = "TestAccount"; DataSchemaCommandCollection commands = new DataSchemaCommandCollection(); commands.Add(command1); commands.Add(command2); Version legacyVersion = new Version(1, 0, 0, 0); Version commandVersion = new Version(1, 1, 0, 0); Version currentVersion = new Version(1, 1, 0, 0); string groupName = "TestGroup"; string commandsPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + DataAccess.Data.Schema.SchemaDirectory; DataSchema schema = (DataSchema)DataAccess.Data.InitializeDataSchema(); schema.SchemaCommandDirectoryPath = commandsPath; schema.LegacyVersion = legacyVersion; schema.ApplicationVersion = currentVersion; schema.SaveCommands(commandsPath, commands, groupName, commandVersion); DataSchemaCommandCollection foundCommands = schema.GetCommands(); Assert.AreEqual(commands.Count, foundCommands.Count, "Incorrect number of commands found."); }
public void Test_ImportFromXml_RenewSchema_TypeAndProperty() { Version currentVersion = new Version(1, 0, 0, 0); Version legacyVersion = new Version(0, 9, 0, 0); TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "Test"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test Role"; user.Roles = new TestRole[] { role }; DataExporter exporter = (DataExporter)DataAccess.Data.InitializeDataExporter(); exporter.ExportDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Exported"; // IMPORTANT: Export the references before the entities, because the references are stripped from the entities upon export // Alternative is to reactivate the entities and their references using DataAccess.Data.Activator. EntityReferenceCollection references = DataAccess.Data.Referencer.GetActiveReferences(user); exporter.ExportEntity(references[0]); exporter.ExportEntity(user); exporter.ExportEntity(role); DataSchema schema = (DataSchema)DataAccess.Data.Schema; schema.LegacyVersion = legacyVersion; schema.ApplicationVersion = currentVersion; schema.SchemaCommandDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Schema"; RenamePropertyCommand command1 = new RenamePropertyCommand(); command1.TypeName = user.ShortTypeName; command1.PropertyName = "Roles"; command1.NewPropertyName = "GrantedRoles"; RenameTypeCommand command2 = new RenameTypeCommand(); command2.TypeName = user.ShortTypeName; command2.NewTypeName = typeof(TestAccount).Name; RenamePropertyCommand command3 = new RenamePropertyCommand(); command3.TypeName = role.ShortTypeName; command3.PropertyName = "Users"; command3.NewPropertyName = "Accounts"; DataSchemaCommandCollection commands = new DataSchemaCommandCollection(); commands.Add(command1); commands.Add(command2); commands.Add(command3); schema.SchemaCommands = commands; DataImporter importer = (DataImporter)DataAccess.Data.Importer; importer.ImportableDirectoryPath = exporter.ExportDirectoryPath; importer.ImportedDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Imported"; importer.ImportFromXml(); TestAccount foundAccount = DataAccess.Data.Reader.GetEntity <TestAccount>("ID", user.ID); Assert.IsNotNull(foundAccount, "foundAccount == null"); Assert.AreEqual(user.ID.ToString(), foundAccount.ID.ToString(), "The ID of the found account doesn't match the ID of the original user."); DataAccess.Data.Activator.Activate(foundAccount, "GrantedRoles"); Assert.IsNotNull(foundAccount.GrantedRoles, "user.GrantedRoles == null"); Assert.AreEqual(1, foundAccount.GrantedRoles.Length, "Invalid number of roles found."); TestRole foundRole = DataAccess.Data.Reader.GetEntity <TestRole>("ID", role.ID); Assert.IsNotNull(foundRole, "foundRole == null"); Assert.AreEqual(role.ID.ToString(), foundRole.ID.ToString(), "The ID of the found role doesn't match the ID of the original role."); }
public void Test_ImportFromXml_RenewSchema_TypeAndProperty() { Version currentVersion = new Version(1, 0, 0, 0); Version legacyVersion = new Version(0, 9, 0, 0); TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "Test"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test Role"; user.Roles = new TestRole[] {role}; DataExporter exporter = (DataExporter)DataAccess.Data.InitializeDataExporter(); exporter.ExportDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Exported"; // IMPORTANT: Export the references before the entities, because the references are stripped from the entities upon export // Alternative is to reactivate the entities and their references using DataAccess.Data.Activator. EntityReferenceCollection references = DataAccess.Data.Referencer.GetActiveReferences(user); exporter.ExportEntity(references[0]); exporter.ExportEntity(user); exporter.ExportEntity(role); DataSchema schema = (DataSchema)DataAccess.Data.Schema; schema.LegacyVersion = legacyVersion; schema.ApplicationVersion = currentVersion; schema.SchemaCommandDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Schema"; RenamePropertyCommand command1 = new RenamePropertyCommand(); command1.TypeName = user.ShortTypeName; command1.PropertyName = "Roles"; command1.NewPropertyName = "GrantedRoles"; RenameTypeCommand command2 = new RenameTypeCommand(); command2.TypeName = user.ShortTypeName; command2.NewTypeName = typeof(TestAccount).Name; RenamePropertyCommand command3 = new RenamePropertyCommand(); command3.TypeName = role.ShortTypeName; command3.PropertyName = "Users"; command3.NewPropertyName = "Accounts"; DataSchemaCommandCollection commands = new DataSchemaCommandCollection(); commands.Add(command1); commands.Add(command2); commands.Add(command3); schema.SchemaCommands = commands; DataImporter importer = (DataImporter)DataAccess.Data.Importer; importer.ImportableDirectoryPath = exporter.ExportDirectoryPath; importer.ImportedDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Imported"; importer.ImportFromXml(); TestAccount foundAccount = DataAccess.Data.Reader.GetEntity<TestAccount>("ID", user.ID); Assert.IsNotNull(foundAccount, "foundAccount == null"); Assert.AreEqual(user.ID.ToString(), foundAccount.ID.ToString(), "The ID of the found account doesn't match the ID of the original user."); DataAccess.Data.Activator.Activate(foundAccount, "GrantedRoles"); Assert.IsNotNull(foundAccount.GrantedRoles, "user.GrantedRoles == null"); Assert.AreEqual(1, foundAccount.GrantedRoles.Length, "Invalid number of roles found."); TestRole foundRole = DataAccess.Data.Reader.GetEntity<TestRole>("ID", role.ID); Assert.IsNotNull(foundRole, "foundRole == null"); Assert.AreEqual(role.ID.ToString(), foundRole.ID.ToString(), "The ID of the found role doesn't match the ID of the original role."); }