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_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_RenewSchema()
        {
            TestUser user = new TestUser();
            user.ID = Guid.NewGuid();
            user.FirstName = "--FirstName--";
            user.LastName = "--LastName--";
            user.Email = "--Email--";
            user.Username = "******";

            XmlDocument document = XmlUtilities.SerializeToDocument(user);

            RenamePropertyCommand command1 = new RenamePropertyCommand();
            command1.PropertyName = "LastName";
            command1.NewPropertyName = "Surname";
            command1.TypeName = "TestUser";

            DataSchemaCommandCollection commands = new DataSchemaCommandCollection();
            commands.Add(command1);

            DataSchema schema = (DataSchema)DataAccess.Data.InitializeDataSchema();

            schema.SchemaCommands = commands;

            schema.RenewSchema(document);

            TestUser user2 = (TestUser)XmlUtilities.DeserializeFromDocument(document, user.GetType());

            Assert.IsNotNull(user2, "user2 == null");

            Assert.AreEqual(user.ID.ToString(), user2.ID.ToString(), "The IDs don't match.");

            Assert.AreEqual(user.LastName, user2.Surname, "The value of the LastName wasn't moved to the Surname property like it should have.");
        }
        public void Test_CheckIsUpToDate_True()
        {
            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(0, 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();
        }