Ejemplo n.º 1
0
        public async Task UpdateWithNoDataInDatabase()
        {
            try
            {
                await Helper.CreateBatch(SqlClientFactory.Instance, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false")
                .AddQuery(CommandType.Text, "ALTER DATABASE TestDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE\r\nALTER DATABASE TestDatabase SET ONLINE\r\nDROP DATABASE TestDatabase")
                .AddQuery(CommandType.Text, "ALTER DATABASE TestDatabase2 SET OFFLINE WITH ROLLBACK IMMEDIATE\r\nALTER DATABASE TestDatabase2 SET ONLINE\r\nDROP DATABASE TestDatabase2")
                .AddQuery(CommandType.Text, "ALTER DATABASE MockDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE\r\nALTER DATABASE MockDatabase SET ONLINE\r\nDROP DATABASE MockDatabase")
                .AddQuery(CommandType.Text, "ALTER DATABASE MockDatabaseForMockMapping SET OFFLINE WITH ROLLBACK IMMEDIATE\r\nALTER DATABASE MockDatabaseForMockMapping SET ONLINE\r\nDROP DATABASE MockDatabaseForMockMapping")
                .ExecuteScalarAsync <int>().ConfigureAwait(false);
            }
            catch { }
            _ = new SchemaManager(MappingManager, Configuration, Logger, DataModeler, Sherlock, Helper);
            var TestObject = Canister.Builder.Bootstrapper.Resolve <ISession>();
            var Result     = new ManyToManyPropertySelfReferencing
            {
                BoolValue = false
            };

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

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

            Assert.Equal(2, Results.Count());
        }
Ejemplo n.º 2
0
        public async Task InsertMultipleObjectsWithCascade()
        {
            var TestObject = Canister.Builder.Bootstrapper.Resolve <ISession>();

            await SetupDataAsync().ConfigureAwait(false);

            var Result1 = new ManyToManyPropertySelfReferencing
            {
                BoolValue = false
            };

            Result1.Children.Add(new ManyToManyPropertySelfReferencing
            {
                BoolValue = true
            });
            var Result2 = new ManyToManyPropertySelfReferencing
            {
                BoolValue = false
            };

            Result2.Children.Add(new ManyToManyPropertySelfReferencing
            {
                BoolValue = true
            });
            var Result3 = new ManyToManyPropertySelfReferencing
            {
                BoolValue = false
            };

            Result3.Children.Add(new ManyToManyPropertySelfReferencing
            {
                BoolValue = true
            });
            await TestObject.Save(Result1, Result2, Result3).ExecuteAsync().ConfigureAwait(false);

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

            Assert.Equal(12, Results.Count());
            Assert.Contains(Results, x => x.ID == Result1.ID &&
                            !x.BoolValue &&
                            x.Children.Count == 1 &&
                            x.Children.All(y => y.BoolValue));
            Assert.Contains(Results, x => x.ID == Result2.ID &&
                            !x.BoolValue &&
                            x.Children.Count == 1 &&
                            x.Children.All(y => y.BoolValue));
            Assert.Contains(Results, x => x.ID == Result3.ID &&
                            !x.BoolValue &&
                            x.Children.Count == 1 &&
                            x.Children.All(y => y.BoolValue));
        }
Ejemplo n.º 3
0
        private async Task SetupDataAsync()
        {
            _ = new SchemaManager(MappingManager, Configuration, Logger, DataModeler, Sherlock, Helper);
            var Session = Canister.Builder.Bootstrapper.Resolve <ISession>();
            await Helper
            .CreateBatch()
            .AddQuery(CommandType.Text, "DELETE FROM Parent_Child")
            .AddQuery(CommandType.Text, "DELETE FROM ManyToManyPropertySelfReferencing_")
            .ExecuteAsync()
            .ConfigureAwait(false);

            var InitialData = new ManyToManyPropertySelfReferencing[]
            {
                new ManyToManyPropertySelfReferencing
                {
                    BoolValue = true,
                    Children  = new List <ManyToManyPropertySelfReferencing>
                    {
                        new ManyToManyPropertySelfReferencing
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToManyPropertySelfReferencing
                {
                    BoolValue = true,
                    Children  = new List <ManyToManyPropertySelfReferencing>
                    {
                        new ManyToManyPropertySelfReferencing
                        {
                            BoolValue = true
                        }
                    }
                },
                new ManyToManyPropertySelfReferencing
                {
                    BoolValue = true,
                    Children  = new List <ManyToManyPropertySelfReferencing>
                    {
                        new ManyToManyPropertySelfReferencing
                        {
                            BoolValue = true
                        }
                    }
                }
            };
            await Session.Save(InitialData).ExecuteAsync().ConfigureAwait(false);
        }