private MigrationCommandListBuilder CreateBuilder()
    {
        var typeMappingSource = new TestRelationalTypeMappingSource(
            TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

        var logger           = new FakeRelationalCommandDiagnosticsLogger();
        var migrationsLogger = new FakeDiagnosticsLogger <DbLoggerCategory.Migrations>();
        var generationHelper = new RelationalSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies());

        return(new MigrationCommandListBuilder(
                   new MigrationsSqlGeneratorDependencies(
                       new RelationalCommandBuilderFactory(
                           new RelationalCommandBuilderDependencies(
                               typeMappingSource,
                               new ExceptionDetector())),
                       new FakeSqlGenerator(
                           new UpdateSqlGeneratorDependencies(
                               generationHelper,
                               typeMappingSource)),
                       generationHelper,
                       typeMappingSource,
                       new CurrentDbContext(new FakeDbContext()),
                       new ModificationCommandFactory(),
                       new LoggingOptions(),
                       logger,
                       migrationsLogger)));
    }
Ejemplo n.º 2
0
            private static ModificationCommandBatchFactoryDependencies CreateDependencies(
                IUpdateSqlGenerator sqlGenerator)
            {
                var typeMappingSource = new TestRelationalTypeMappingSource(
                    TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                    TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

                var logger = new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>();

                return(new ModificationCommandBatchFactoryDependencies(
                           new RelationalCommandBuilderFactory(
                               new RelationalCommandBuilderDependencies(
                                   typeMappingSource)),
                           new RelationalSqlGenerationHelper(
                               new RelationalSqlGenerationHelperDependencies()),
                           sqlGenerator
                           ?? new FakeSqlGenerator(
                               RelationalTestHelpers.Instance.CreateContextServices()
                               .GetRequiredService <UpdateSqlGeneratorDependencies>()),
                           new TypedRelationalValueBufferFactoryFactory(
                               new RelationalValueBufferFactoryDependencies(
                                   typeMappingSource,
                                   new CoreSingletonOptions())),
                           new CurrentDbContext(new FakeDbContext()),
                           logger));
            }
Ejemplo n.º 3
0
        public void Can_add_composite_parameter()
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(
                    typeMapper));

            parameterBuilder.AddCompositeParameter(
                "CompositeInvariant",
                new List <IRelationalParameter>
            {
                new TypeMappedRelationalParameter(
                    "FirstInvariant",
                    "FirstName",
                    new IntTypeMapping("int", DbType.Int32),
                    nullable: false),
                new TypeMappedRelationalParameter(
                    "SecondInvariant",
                    "SecondName",
                    new StringTypeMapping("nvarchar(max)"),
                    nullable: true)
            });

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as CompositeRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("CompositeInvariant", parameter.InvariantName);
            Assert.Equal(2, parameter.RelationalParameters.Count);
        }
Ejemplo n.º 4
0
        public void Can_add_type_mapped_parameter_by_property(bool nullable)
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var modelBuilder = RelationalTestHelpers.Instance.CreateConventionBuilder();

            modelBuilder.Entity("MyType").Property <string>("MyProp").IsRequired(!nullable);

            var model = modelBuilder.FinalizeModel(designTime: false, skipValidation: true);

            var property = model.GetEntityTypes().Single().FindProperty("MyProp");

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(typeMapper));

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name",
                property.GetRelationalTypeMapping(),
                property.IsNullable);

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
            Assert.Equal(property.GetTypeMapping(), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.IsNullable);
        }
Ejemplo n.º 5
0
        public void Can_add_type_mapped_parameter_by_property(bool nullable)
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var model    = (IMutableModel) new Model();
            var property = model.AddEntityType("MyType").AddProperty("MyProp", typeof(string));

            property.IsNullable = nullable;

            RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService <IModelRuntimeInitializer>()
            .Initialize(model.FinalizeModel(), designTime: false, validationLogger: null);

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(typeMapper));

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name",
                property.GetRelationalTypeMapping(),
                property.IsNullable);

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
            Assert.Equal(property.GetTypeMapping(), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.IsNullable);
        }
        public void Can_add_type_mapped_parameter_by_property(bool nullable)
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var property = ((IMutableModel) new Model()).AddEntityType("MyType").AddProperty("MyProp", typeof(string));

            property.IsNullable = nullable;
            property.SetTypeMapping(GetMapping(typeMapper, property));

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(
                    typeMapper));

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name",
                property.GetRelationalTypeMapping(),
                property.IsNullable);

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
            Assert.Equal(GetMapping(typeMapper, property), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.IsNullable);
        }
Ejemplo n.º 7
0
        public void Can_add_type_mapped_parameter_by_property(bool nullable)
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var property = new Model().AddEntityType("MyType").AddProperty("MyProp", typeof(string));

            property.IsNullable = nullable;
            property[CoreAnnotationNames.TypeMapping] = GetMapping(typeMapper, property);

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(
                    typeMapper,
                    new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>()));

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name",
                property);

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
            Assert.Equal(GetMapping(typeMapper, property), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.IsNullable);
        }
Ejemplo n.º 8
0
        protected override PropertyMappingValidationConvention CreateConvention()
        {
            var typeMappingSource = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            return(new PropertyMappingValidationConvention(
                       typeMappingSource,
                       TestServiceFactory.Instance.Create <IMemberClassifier>(
                           (typeof(ITypeMappingSource), typeMappingSource))));
        }
        protected override IModelValidator CreateModelValidator()
        {
            var typeMappingSource = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            return(new RelationalModelValidator(
                       new ModelValidatorDependencies(
                           typeMappingSource,
                           new MemberClassifier(
                               typeMappingSource,
                               TestServiceFactory.Instance.Create <IParameterBindingFactories>())),
                       new RelationalModelValidatorDependencies(typeMappingSource)));
        }
        public void Does_not_add_empty_composite_parameter()
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

            parameterBuilder.AddCompositeParameter(
                "CompositeInvariant",
                builder => { });

            Assert.Equal(0, parameterBuilder.Parameters.Count);
        }
Ejemplo n.º 11
0
        public void Does_not_add_empty_composite_parameter()
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(
                    typeMapper,
                    new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>()));

            parameterBuilder.AddCompositeParameter(
                "CompositeInvariant",
                new List <IRelationalParameter>());

            Assert.Equal(0, parameterBuilder.Parameters.Count);
        }
        private MigrationCommandListBuilder CreateBuilder()
        {
            var typeMappingSource = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var logger           = new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>();
            var generationHelper = new RelationalSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies());

            return(new MigrationCommandListBuilder(
                       new MigrationsSqlGeneratorDependencies(
                           new RelationalCommandBuilderFactory(typeMappingSource),
                           new FakeSqlGenerator(
                               new UpdateSqlGeneratorDependencies(
                                   generationHelper,
                                   typeMappingSource)),
                           generationHelper,
                           typeMappingSource,
                           logger)));
        }
        public void Can_add_dynamic_parameter()
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name");

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as DynamicRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
        }
Ejemplo n.º 14
0
        public void Can_add_dynamic_parameter()
        {
            var typeMapper = new TestRelationalTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var parameterBuilder = new RelationalCommandBuilder(
                new RelationalCommandBuilderDependencies(
                    typeMapper,
                    new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>()));

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name");

            Assert.Equal(1, parameterBuilder.Parameters.Count);

            var parameter = parameterBuilder.Parameters[0] as DynamicRelationalParameter;

            Assert.NotNull(parameter);
            Assert.Equal("InvariantName", parameter.InvariantName);
            Assert.Equal("Name", parameter.Name);
        }