Exemplo n.º 1
0
        public void GenerateQueryWithManyToOneManyProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyPropertiesMapping(),
                new ManyToOneOnePropertiesMapping()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);
            var ManyToOneProperty = Mappings.Mappings[typeof(ManyToOneManyProperties)].ManyToOneProperties.First();
            var TempDataModel     = new Inflatable.Schema.DataModel(Mappings, Configuration, Logger, DataModeler, Sherlock, Helper);

            ManyToOneProperty.Setup(Mappings, TempDataModel.SourceSpec);
            var TestObject    = new DeletePropertiesQuery <ManyToOneManyProperties>(Mappings, ObjectPool);
            var TempManyToOne = new ManyToOneManyProperties {
                ID = 10, BoolValue = true
            };

            TempManyToOne.ManyToOneClass.Add(new ManyToOneOneProperties {
                ID = 1
            });
            TempManyToOne.ManyToOneClass.Add(new ManyToOneOneProperties {
                ID = 2
            });
            var Result = TestObject.GenerateQueries(TempManyToOne, ManyToOneProperty);

            Assert.Empty(Result);
        }
Exemplo n.º 2
0
        public void GenerateQueryWithManyToOneManyProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyPropertiesMapping(),
                new ManyToOneOnePropertiesMapping()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

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

            TempManyToOneMany.ManyToOneClass.Add(new ManyToOneOneProperties {
                ID = 1
            });
            TempManyToOneMany.ManyToOneClass.Add(new ManyToOneOneProperties {
                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("ManyToOneManyProperties_ID_", Result.Parameters[0].ID);
            Assert.Equal("ID_", Result.Parameters[1].ID);
            Assert.Equal("UPDATE [dbo].[ManyToOneOneProperties_] SET [dbo].[ManyToOneOneProperties_].[ManyToOneManyProperties_ID_] = @ManyToOneManyProperties_ID_ FROM [dbo].[ManyToOneOneProperties_] WHERE [dbo].[ManyToOneOneProperties_].[ID_] = @ID_;", Result.QueryString);
            Assert.Equal(QueryType.JoinsSave, Result.QueryType);
            Result = TestObject.GenerateQueries(TempManyToOneMany, ManyToOneManyProperty)[1];
            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Equal(2, Result.Parameters.Length);
            Assert.Equal(10, Result.Parameters[0].InternalValue);
            Assert.Equal(2, Result.Parameters[1].InternalValue);
            Assert.Equal("ManyToOneManyProperties_ID_", Result.Parameters[0].ID);
            Assert.Equal("ID_", Result.Parameters[1].ID);
            Assert.Equal("UPDATE [dbo].[ManyToOneOneProperties_] SET [dbo].[ManyToOneOneProperties_].[ManyToOneManyProperties_ID_] = @ManyToOneManyProperties_ID_ FROM [dbo].[ManyToOneOneProperties_] WHERE [dbo].[ManyToOneOneProperties_].[ID_] = @ID_;", Result.QueryString);
            Assert.Equal(QueryType.JoinsSave, Result.QueryType);
        }
Exemplo n.º 3
0
        public async Task UpdateWithNoDataInDatabase()
        {
            await DeleteData().ConfigureAwait(false);

            _ = new SchemaManager(MappingManager, Configuration, Logger, DataModeler, Sherlock, Helper);
            var TestObject = Canister.Builder.Bootstrapper.Resolve <ISession>();
            var Result     = new ManyToOneManyProperties
            {
                BoolValue = false
            };

            Result.ManyToOneClass.Add(new ManyToOneOneProperties
            {
                BoolValue = true
            });
            await TestObject.Save(Result).ExecuteAsync().ConfigureAwait(false);

            var Results = await TestObject.ExecuteAsync <ManyToOneManyProperties>("SELECT ID_ as [ID] FROM ManyToOneManyProperties_", CommandType.Text, "Default").ConfigureAwait(false);

            Assert.Single(Results);
        }
Exemplo n.º 4
0
        public void GenerateQueryWithManyToOneManyProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new ManyToOneManyPropertiesMapping(),
                new ManyToOneOnePropertiesMapping()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);

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

            ManyToOneManyProperty.Setup(Mappings, TempDataModel.SourceSpec);

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

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

            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].[ManyToOneManyProperties_].[ID_] AS [ID],[dbo].[ManyToOneManyProperties_].[BoolValue_] AS [BoolValue]\r\nFROM [dbo].[ManyToOneManyProperties_]\r\nWHERE ([dbo].[ManyToOneManyProperties_].[ID_]=@ID0);", Result.QueryString);
            Assert.Equal(QueryType.LoadData, Result.QueryType);
        }
Exemplo n.º 5
0
        private async Task SetupDataAsync()
        {
            var TestObject = new SchemaManager(MappingManager, Configuration, Logger, DataModeler, Sherlock, Helper);
            var Session    = Canister.Builder.Bootstrapper.Resolve <ISession>();
            await Helper
            .CreateBatch()
            .AddQuery(CommandType.Text, "DELETE FROM ManyToOneManyProperties_")
            .AddQuery(CommandType.Text, "DELETE FROM ManyToOneManyCascadeProperties_")
            .ExecuteScalarAsync <int>().ConfigureAwait(false);

            var InitialData = new ManyToOneManyCascadeProperties[]
            {
                new ManyToOneManyCascadeProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToOneManyCascadeProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToOneManyCascadeProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
            };
            var InitialData2 = new ManyToOneManyProperties[]
            {
                new ManyToOneManyProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToOneManyProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToOneManyProperties
                {
                    BoolValue      = true,
                    ManyToOneClass = new List <ManyToOneOneProperties>
                    {
                        new ManyToOneOneProperties
                        {
                            BoolValue = true
                        }
                    }
                },
            };

            await Session.Save(InitialData2.SelectMany(x => x.ManyToOneClass).ToArray()).ExecuteAsync().ConfigureAwait(false);

            await Session.Save(InitialData).ExecuteAsync().ConfigureAwait(false);

            await Session.Save(InitialData2).ExecuteAsync().ConfigureAwait(false);
        }