コード例 #1
0
        public async Task UpdateWithNoDataInDatabase()
        {
            var TestObject = Canister.Builder.Bootstrapper.Resolve <ISession>();
            await TestObject.Delete(DbContext <ManyToManyProperties> .CreateQuery().ToList().ToArray()).ExecuteAsync().ConfigureAwait(false);

            await TestObject.Delete(DbContext <AllReferencesAndID> .CreateQuery().ToList().ToArray()).ExecuteAsync().ConfigureAwait(false);

            var Result = new ManyToManyProperties
            {
                BoolValue = false
            };

            Result.ManyToManyClass.Add(new AllReferencesAndID
            {
                ByteArrayValue = new byte[] { 9, 10, 11, 12 },
                ByteValue      = 34,
                CharValue      = 'c',
                DateTimeValue  = new DateTime(2000, 1, 1)
            });
            await Assert.ThrowsAsync <SqlException>(async() => await TestObject.Save(Result).ExecuteAsync().ConfigureAwait(false)).ConfigureAwait(false);

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

            Assert.Single(Results);
        }
コード例 #2
0
ファイル: MappingBaseClass.cs プロジェクト: cjwang/Inflatable
 /// <summary>
 /// Copies the specified mapping.
 /// </summary>
 /// <param name="mapping">The mapping.</param>
 public void Copy(IMapping mapping)
 {
     if (mapping is null)
     {
         return;
     }
     foreach (var prop in mapping.IDProperties.Where(x => !IDProperties.Any(y => y.Name == x.Name)))
     {
         CopyProperty(prop);
     }
     foreach (var prop in mapping.ReferenceProperties.Where(x => !ReferenceProperties.Any(y => y.Name == x.Name)))
     {
         CopyProperty(prop);
     }
     foreach (var prop in mapping.MapProperties.Where(x => !MapProperties.Any(y => y.Name == x.Name)))
     {
         CopyProperty(prop);
     }
     foreach (var prop in mapping.ManyToManyProperties.Where(x => !ManyToManyProperties.Any(y => y.Name == x.Name)))
     {
         CopyProperty(prop);
     }
     foreach (var prop in mapping.ManyToOneProperties.Where(x => !ManyToOneProperties.Any(y => y.Name == x.Name)))
     {
         CopyProperty(prop);
     }
 }
コード例 #3
0
        public void GenerateQueryWithManyToManyProperties()
        {
            var Mappings = new MappingSource(new IMapping[] {
                new AllReferencesAndIDMappingWithDatabase(),
                new ManyToManyPropertiesMapping()
            },
                                             new MockDatabaseMapping(),
                                             new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger),
                                             Canister.Builder.Bootstrapper.Resolve <ILogger>(),
                                             ObjectPool);
            var ManyToManyProperty = Mappings.Mappings[typeof(ManyToManyProperties)].ManyToManyProperties.First();
            var TempDataModel      = new Inflatable.Schema.DataModel(Mappings, Configuration, Logger, DataModeler, Sherlock, Helper);

            ManyToManyProperty.Setup(Mappings, TempDataModel.SourceSpec);
            var TestObject     = new DeletePropertiesQuery <ManyToManyProperties>(Mappings, ObjectPool);
            var TempManyToMany = new ManyToManyProperties {
                ID = 10, BoolValue = true
            };

            TempManyToMany.ManyToManyClass.Add(new TestDatabases.SimpleTest.AllReferencesAndID {
                ID = 1
            });
            TempManyToMany.ManyToManyClass.Add(new TestDatabases.SimpleTest.AllReferencesAndID {
                ID = 2
            });
            var Result = TestObject.GenerateQueries(TempManyToMany, ManyToManyProperty)[0];

            Assert.Equal(CommandType.Text, Result.DatabaseCommandType);
            Assert.Single(Result.Parameters);
            Assert.Equal(10, Result.Parameters[0].InternalValue);
            Assert.Equal("ManyToManyProperties_ID_", Result.Parameters[0].ID);
            Assert.Equal("DELETE FROM [dbo].[AllReferencesAndID_ManyToManyProperties] WHERE ([dbo].[AllReferencesAndID_ManyToManyProperties].[ManyToManyProperties_ID_] = @ManyToManyProperties_ID_);", Result.QueryString);
            Assert.Equal(QueryType.JoinsDelete, Result.QueryType);
        }
コード例 #4
0
ファイル: MappingBaseClass.cs プロジェクト: cjwang/Inflatable
 /// <summary>
 /// Copies the property.
 /// </summary>
 /// <param name="prop">The property.</param>
 public void CopyProperty(IManyToManyProperty prop)
 {
     if (prop is null)
     {
         return;
     }
     ManyToManyProperties.Add(prop.Convert <TClassType>(this));
 }
コード例 #5
0
ファイル: MappingBaseClass.cs プロジェクト: cjwang/Inflatable
 /// <summary>
 /// Determines whether the mapping contains a property.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns><c>true</c> if the mapping contains the specified property; otherwise, <c>false</c>.</returns>
 public bool ContainsProperty(string propertyName)
 {
     return(IDProperties.Any(x => x.Name == propertyName) ||
            ReferenceProperties.Any(x => x.Name == propertyName) ||
            MapProperties.Any(x => x.Name == propertyName) ||
            ManyToManyProperties.Any(x => x.Name == propertyName) ||
            ManyToOneProperties.Any(x => x.Name == propertyName));
 }
コード例 #6
0
        public void GetAsParameter(ManyToManyProperties inputObject, object expectedResult)
        {
            var Result = TestObject.GetAsParameter(inputObject);

            Assert.Equal(DbType.Int64, Result.DatabaseType);
            Assert.Equal(ParameterDirection.Input, Result.Direction);
            Assert.Equal("ManyToManyClass_ID_", Result.ID);
            Assert.Equal(expectedResult, Result.InternalValue);
            Assert.Equal("@", Result.ParameterStarter);
        }
コード例 #7
0
ファイル: MappingBaseClass.cs プロジェクト: cjwang/Inflatable
        /// <summary>
        /// Sets a property as a many to many type.
        /// </summary>
        /// <typeparam name="TDataType">The type of the data type.</typeparam>
        /// <param name="expression">Expression pointing to the property</param>
        /// <returns>The many to many object</returns>
        public ManyToMany <TClassType, TDataType> ManyToMany <TDataType>(System.Linq.Expressions.Expression <Func <TClassType, IList <TDataType> > > expression)
            where TDataType : class
        {
            if (expression is null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var ReturnValue = new ManyToMany <TClassType, TDataType>(expression, this);

            ManyToManyProperties.Add(ReturnValue);
            return(ReturnValue);
        }
コード例 #8
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 ManyToManyProperties_")
            .AddQuery(CommandType.Text, "DELETE FROM ManyToManyPropertiesWithCascade_")
            .AddQuery(CommandType.Text, "DELETE FROM AllReferencesAndID_")
            .ExecuteScalarAsync <int>().ConfigureAwait(false);

            var InitialData = new ManyToManyProperties[]
            {
                new ManyToManyProperties
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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 ManyToManyProperties
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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 ManyToManyProperties
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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 ManyToManyPropertiesWithCascade[]
            {
                new ManyToManyPropertiesWithCascade
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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 ManyToManyPropertiesWithCascade
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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 ManyToManyPropertiesWithCascade
                {
                    BoolValue       = true,
                    ManyToManyClass = new List <AllReferencesAndID>()
                    {
                        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.SelectMany(x => x.ManyToManyClass).ToArray()).ExecuteAsync().ConfigureAwait(false);

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

            await Session.Save(InitialData2).ExecuteAsync().ConfigureAwait(false);
        }
コード例 #9
0
ファイル: MappingBaseClass.cs プロジェクト: cjwang/Inflatable
        /// <summary>
        /// Reduces this instance based on parent mapping properties.
        /// </summary>
        /// <param name="parentMapping">The parent mapping.</param>
        /// <param name="logger">The logger.</param>
        public void Reduce(IMapping parentMapping, ILogger logger)
        {
            if (parentMapping is null)
            {
                return;
            }
            var IsDebug = logger?.IsEnabled(Serilog.Events.LogEventLevel.Debug) ?? false;

            for (var x = 0; x < parentMapping.ReferenceProperties.Count; ++x)
            {
                var ReferenceProperty1 = parentMapping.ReferenceProperties[x];
                for (var y = 0; y < ReferenceProperties.Count; ++y)
                {
                    var ReferenceProperty2 = ReferenceProperties[y];
                    if (ReferenceProperty1.Similar(ReferenceProperty2))
                    {
                        if (IsDebug)
                        {
                            logger?.Debug("Found duplicate reference and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name);
                        }
                        ReferenceProperties.Remove(ReferenceProperty2);
                        --y;
                    }
                }
            }
            for (var x = 0; x < parentMapping.MapProperties.Count; ++x)
            {
                var ReferenceProperty1 = parentMapping.MapProperties[x];
                for (var y = x + 1; y < MapProperties.Count; ++y)
                {
                    var ReferenceProperty2 = MapProperties[y];
                    if (ReferenceProperty1.Similar(ReferenceProperty2))
                    {
                        if (IsDebug)
                        {
                            logger?.Debug("Found duplicate map and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name);
                        }
                        MapProperties.Remove(ReferenceProperty2);
                        --y;
                    }
                }
            }
            for (var x = 0; x < parentMapping.ManyToManyProperties.Count; ++x)
            {
                var ReferenceProperty1 = parentMapping.ManyToManyProperties[x];
                for (var y = x + 1; y < ManyToManyProperties.Count; ++y)
                {
                    var ReferenceProperty2 = ManyToManyProperties[y];
                    if (ReferenceProperty1.Similar(ReferenceProperty2))
                    {
                        if (IsDebug)
                        {
                            logger?.Debug("Found duplicate many to many and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name);
                        }
                        ManyToManyProperties.Remove(ReferenceProperty2);
                        --y;
                    }
                }
            }

            for (var x = 0; x < parentMapping.ManyToOneProperties.Count; ++x)
            {
                var ReferenceProperty1 = parentMapping.ManyToOneProperties[x];
                for (var y = x + 1; y < ManyToOneProperties.Count; ++y)
                {
                    var ReferenceProperty2 = ManyToOneProperties[y];
                    if (ReferenceProperty1.Similar(ReferenceProperty2))
                    {
                        if (IsDebug)
                        {
                            logger?.Debug("Found duplicate many to one and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name);
                        }
                        ManyToOneProperties.Remove(ReferenceProperty2);
                        --y;
                    }
                }
            }
        }
コード例 #10
0
 public void GetValue(ManyToManyProperties inputObject, object expectedResult) => Assert.Equal(expectedResult, TestObject.GetValue(inputObject));
コード例 #11
0
 public void SetValue(ManyToManyProperties inputObject, long newValue, object expectedResult)
 {
     TestObject.SetValue(inputObject, newValue);
     Assert.Equal(expectedResult, TestObject.GetValue(inputObject));
 }