示例#1
0
        public void Clone_Typed(string?cloneDatabaseName, string expectedDatabaseName)
        {
            var credential = new PSCredential("username", "password".Secure());

            var original = new SqlContext
            {
                ServerName        = "server",
                ServerPort        = 1234,
                InstanceName      = "instance",
                DatabaseName      = "database",
                Credential        = credential,
                EncryptionMode    = EncryptionMode.Full,
                ConnectTimeout    = 42.Seconds(),
                ClientName        = "client",
                ApplicationName   = "application",
                ApplicationIntent = ApplicationIntent.ReadOnly,
                ExposeCredentialInConnectionString = true,
                EnableConnectionPooling            = true,
                EnableMultipleActiveResultSets     = true,
            };

            var context = original.Clone(cloneDatabaseName);

            context.Should().NotBeNull().And.NotBeSameAs(original);

            context.ServerName.Should().Be("server");
            context.ServerPort.Should().Be(1234);
            context.InstanceName.Should().Be("instance");
            context.DatabaseName.Should().Be(expectedDatabaseName);
            context.Credential.Should().BeSameAs(credential);
            context.EncryptionMode.Should().Be(EncryptionMode.Full);
            context.ConnectTimeout.Should().Be(42.Seconds());
            context.ClientName.Should().Be("client");
            context.ApplicationName.Should().Be("application");
            context.ApplicationIntent.Should().Be(ApplicationIntent.ReadOnly);
            context.ExposeCredentialInConnectionString.Should().BeTrue();
            context.EnableConnectionPooling.Should().BeTrue();
            context.EnableMultipleActiveResultSets.Should().BeTrue();
        }