public void Should_Find_Sql_Package_Runner_If_Tool_Path_Not_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Working/tools/SqlPackage.exe", result.Path.FullPath);
            }
            public void Should_Not_Add_Quiet_If_Not_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport", result.Args);
            }
            public void Should_Set_Working_Directory()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Working", result.Process.WorkingDirectory.FullPath);
            }
            public void Should_Add_Universal_Authentication_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.UniversalAuthentication = true;

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport /UniversalAuthentication:True", result.Args);
            }
            public void Should_Add_Tenant_Id_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.TenantId = "10";

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport /TenantId:10", result.Args);
            }
            public void Should_Not_Add_Target_Connection_If_Target_File_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.TargetFile = "./sqlpublishprofile.pubxml";

                // When
                var result = fixture.Run();

                // Then
                Assert.DoesNotContain("/TargetConnectionString:", result.Args);
            }
            public void Should_Throw_If_Settings_Is_Null()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings = null;

                // When
                var result = Record.Exception(() => fixture.Run());

                // Then
                Assert.IsType <ArgumentNullException>(result);
            }
            public void Should_Not_Add_Source_File_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.SourceFile = "./sqlpublishprofile.pubxml";

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport", result.Args);
            }
            public void Should_Not_Add_Source_File()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.SourceFile = "./sqlpublishprofile.pubxml";

                // When
                var result = fixture.Run();

                // Then
                Assert.DoesNotContain("/SourceFile:", result.Args);
            }
            public void Should_Add_Quiet_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.Quiet = true;

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport /Quiet:True", result.Args);
            }
            public void Should_Add_Overwrite_Files_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.OverwriteFiles = true;

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport /OverwriteFiles:True", result.Args);
            }
            public void Should_Add_OutputPath_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.OutputPath = "./artifacts";

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport /OutputPath:\"/Working/artifacts\"", result.Args);
            }
            public void Should_Add_Properties_If_Provided(string key, string value)
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.Properties.Add(key, value);

                // When
                var result = fixture.Run();

                //Then
                Assert.Equal($"/Action:DriftReport /p:{key}={value}", result.Args);
            }
            public void Should_Add_Properties_After_Settings_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.UniversalAuthentication = true;
                fixture.Settings.Properties.Add("CommandTimeout", "120");

                // When
                var result = fixture.Run();

                //Then
                Assert.Equal($"/Action:DriftReport /UniversalAuthentication:True /p:CommandTimeout=120", result.Args);
            }
            public void Should_Not_Add_Source_Connection_String_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.SourceConnectionString =
                    "Data Source=(LocalDB)\\v11.0;AttachDbFileName=|DataDirectory|\\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True";

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal("/Action:DriftReport", result.Args);
            }
            public void Should_Throw_If_Sql_Package_Runner_Was_Not_Found()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.GivenDefaultToolDoNotExist();

                // When
                var result = Record.Exception(() => fixture.Run());

                // Then
                Assert.IsType <CakeException>(result);
                Assert.Equal("SqlPackage: Could not locate executable.", result?.Message);
            }
            public void Should_Use_Sql_Package_Runner_From_Tool_Path_If_Provided(string toolPath, string expected)
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.ToolPath = toolPath;
                fixture.GivenSettingsToolPathExist();

                // When
                var result = fixture.Run();

                // Then
                Assert.Equal(expected, result.Path.FullPath);
            }
            public void Should_Not_Add_Target_File_If_Target_Connection_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.TargetConnectionString =
                    "Data Target=(LocalDB)\\v11.0;AttachDbFileName=|DataDirectory|\\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True";

                // When
                var result = fixture.Run();

                // Then
                Assert.DoesNotContain("/TargetFile:", result.Args);
            }
            public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.GivenProcessExitsWithCode(1);

                // When
                var result = Record.Exception(() => fixture.Run());

                // Then
                Assert.IsType <CakeException>(result);
                Assert.Equal("SqlPackage: Process returned an error (exit code 1).", result?.Message);
            }
            public void Should_Throw_If_Process_Was_Not_Started()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.GivenProcessCannotStart();

                // When
                var result = Record.Exception(() => fixture.Run());

                // Then
                Assert.IsType <CakeException>(result);
                Assert.Equal("SqlPackage: Process was not started.", result?.Message);
            }
            public void Should_Not_Add_Target_Properties_If_Target_File_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.TargetFile = "./sqlpublishprofile.pubxml";

                // When
                var result = fixture.Run();

                // Then
                Assert.DoesNotContain("/TargetConnectionString:", result.Args);
                Assert.DoesNotContain("/TargetDatabaseName:", result.Args);
                Assert.DoesNotContain("/TargetEncryptConnection:", result.Args);
                Assert.DoesNotContain("/TargetPassword:"******"/TargetServerName:", result.Args);
                Assert.DoesNotContain("/TargetTimeout:", result.Args);
                Assert.DoesNotContain("/TargetTrustServerCertificate:", result.Args);
                Assert.DoesNotContain("/TargetUser:", result.Args);
            }
            public void Should_Not_Add_Source_Properties_If_Provided()
            {
                // Given
                var fixture = new SqlPackageDriftReportFixture();

                fixture.Settings.SourceConnectionString =
                    "Data Source=(LocalDB)\\v11.0;AttachDbFileName=|DataDirectory|\\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True";

                // When
                var result = fixture.Run();

                // Then
                Assert.DoesNotContain("/SourceConnectionString:", result.Args);
                Assert.DoesNotContain("/SourceDatabaseName:", result.Args);
                Assert.DoesNotContain("/SourceEncryptConnection:", result.Args);
                Assert.DoesNotContain("/SourcePassword:"******"/SourceServerName:", result.Args);
                Assert.DoesNotContain("/SourceTimeout:", result.Args);
                Assert.DoesNotContain("/SourceTrustServerCertificate:", result.Args);
                Assert.DoesNotContain("/SourceUser:", result.Args);
            }
 public TheRunMethod()
 {
     fixture = new SqlPackageDriftReportFixture();
 }