Exemple #1
0
        public async Task InsertMultipleObjectsWithCascade()
        {
            var TestObject = Canister.Builder.Bootstrapper.Resolve <ISession>();

            await SetupDataAsync().ConfigureAwait(false);

            var Result1 = new MapPropertiesWithCascade
            {
                BoolValue   = false,
                MappedClass = new AllReferencesAndID
                {
                    ByteArrayValue = new byte[] { 1, 2, 3, 4 },
                    ByteValue      = 34,
                    CharValue      = 'a',
                    DateTimeValue  = new DateTime(2000, 1, 1)
                }
            };
            var Result2 = new MapPropertiesWithCascade
            {
                BoolValue   = false,
                MappedClass = new AllReferencesAndID
                {
                    ByteArrayValue = new byte[] { 5, 6, 7, 8 },
                    ByteValue      = 34,
                    CharValue      = 'b',
                    DateTimeValue  = new DateTime(2000, 1, 1)
                }
            };
            var Result3 = new MapPropertiesWithCascade
            {
                BoolValue   = false,
                MappedClass = new AllReferencesAndID
                {
                    ByteArrayValue = new byte[] { 9, 10, 11, 12 },
                    ByteValue      = 34,
                    CharValue      = 'c',
                    DateTimeValue  = new DateTime(2000, 1, 1)
                }
            };
            await TestObject.Save(Result1, Result2, Result3).ExecuteAsync().ConfigureAwait(false);

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

            Assert.Equal(6, Results.Count());
            Assert.Contains(Results, x => x.ID == Result1.ID &&
                            !x.BoolValue &&
                            x.MappedClass.ByteValue == 34 &&
                            x.MappedClass.CharValue == 'a' &&
                            x.MappedClass.DateTimeValue == new DateTime(2000, 1, 1));
            Assert.Contains(Results, x => x.ID == Result2.ID &&
                            !x.BoolValue &&
                            x.MappedClass.ByteValue == 34 &&
                            x.MappedClass.CharValue == 'b' &&
                            x.MappedClass.DateTimeValue == new DateTime(2000, 1, 1));
            Assert.Contains(Results, x => x.ID == Result3.ID &&
                            !x.BoolValue &&
                            x.MappedClass.ByteValue == 34 &&
                            x.MappedClass.CharValue == 'c' &&
                            x.MappedClass.DateTimeValue == new DateTime(2000, 1, 1));
        }
Exemple #2
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 AllReferencesAndID_")
            .AddQuery(CommandType.Text, "DELETE FROM MapProperties_")
            .AddQuery(CommandType.Text, "DELETE FROM MapPropertiesWithCascade_")
            .ExecuteScalarAsync <int>().ConfigureAwait(false);

            var InitialData = new MapProperties[]
            {
                new MapProperties
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
                new MapProperties
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
                new MapProperties
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
            };
            var InitialData2 = new MapPropertiesWithCascade[]
            {
                new MapPropertiesWithCascade
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
                new MapPropertiesWithCascade
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
                new MapPropertiesWithCascade
                {
                    BoolValue   = true,
                    MappedClass = new AllReferencesAndID
                    {
                        BoolValue         = true,
                        ByteValue         = 1,
                        NullableBoolValue = true,
                        CharValue         = 'a',
                        DateTimeValue     = new DateTime(2008, 1, 1),
                        DecimalValue      = 13.2m,
                        DoubleValue       = 423.12341234,
                        FloatValue        = 1243.1f,
                        GuidValue         = Guid.Parse("ad0d39ad-6889-4ab3-965d-3d4042344ee6"),
                        IntValue          = 12,
                        LongValue         = 2,
                        NullableByteValue = 1,
                        SByteValue        = 2,
                        ShortValue        = 1,
                        StringValue1      = "asdfvzxcv",
                        StringValue2      = "qwerertyizjgposgj",
                        ULongValue        = 12,
                        UIntValue         = 5342,
                        UShortValue       = 1234
                    }
                },
            };

            await Session.Save(InitialData.Select(x => x.MappedClass).ToArray()).ExecuteAsync().ConfigureAwait(false);

            await Session.Save(InitialData2.Select(x => x.MappedClass).ToArray()).ExecuteAsync().ConfigureAwait(false);

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

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