aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs
blob: 84a81035be3b41ed3039c59cad49e6ebb72df048 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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.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 Synchronize_Schema()
        {
            SqlConnection connection = new SqlConnection("Server=localhost\\SQLEXPRESS;Integrated security=SSPI");

            String command = @"CREATE DATABASE Test";

            SqlCommand cmd = new SqlCommand(command, connection);
            connection.Open();
            cmd.ExecuteNonQuery();

            ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema);

            var temp_folder = Helper.GetTempFolderPath();

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

            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");

            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);
        }
    }
}