Ejemplo n.º 1
0
        public void GenerateQueryWithManyToOneManyFromComplexGraphProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyFromComplexClassMapping(),
                new IManyToOneManyMapping(),
                new AllReferencesAndIDMappingWithDatabase()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

            var ManyToOneManyProperty = Mappings.Mappings[typeof(ManyToOneManyFromComplexClass)].ManyToOneProperties.First();
            var TempDataModel         = new Inflatable.Schema.DataModel(Mappings, Configuration, Logger, DataModeler, Sherlock, Helper);

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);
            ManyToOneManyProperty.SetColumnInfo(Mappings);

            var TestObject        = new SavePropertiesQuery <ManyToOneManyFromComplexClass>(Mappings, ObjectPool);
            var TempManyToOneMany = new ManyToOneManyFromComplexClass {
                ID = 10, BoolValue = true
            };

            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 1
            });
            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 2
            });

            var Result = TestObject.GenerateQueries(TempManyToOneMany, ManyToOneManyProperty)[0];

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Equal(2, Result.Parameters.Length);
            Assert.Equal(10, Result.Parameters[0].InternalValue);
            Assert.Equal(1, Result.Parameters[1].InternalValue);
            Assert.Equal("IManyToOneMany_ID_", Result.Parameters[0].ID);
            Assert.Equal("ID_", Result.Parameters[1].ID);
            Assert.Equal("UPDATE [dbo].[AllReferencesAndID_] SET [dbo].[AllReferencesAndID_].[IManyToOneMany_ID_] = @IManyToOneMany_ID_ FROM [dbo].[AllReferencesAndID_] WHERE [dbo].[AllReferencesAndID_].[ID_] = @ID_;", Result.QueryString);
            Assert.Equal(QueryType.JoinsSave, Result.QueryType);
        }
Ejemplo n.º 2
0
        public void GenerateQueryWithManyToOneManyFromComplexGraphProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyFromComplexClassMapping(),
                new IManyToOneManyMapping(),
                new AllReferencesAndIDMappingWithDatabase()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

            var ManyToOneManyProperty = Mappings.Mappings[typeof(ManyToOneManyFromComplexClass)].ManyToOneProperties[0];
            var TempDataModel         = new Inflatable.Schema.DataModel(Mappings, Configuration, Logger, DataModeler, Sherlock, Helper);

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);

            var TestObject        = new DataLoadQuery <ManyToOneManyFromComplexClass>(Mappings, ObjectPool);
            var TempManyToOneMany = new ManyToOneManyFromComplexClass {
                ID = 10, BoolValue = true
            };

            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 1
            });
            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 2
            });

            var Result = TestObject.GenerateQueries(new Dynamo[] { new Dynamo(new { ID = 10 }) })[0];

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Single(Result.Parameters);
            Assert.Equal(10, Result.Parameters[0].InternalValue);
            Assert.Equal("ID0", Result.Parameters[0].ID);
            Assert.Equal("SELECT [dbo].[IManyToOneMany_].[ID_] AS [ID],[dbo].[IManyToOneMany_].[BoolValue_] AS [BoolValue]\r\nFROM [dbo].[ManyToOneManyFromComplexClass_]\r\nINNER JOIN [dbo].[IManyToOneMany_] ON [dbo].[ManyToOneManyFromComplexClass_].[IManyToOneMany_ID_]=[dbo].[IManyToOneMany_].[ID_]\r\nWHERE ([dbo].[IManyToOneMany_].[ID_]=@ID0);", Result.QueryString);
            Assert.Equal(QueryType.LoadData, Result.QueryType);
        }
Ejemplo n.º 3
0
        public void GenerateQueryWithManyToOneManyFromComplexGraphProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyFromComplexClassMapping(),
                new IManyToOneManyMapping(),
                new AllReferencesAndIDMappingWithDatabase()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

            var ManyToOneManyProperty = Mappings.Mappings[typeof(ManyToOneManyFromComplexClass)].ManyToOneProperties.First();
            var TempDataModel         = new Inflatable.Schema.DataModel(Mappings, Configuration, Logger, DataModeler, Sherlock, Helper);

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);

            var TestObject        = new LoadPropertiesQuery <ManyToOneManyFromComplexClass>(Mappings, ObjectPool);
            var TempManyToOneMany = new ManyToOneManyFromComplexClass {
                ID = 10, BoolValue = true
            };

            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 1
            });
            TempManyToOneMany.ManyToOneClass.Add(new AllReferencesAndID {
                ID = 2
            });

            var Result = TestObject.GenerateQueries(TempManyToOneMany, ManyToOneManyProperty)[0];

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Single(Result.Parameters);
            Assert.Equal(10, Result.Parameters[0].InternalValue);
            Assert.Equal("ID", Result.Parameters[0].ID);
            Assert.Equal("SELECT [dbo].[AllReferencesAndID_].[ID_] AS [ID],[dbo].[AllReferencesAndID_].[BoolValue_] AS [BoolValue],[dbo].[AllReferencesAndID_].[ByteArrayValue_] AS [ByteArrayValue],[dbo].[AllReferencesAndID_].[ByteValue_] AS [ByteValue],[dbo].[AllReferencesAndID_].[CharValue_] AS [CharValue],[dbo].[AllReferencesAndID_].[DateTimeValue_] AS [DateTimeValue],[dbo].[AllReferencesAndID_].[DecimalValue_] AS [DecimalValue],[dbo].[AllReferencesAndID_].[DoubleValue_] AS [DoubleValue],[dbo].[AllReferencesAndID_].[FloatValue_] AS [FloatValue],[dbo].[AllReferencesAndID_].[GuidValue_] AS [GuidValue],[dbo].[AllReferencesAndID_].[IntValue_] AS [IntValue],[dbo].[AllReferencesAndID_].[LongValue_] AS [LongValue],[dbo].[AllReferencesAndID_].[NullableBoolValue_] AS [NullableBoolValue],[dbo].[AllReferencesAndID_].[NullableByteValue_] AS [NullableByteValue],[dbo].[AllReferencesAndID_].[NullableCharValue_] AS [NullableCharValue],[dbo].[AllReferencesAndID_].[NullableDateTimeValue_] AS [NullableDateTimeValue],[dbo].[AllReferencesAndID_].[NullableDecimalValue_] AS [NullableDecimalValue],[dbo].[AllReferencesAndID_].[NullableDoubleValue_] AS [NullableDoubleValue],[dbo].[AllReferencesAndID_].[NullableFloatValue_] AS [NullableFloatValue],[dbo].[AllReferencesAndID_].[NullableGuidValue_] AS [NullableGuidValue],[dbo].[AllReferencesAndID_].[NullableIntValue_] AS [NullableIntValue],[dbo].[AllReferencesAndID_].[NullableLongValue_] AS [NullableLongValue],[dbo].[AllReferencesAndID_].[NullableSByteValue_] AS [NullableSByteValue],[dbo].[AllReferencesAndID_].[NullableShortValue_] AS [NullableShortValue],[dbo].[AllReferencesAndID_].[NullableTimeSpanValue_] AS [NullableTimeSpanValue],[dbo].[AllReferencesAndID_].[NullableUIntValue_] AS [NullableUIntValue],[dbo].[AllReferencesAndID_].[NullableULongValue_] AS [NullableULongValue],[dbo].[AllReferencesAndID_].[NullableUShortValue_] AS [NullableUShortValue],[dbo].[AllReferencesAndID_].[SByteValue_] AS [SByteValue],[dbo].[AllReferencesAndID_].[ShortValue_] AS [ShortValue],[dbo].[AllReferencesAndID_].[StringValue1_] AS [StringValue1],[dbo].[AllReferencesAndID_].[StringValue2_] AS [StringValue2],[dbo].[AllReferencesAndID_].[TimeSpanValue_] AS [TimeSpanValue],[dbo].[AllReferencesAndID_].[UIntValue_] AS [UIntValue],[dbo].[AllReferencesAndID_].[ULongValue_] AS [ULongValue],[dbo].[AllReferencesAndID_].[UShortValue_] AS [UShortValue],[dbo].[AllReferencesAndID_].[UriValue_] AS [UriValue]\r\nFROM [dbo].[AllReferencesAndID_]\r\nWHERE [dbo].[AllReferencesAndID_].[IManyToOneMany_ID_]=@ID;", Result.QueryString);
            Assert.Equal(QueryType.LoadProperty, Result.QueryType);
        }