public void SetPropertyInvalidFormat()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            Should.Throw <ArgumentException>(() => packageDeployer.SetProperty("AllowDropBlockingAssemblies", "ARandomString"));
        }
        public void DeployNoAuthentication()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            Should.Throw <InvalidOperationException>(() => packageDeployer.Deploy("TestDatabase"));
        }
        public void LoadPackageFileDoesNotExist()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = "SomeDummyFile.dacpac";

            // Act
            Should.Throw <ArgumentException>(() => packageDeployer.LoadPackage(new FileInfo(packagePath)));

            // Assert
            packageDeployer.Package.ShouldBeNull();
        }
        public void LoadPackage()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);

            // Assert
            packageDeployer.Package.ShouldNotBeNull();
        }
        public void UseWindowsAuthentication()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.UseWindowsAuthentication();

            // Assert
            packageDeployer.ConnectionStringBuilder.IntegratedSecurity.ShouldBeTrue();
        }
        public void SetPropertyDatabaseSpecificationInvalidEdition()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            Should.Throw <ArgumentException>(() => packageDeployer.SetProperty("DatabaseSpecification", "MyFancyEdition;1024;P15"));

            // Assert
            packageDeployer.DeployOptions.DatabaseSpecification.Edition.ShouldBe(DacAzureEdition.Default);
            packageDeployer.DeployOptions.DatabaseSpecification.MaximumSize.ShouldBe(default);
        public void SetPropertyExcludeObjectTypes()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.SetProperty("ExcludeObjectTypes", "Contracts;Endpoints");

            // Assert
            packageDeployer.DeployOptions.ExcludeObjectTypes.ShouldBe(new ObjectType[] { ObjectType.Contracts, ObjectType.Endpoints });
        }
        public void SetPropertyDoNotDropObjectTypes()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.SetProperty("DoNotDropObjectTypes", "Aggregates;Assemblies");

            // Assert
            packageDeployer.DeployOptions.DoNotDropObjectTypes.ShouldBe(new ObjectType[] { ObjectType.Aggregates, ObjectType.Assemblies });
        }
        public void SetPropertySimpleValue()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.SetProperty("AllowDropBlockingAssemblies", "true");

            // Assert
            packageDeployer.DeployOptions.AllowDropBlockingAssemblies.ShouldBeTrue();
        }
        public void SetSqlCmdVariableNoValue()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            Should.Throw <ArgumentException>(() => packageDeployer.SetSqlCmdVariable("MySqlCmdVariable", string.Empty));

            // Assert
            packageDeployer.DeployOptions.SqlCommandVariableValues.ContainsKey("MySqlCmdVariable").ShouldBeFalse();
        }
        public void UseTargetServerAndPort()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.UseTargetServerAndPort("localhost", 1432);

            // Assert
            packageDeployer.ConnectionStringBuilder.DataSource.ShouldNotBeNull();
            packageDeployer.ConnectionStringBuilder.DataSource.ShouldBe("localhost,1432");
        }
        public void SetSqlCmdVariable()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.SetSqlCmdVariable("MySqlCmdVariable", "SomeValue");

            // Assert
            packageDeployer.DeployOptions.SqlCommandVariableValues.ContainsKey("MySqlCmdVariable").ShouldBeTrue();
            packageDeployer.DeployOptions.SqlCommandVariableValues["MySqlCmdVariable"].ShouldBe("SomeValue");
        }
        public void SetPropertyDatabaseSpecification()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.SetProperty("DatabaseSpecification", "Hyperscale;1024;P15");

            // Assert
            packageDeployer.DeployOptions.DatabaseSpecification.Edition.ShouldBe(DacAzureEdition.Hyperscale);
            packageDeployer.DeployOptions.DatabaseSpecification.MaximumSize.ShouldBe(1024);
            packageDeployer.DeployOptions.DatabaseSpecification.ServiceObjective.ShouldBe("P15");
        }
        public void UseSqlServerAuthenticationNoPasswordPrompts()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.UseSqlAuthentication("testuser", null);

            // Assert
            packageDeployer.ConnectionStringBuilder.IntegratedSecurity.ShouldBeFalse();
            packageDeployer.ConnectionStringBuilder.UserID.ShouldBe("testuser");
            _console.Received().ReadLine();
        }
        public void UseSqlAuthenticationWithPasswordDoesNotPrompt()
        {
            // Arrange
            using var packageDeployer = new PackageDeployer(_console);
            var packagePath = BuildSimpleModel();

            // Act
            packageDeployer.LoadPackage(packagePath);
            packageDeployer.UseSqlAuthentication("testuser", "testpassword");

            // Assert
            packageDeployer.ConnectionStringBuilder.IntegratedSecurity.ShouldBeFalse();
            packageDeployer.ConnectionStringBuilder.UserID.ShouldBe("testuser");
            packageDeployer.ConnectionStringBuilder.Password.ShouldBe("testpassword");
            _console.DidNotReceive().ReadLine();
        }