aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs
blob: 5b7ce16ca05896ffb8112b0b5bad1592efaaa597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tango.PPC.Jobs.Dialogs
{
    /// <summary>
    /// Interaction logic for SpoolChangeView.xaml
    /// </summary>
    public partial class SpoolChangeView : UserControl
    {
        public SpoolChangeView()
        {
            InitializeComponent();
        }
    }
}
6 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Core.DB;
using Tango.Core.IO;
using Tango.SQLExaminer;

namespace Tango.UnitTesting
{
    [TestClass]
    [TestCategory("SQL Examiner")]
    public class SQLExaminer_TST
    {
        [TestMethod]
        public void Generate_Schema_Synchronization_Script()
        {
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango", false, "Synchronizer", "Aa123456").
                SetTargetServer("twine01\\SQLTWINE", "Tango").
                SetBackupFile(Path.Combine(temp_folder, "db.bak")).
                SetReportFile(Path.Combine(temp_folder, "report.xml"));

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "schema.xml");

            config.ToFile(config_path);

            Helper.ShowInExplorer(config_path);
        }

        [TestMethod]
        public void Generate_Provisioning_Synchronization_Script()
        {
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango", false, "Synchronizer", "Aa123456").
                SetTargetServer("twine01\\SQLTWINE", "Tango").
                SetReportFile(Path.Combine(temp_folder, "report.xml")).
                SetMachineSerialNumber("1111");

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "provision.xml");

            config.ToFile(config_path);

            Helper.ShowInExplorer(config_path);
        }

        [TestMethod]
        public void Generate_Data_Overriding_Script()
        {
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango", false, "Synchronizer", "Aa123456").
                SetTargetServer("twine01\\SQLTWINE", "Tango").
                SetReportFile(Path.Combine(temp_folder, "report.xml"));

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "data.xml");

            config.ToFile(config_path);

            Helper.ShowInExplorer(config_path);
        }

        [TestMethod]
        public void LoadReport()
        {
            ExaminerDataReport report = ExaminerDataReport.FromFile("C:\\DATA\\report_data.xml");
        }

        [TestMethod]
        public void Synchronize_Schema()
        {
            SqlConnection connection = new SqlConnection("Server=localhost\\SQLEXPRESS;Integrated security=SSPI");

            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango").
                SetTargetServer("localhost\\SQLEXPRESS", "Test").
                SetReportFile("C:\\Data\\Report.xml");

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "schema.xml");

            config.ToFile(config_path);

            ExaminerProcess process = new ExaminerProcess(config_path, ExaminerProcessType.Schema);
            var result = process.Execute().Result;

            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);
        }

        [TestMethod]
        public void Override_Data()
        {
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango").
                SetTargetServer("localhost\\SQLEXPRESS", "Test").
                SetReportFile("C:\\DATA\\report_data.xml");

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "data.xml");

            config.ToFile(config_path);

            ExaminerProcess process = new ExaminerProcess(config_path, ExaminerProcessType.Data);
            process.Progress += (x, msg) =>
            {
                Debug.WriteLine(msg);
            };
            var result = process.Execute().Result;

            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);
        }

        [TestMethod]
        public void Provision_Machine()
        {
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine);

            var temp_folder = Helper.GetTempFolderPath();

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", "Tango").
                SetTargetServer("localhost\\SQLEXPRESS", "Test").
                SetMachineSerialNumber("1111");

            var config = builder.Build();

            String config_path = Path.Combine(temp_folder, "provision.xml");

            config.ToFile(config_path);

            ExaminerProcess process = new ExaminerProcess(config_path, ExaminerProcessType.Data);
            process.Progress += (x, msg) =>
            {
                Debug.WriteLine(msg);
            };
            var result = process.Execute().Result;

            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);
        }

        [TestMethod]
        public void Perform_Full_DataBase_Cycle()
        {
            String temp_folder = Helper.GetTempFolderPath();
            String report_file = Path.Combine(temp_folder, "report.xml");
            String config_file = Path.Combine(temp_folder, "config.xml");
            String machine_serial_number = "1111";

            String tango_db = "Tango";
            String source_db = "Source_DB_Test";
            String target_db = "Target_DB_Test";

            DbManager db = DbManager.FromAddress("localhost\\SQLEXPRESS");
            Assert.IsTrue(db.Exists("Tango"), "Database Tango does not exists.");

            if (db.Exists(source_db))
            {
                db.Delete(source_db);
            }

            if (db.Exists(target_db))
            {
                db.Delete(target_db);
            }

            Assert.IsFalse(db.Exists(source_db), source_db + " exists.");
            Assert.IsFalse(db.Exists(target_db), target_db + " exists.");

            //Clone Tango DB to SourceDB
            db.CloneDB(
                "Tango",
                Path.Combine(temp_folder, "Tango.bak"),
                source_db,
                Path.Combine(temp_folder, "Source_DB_Test.mdf"),
                Path.Combine(temp_folder, "Source_DB_Test.ldf"));

            //Create target database
            db.Create(target_db);

            //Create schema configuration
            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema);

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", source_db).
                SetTargetServer("localhost\\SQLEXPRESS", target_db).
                Synchronize().
                SetReportFile(report_file);

            //Synchronize Source schema with Target schema
            ExaminerProcessResult result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Schema).Execute().Result;

            var schema_report = ExaminerSchemaReport.FromFile(report_file);

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            //Should have differences
            Assert.IsTrue(schema_report.HasDifferences);

            //Create override data configuration
            builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData);

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", source_db).
                SetTargetServer("localhost\\SQLEXPRESS", target_db).
                Synchronize().
                SetReportFile(report_file);

            result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            var data_report = ExaminerDataReport.FromFile(report_file);

            //Should have differences
            Assert.IsTrue(data_report.HasDifferences);

            //Provision Target
            builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine);

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", source_db).
                SetTargetServer("localhost\\SQLEXPRESS", target_db).
                SetMachineSerialNumber(machine_serial_number).
                Synchronize().
                SetReportFile(report_file);

            result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            data_report = ExaminerDataReport.FromFile(report_file);

            //Should have differences
            Assert.IsTrue(data_report.HasDifferences);

            //Check if machine exists in target

            String job_guid = String.Empty;

            using (var context = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS", target_db, DataSourceType.SQLServer))
            {
                context.Configuration.LazyLoadingEnabled = false;
                Assert.IsTrue(context.Machines.Count() == 1);
                Assert.IsTrue(context.Machines.Any(x => x.SerialNumber == machine_serial_number));

                //Add new job to the target
                Job job = new Job();
                job.Name = "Test Job";
                job.Machine = context.Machines.First();
                job.Rml = context.Rmls.First();
                job.ColorSpace = context.ColorSpaces.First();
                job.CreationDate = DateTime.UtcNow;
                job.Description = "Description";
                job.SpoolType = context.SpoolTypes.First();
                job.User = context.Users.First();
                job.WindingMethod = context.WindingMethods.First();
                job.AddSolidSegment();
                job.AddGradientSegment();

                context.Jobs.Add(job);

                context.SaveChanges();

                job_guid = job.Guid;

                Assert.IsTrue(context.BrushStops.Count() == 3);
            }

            //Update new job from target to source
            builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.UpdateTwineDB);

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", target_db).
                SetTargetServer("localhost\\SQLEXPRESS", source_db).
                Synchronize().
                SetReportFile(report_file);

            result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            data_report = ExaminerDataReport.FromFile(report_file);

            //Should have differences
            Assert.IsTrue(data_report.HasDifferences);

            //Check the new job exists on source..
            using (var context = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS", source_db, DataSourceType.SQLServer))
            {
                Assert.IsTrue(context.Jobs.Any(x => x.Guid == job_guid));
            }

            //Now change configuration in source and push to machine
            using (var context = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS", source_db, DataSourceType.SQLServer))
            {
                var machine = context.Machines.SingleOrDefault(x => x.SerialNumber == machine_serial_number);
                machine.Configuration.Name = "Test Name " + new Random().Next(0, 1000);
                context.SaveChanges();
            }

            //Update the machine from source
            builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.UpdateMachine);

            builder.
                SetSourceServer("localhost\\SQLEXPRESS", source_db).
                SetTargetServer("localhost\\SQLEXPRESS", target_db).
                SetMachineSerialNumber(machine_serial_number).
                Synchronize().
                SetReportFile(report_file);

            result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            data_report = ExaminerDataReport.FromFile(report_file);

            //Should have differences
            Assert.IsTrue(data_report.HasDifferences);


            //Check no difference after update
            builder.NoSynchronize();
            result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;

            //Synchronization was successful
            Assert.AreEqual(result.ExitCode, ExaminerProcessExitCode.Success);

            data_report = ExaminerDataReport.FromFile(report_file);

            //Should have no differences!
            Assert.IsFalse(data_report.HasDifferences);
        }
    }
}