Exemple #1
0
        static DecimalSqlDataTypeRepresentationTest()
        {
            ConstructorArgumentValidationTestScenarios
            .RemoveAllScenarios()
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <DecimalSqlDataTypeRepresentation>
            {
                Name             = "constructor should throw ArgumentOutOfRangeException when parameter 'precision' is 0",
                ConstructionFunc = () =>
                {
                    var result = new DecimalSqlDataTypeRepresentation(0);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
                ExpectedExceptionMessageContains = new[] { "precision", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <DecimalSqlDataTypeRepresentation>
            {
                Name             = "constructor should throw ArgumentOutOfRangeException when parameter 'precision' is greater than 38",
                ConstructionFunc = () =>
                {
                    var result = new DecimalSqlDataTypeRepresentation(A.Dummy <byte>().ThatIs(_ => _ > 38));

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
                ExpectedExceptionMessageContains = new[] { "precision", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <DecimalSqlDataTypeRepresentation>
            {
                Name             = "constructor should throw ArgumentOutOfRangeException when parameter 'scale' is greater than parameter 'precision'",
                ConstructionFunc = () =>
                {
                    var referenceObject = A.Dummy <DecimalSqlDataTypeRepresentation>();

                    var result = new DecimalSqlDataTypeRepresentation(referenceObject.Precision, A.Dummy <byte>().ThatIs(_ => _ > referenceObject.Precision));

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
                ExpectedExceptionMessageContains = new[] { "scale", },
            });
        }
        public SqlServerDummyFactory()
        {
            // --------------------------- Enums -----------------------------
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(ScriptableObjectType.Invalid);

            // --------------------------- Interfaces ------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
                                                          (ISqlOutputParameterResult) new SqlOutputParameterResult <int?>(A.Dummy <OutputParameterDefinition <int?> >(), A.Dummy <int?>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
                                                          (IResourceLocator)A.Dummy <SqlServerLocator>());

            AutoFixtureBackedDummyFactory.AddDummyCreator(() =>
                                                          (IDatabaseDefinition)A.Dummy <SqlServerDatabaseDefinition>());

            // --------------------------- Data Type Representation -----------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var supportedLength = A.Dummy <PositiveInteger>().ThatIs(_ => (_ >= 1) && (_ <= BinarySqlDataTypeRepresentation.MaxLengthConstant));

                var result = new BinarySqlDataTypeRepresentation(supportedLength);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var precision = A.Dummy <byte>().ThatIs(_ => (_ >= 1) && (_ <= 38));

                var scale = A.Dummy <byte>().ThatIs(_ => (_ <= precision));

                var result = new DecimalSqlDataTypeRepresentation(precision, scale);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var supportUnicode = A.Dummy <bool>();

                var supportedLength = supportUnicode
                        ? A.Dummy <PositiveInteger>().ThatIs(_ => (_ >= 1) && (_ <= StringSqlDataTypeRepresentation.MaxUnicodeLengthConstant))
                        : A.Dummy <PositiveInteger>().ThatIs(_ => (_ >= 1) && (_ <= StringSqlDataTypeRepresentation.MaxNonUnicodeLengthConstant));

                var result = new StringSqlDataTypeRepresentation(supportUnicode, supportedLength);

                return(result);
            });

            // ------------------------ Definition ---------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => ThreadSafeRandom.Next(0, 2) == 0
                    ? (ParameterDefinitionBase)A.Dummy <InputParameterDefinition <int?> >()
                    : A.Dummy <OutputParameterDefinition <int?> >());

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => (InputParameterDefinitionBase)A.Dummy <InputParameterDefinition <int?> >());

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => (OutputParameterDefinitionBase)A.Dummy <OutputParameterDefinition <int?> >());

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new InputParameterDefinition <int?>(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <IntSqlDataTypeRepresentation>(),
                    A.Dummy <int?>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new OutputParameterDefinition <int?>(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <IntSqlDataTypeRepresentation>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new ColumnDefinition(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <SqlDataTypeRepresentationBase>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new SqlServerDatabaseDefinition(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <DatabaseType>(),
                    A.Dummy <RecoveryMode>(),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <long>(),
                    A.Dummy <long>(),
                    A.Dummy <long>(),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <long>(),
                    A.Dummy <long>(),
                    A.Dummy <long>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new TableDefinition(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <IReadOnlyList <ColumnDefinition> >()));

            // ------------------------ Management ---------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var checksumOption    = A.Dummy <ChecksumOption>();
                var cipher            = A.Dummy <Cipher>();
                var compressionOption = A.Dummy <CompressionOption>();
                var device            = A.Dummy <Device>();
                var encryptor         = A.Dummy <Encryptor>();
                var errorHandling     = A.Dummy <ErrorHandling>();

                if (cipher == Cipher.NoEncryption && encryptor != Encryptor.None)
                {
                    encryptor = Encryptor.None;
                }

                if (cipher != Cipher.NoEncryption && encryptor == Encryptor.None)
                {
                    encryptor = A.Dummy <Encryptor>().ThatIsNot(Encryptor.None);
                }

                if (checksumOption == ChecksumOption.Checksum && errorHandling == ErrorHandling.None)
                {
                    errorHandling = A.Dummy <ErrorHandling>().ThatIsNot(ErrorHandling.None);
                }

                var backupSqlServerDatabaseDetails = new BackupSqlServerDatabaseDetails(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <string>().Replace("-", string.Empty),
                    device,
                    A.Dummy <Uri>(),
                    A.Dummy <string>().Replace("-", string.Empty),
                    compressionOption,
                    checksumOption,
                    errorHandling,
                    cipher,
                    encryptor,
                    A.Dummy <string>().Replace("-", string.Empty));

                return(backupSqlServerDatabaseDetails);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var checksumOption       = A.Dummy <ChecksumOption>();
                var device               = A.Dummy <Device>();
                var recoveryOption       = A.Dummy <RecoveryOption>();
                var replaceOption        = A.Dummy <ReplaceOption>();
                var restrictedUserOption = A.Dummy <RestrictedUserOption>();
                var errorHandling        = A.Dummy <ErrorHandling>();

                if (checksumOption == ChecksumOption.Checksum && errorHandling == ErrorHandling.None)
                {
                    errorHandling = A.Dummy <ErrorHandling>().ThatIsNot(ErrorHandling.None);
                }

                var logFilePath  = FormattableString.Invariant($"C:\\directory\\{A.Dummy<string>()}.dat");
                var dataFilePath = FormattableString.Invariant($"C:\\directory\\{A.Dummy<string>()}.ldf");
                return(new RestoreSqlServerDatabaseDetails(
                           dataFilePath,
                           logFilePath,
                           device,
                           A.Dummy <Uri>(),
                           A.Dummy <string>().Replace("-", string.Empty),
                           checksumOption,
                           errorHandling,
                           recoveryOption,
                           replaceOption,
                           restrictedUserOption));
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new TableDescription(
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <string>().Replace("-", string.Empty),
                    A.Dummy <IReadOnlyCollection <ColumnDescription> >()));

            // ------------------------ Resource Location ---------------------------------

            // ------------------------ Stream ---------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new SqlOutputParameterResult <int?>(
                    A.Dummy <OutputParameterDefinition <int?> >(),
                    A.Dummy <int?>()));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new SqlServerStreamConfig(
                    A.Dummy <string>(),
                    A.Dummy <StreamAccessKinds>().Whose(_ => _ != StreamAccessKinds.None),
                    TimeSpan.FromSeconds(A.Dummy <PositiveDouble>()),
                    TimeSpan.FromSeconds(A.Dummy <PositiveDouble>()),
                    A.Dummy <SerializerRepresentation>(),
                    A.Dummy <SerializationFormat>(),
                    Some.ReadOnlyDummies <SqlServerLocator>().ToList()));

            // ------------------------ Operations ---------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new CreateStreamUserOp(
                    A.Dummy <string>(),
                    A.Dummy <string>(),
                    A.Dummy <string>(),
                    CreateStreamUserOp.SupportedStreamAccessKinds.Take(ThreadSafeRandom.Next(1, CreateStreamUserOp.SupportedStreamAccessKinds.Count + 1)).Single(),
                    A.Dummy <bool>())
                );

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new DeleteDatabaseOp(
                    A.Dummy <string>().Replace("-", string.Empty)));

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () => new UpdateStreamStoredProceduresOp(A.Dummy <RecordTagAssociationManagementStrategy>(), A.Dummy <PositiveInteger>()));
        }