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

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

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);

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

            TempManyToOneMany.ManyToOneClass = new AllReferencesAndID {
                ID = 1
            };

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

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Single(Result.Parameters);
            Assert.Equal(1, Result.Parameters[0].InternalValue);
            Assert.Equal("ID0", Result.Parameters[0].ID);
            Assert.Equal("SELECT [dbo].[IManyToOneOne_].[ID_] AS [ID],[dbo].[IManyToOneOne_].[BoolValue_] AS [BoolValue]\r\nFROM [dbo].[ManyToOneOneFromComplexClass_]\r\nINNER JOIN [dbo].[IManyToOneOne_] ON [dbo].[ManyToOneOneFromComplexClass_].[IManyToOneOne_ID_]=[dbo].[IManyToOneOne_].[ID_]\r\nWHERE ([dbo].[IManyToOneOne_].[ID_]=@ID0);", Result.QueryString);
            Assert.Equal(QueryType.LoadData, Result.QueryType);
        }
Exemplo n.º 2
0
        public void GenerateQueryWithManyToOneOneFromComplexGraphProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneOneFromComplexClassMapping(),
                new IManyToOneOneMapping(),
                new AllReferencesAndIDMappingWithDatabase()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

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

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);

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

            TempManyToOneMany.ManyToOneClass = new AllReferencesAndID {
                ID = 1
            };

            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\nINNER JOIN [dbo].[IManyToOneOne_] as [IManyToOneOne_2] ON [IManyToOneOne_2].[AllReferencesAndID_ID_]=[dbo].[AllReferencesAndID_].[ID_]\r\nWHERE [IManyToOneOne_2].[ID_]=@ID;", Result.QueryString);
            Assert.Equal(QueryType.LoadProperty, Result.QueryType);
        }
Exemplo n.º 3
0
        public void GenerateQueryWithManyToOneOneFromComplexGraphProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneOneFromComplexClassMapping(),
                new IManyToOneOneMapping(),
                new AllReferencesAndIDMappingWithDatabase()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

            var ManyToOneManyProperty = Mappings.Mappings[typeof(ManyToOneOneFromComplexClass)].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 <ManyToOneOneFromComplexClass>(Mappings, ObjectPool);
            var TempManyToOneMany = new ManyToOneOneFromComplexClass {
                ID = 10, BoolValue = true
            };

            TempManyToOneMany.ManyToOneClass = new AllReferencesAndID {
                ID = 1
            };

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

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Equal(2, Result.Parameters.Length);
            Assert.Equal(1, Result.Parameters[0].InternalValue);
            Assert.Equal(10, Result.Parameters[1].InternalValue);
            Assert.Equal("AllReferencesAndID_ID_", Result.Parameters[0].ID);
            Assert.Equal("ID", Result.Parameters[1].ID);
            Assert.Equal("UPDATE [dbo].[IManyToOneOne_] SET [dbo].[IManyToOneOne_].[AllReferencesAndID_ID_] = @AllReferencesAndID_ID_ FROM [dbo].[IManyToOneOne_] WHERE [dbo].[IManyToOneOne_].[ID_] = @ID;", Result.QueryString);
            Assert.Equal(QueryType.JoinsSave, Result.QueryType);
        }