コード例 #1
0
        public void BuildInsertTest_with_nonNull_PK_and_KeyValue()
        {
            var data = new POCOMultiTypeObject()
            {
                ID = 1,
            };

            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            using (var command = DbProvider.CreateCommand())
            {
                commandBuilder.BuildInsert(command, data, ed.SourceName, ed.Fields, OnConflictOption.Default, keyValue: 101);
                var commandText = command.CommandText;
                Output.WriteLine(commandText);

                var idParam = command.Parameters["@ID"];
                idParam.Should().NotBeNull();
                idParam.Value.Should().Be(101);

                ValidateCommand(command);
                commandText.Should().Contain("@ID", "Insert with keyData should assign ID column");

                VerifyCommandSyntex(commandText);
            }
        }
コード例 #2
0
        void VerifyDataObjectInfoFields(EntityDescription doi)
        {
            Assert.NotNull(doi.Fields.PrimaryKeyField);
            Assert.NotNull(doi.Fields.PrimaryKeyField.Property.Getter);
            Assert.NotNull(doi.Fields.PrimaryKeyField.Property.Setter);

            VerifyField(doi, "ID");
            VerifyField(doi, "StringField");
            VerifyField(doi, "IntField");
            VerifyField(doi, "NIntField");
            VerifyField(doi, "LongField");
            VerifyField(doi, "NLongField");
            VerifyField(doi, "BoolField");
            VerifyField(doi, "NBoolField");
            VerifyField(doi, "FloatField");
            VerifyField(doi, "NFloatField");
            VerifyField(doi, "DoubleField");
            VerifyField(doi, "NDoubleField");
            VerifyField(doi, "GuidField");
            VerifyField(doi, "DateTimeField");

            VerifyField(doi, "PartialyPublicField");
            //VerifyField(doi, "PrivateField");
            VerifyField(doi, "CreatedBy");
            VerifyField(doi, "ModifiedBy");

            //verify non visible field
            VerifyNonvisableField(doi, "IgnoredField");
            VerifyNonvisableField(doi, "PartialyPublicAutomaticField");

            VerifyNonvisableField(doi, "PrivateIgnoredField", true);
            VerifyNonvisableField(doi, "PrivateAutomaticField", true);
            VerifyNonvisableField(doi, "IInterface.InterfaceProperty", true);
            VerifyNonvisableField(doi, "InterfaceProperty", true);
        }
コード例 #3
0
        public void BuildUpdateTest()
        {
            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            var data = new POCOMultiTypeObject()
            {
                ID = 1,
            };

            using (var command = DbProvider.CreateCommand())
            {
                commandBuilder.BuildUpdate(command, data, ed.SourceName, ed.Fields, option: OnConflictOption.Default);
                var commandText = command.CommandText;

                ValidateCommand(command);
                commandText.Should().Contain("ID", "");

                command.Parameters.OfType <DbParameter>().Where(x => x.ParameterName == "@ID")
                .Should().HaveCount(1);

                command.Parameters.OfType <DbParameter>().Select(x => x.ParameterName).Should().OnlyHaveUniqueItems();

                VerifyCommandSyntex(commandText);

                Output.WriteLine(command.CommandText);
            }

            //Assert.Throws(typeof(InvalidOperationException), () => commandBuilder.BuildUpdateCommand(provider, data, null, Core.SQL.OnConflictOption.Default));
        }
コード例 #4
0
        public void ReadData(System.Data.IDataReader reader, Object obj, EntityDescription discription, IDictionary <string, int> ordinalLookup)
        {
            var fields = discription.Fields;

            foreach (var field in fields)
            {
                if (ReadField(reader, ordinalLookup, field, out var value))
                {
                    field.SetFieldValue(obj, value);
                }
            }

            var keyField = fields.PrimaryKeyField;

            if (keyField != null)
            {
                if (ReadField(reader, ordinalLookup, keyField, out var value))
                {
                    keyField.SetFieldValue(obj, value);
                }
            }

            if (obj is IPersistanceTracking)
            {
                ((IPersistanceTracking)obj).OnRead();
            }
        }
コード例 #5
0
        public void BuildInsertTest()
        {
            var ed = new EntityDescription(typeof(POCOMultiTypeObject));
            var provider = new SQLite.SQLiteProviderFactory();

            var data = new POCOMultiTypeObject();

            var commandBuilder = ed.CommandBuilder;
            using (var command = commandBuilder.BuildInsertCommand(provider, data, null, Core.SQL.OnConflictOption.Default))
            {
                _output.WriteLine(command.CommandText);

                Assert.NotNull(command);
                AssertEx.NotNullOrWhitespace(command.CommandText);

                Assert.DoesNotContain("ID", command.CommandText);

                VerifyCommandSyntex(provider, command);
            }

            using (var command = commandBuilder.BuildInsertCommand(provider, data, 1, Core.SQL.OnConflictOption.Default))
            {
                _output.WriteLine(command.CommandText);

                Assert.NotNull(command);
                AssertEx.NotNullOrWhitespace(command.CommandText);

                Assert.Contains("ID", command.CommandText);

                VerifyCommandSyntex(provider, command);
            }
        }
コード例 #6
0
        public void Test_VanillaMultiTypeObject()
        {
            Type t   = typeof(POCOMultiTypeObject);
            var  doi = new EntityDescription(t);

            VerifyDataObjectInfo(t, doi);
        }
コード例 #7
0
        public void CreateInstanceOfEntityTest_WithPOCO()
        {
            var ed = new EntityDescription(typeof(POCOMultiTypeObject));

            var instance = ed.Inflator.CreateInstanceOfEntity();
            Assert.True(instance is POCOMultiTypeObject);
            Assert.NotNull(instance);
        }
コード例 #8
0
        private void VerifyDataObjectInfo(Type dataType, EntityDescription doi)
        {
            doi.Should().NotBeNull();
            doi.EntityType.Should().Be(dataType);
            doi.SourceName.Should().NotBeNullOrWhiteSpace();

            VerifyDataObjectInfoFields(doi);
        }
コード例 #9
0
        void VerifyDataObjectInfo(Type dataType, EntityDescription doi)
        {
            Assert.NotNull(doi);
            Assert.Equal(dataType, doi.EntityType);
            AssertEx.NotNullOrWhitespace(doi.SourceName);

            VerifyDataObjectInfoFields(doi);
        }
コード例 #10
0
        public void CreateInstanceOfEntityTest_WithOataObject()
        {
            var ed = new EntityDescription(typeof(DOMultiPropType));

            var instance = ed.Inflator.CreateInstanceOfEntity();
            Assert.True(instance is DOMultiPropType);
            Assert.NotNull(instance);
        }
コード例 #11
0
        public EntityCommandBuilder(EntityDescription entDesc)
        {
            EntityDescription = entDesc;

            if (EntityDescription.Source != null)
            {
                _selectCommand = MakeSelectCommand();
                //InitializeLegacySelectCommand();
            }
        }
コード例 #12
0
        private void VerifyField(EntityDescription doi, string fieldName)
        {
            doi.Fields.Should().Contain(x => x.Name == fieldName, because: fieldName);

            var field = doi.Fields.Where(x => x.Name == fieldName).Single();

            field.RunTimeType.Should().NotBeNull();
            field.Property.Getter.Should().NotBeNull();
            field.Property.Setter.Should().NotBeNull();

            field.PersistanceFlags.Should().HaveFlag(PersistanceFlags.OnUpdate);
            field.PersistanceFlags.Should().HaveFlag(PersistanceFlags.OnInsert);
        }
コード例 #13
0
        private void VerifyPKField(EntityDescription doi, string fieldName)
        {
            var pkField = doi.Fields.PrimaryKeyField;

            pkField.Should().NotBeNull();
            pkField.Name.Should().Be(fieldName);
            fieldName.Should().NotBeNullOrWhiteSpace();

            pkField.Property.Getter.Should().NotBeNull();
            pkField.Property.Setter.Should().NotBeNull();
            pkField.PersistanceFlags.Should().Be(PersistanceFlags.OnInsert);

            doi.Fields.Should().Contain(pkField);
        }
コード例 #14
0
        public void LoadDataObjects()
        {
            var types = (from t in System.Reflection.Assembly.GetAssembly(typeof(DataObject_Base)).GetTypes()
                         where t.IsClass && t.Namespace == "CruiseDAL.DataObjects"
                         select t).ToList();

            foreach (Type t in types)
            {
                _output.WriteLine(t.FullName);
                var doi = new EntityDescription(t);

                VerifyDataObjectInfo(t, doi);
            }
        }
コード例 #15
0
        public void MakeSelectCommandTest()
        {
            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            var selectBuilder = commandBuilder.BuildSelect(ed.Source, ed.Fields);
            var commandText   = selectBuilder.ToString();

            Output.WriteLine(commandText);

            commandText.Should().NotBeNullOrWhiteSpace();

            VerifyCommandSyntex(commandText);
        }
コード例 #16
0
        public void BuildSelectTest()
        {
            var ed = new EntityDescription(typeof(POCOMultiTypeObject));
            var provider = new SQLite.SQLiteProviderFactory();

            var commandBuilder = ed.CommandBuilder;
            using (var command = commandBuilder.BuildSelectCommand(provider, null))
            {
                _output.WriteLine(command.CommandText);
                Assert.NotNull(command);
                AssertEx.NotNullOrWhitespace(command.CommandText);
                VerifyCommandSyntex(provider, command);
            }
        }
コード例 #17
0
        public EntityDescription LookUpEntityByType(Type type)
        {
            lock (_entityDescriptionLookup)
            {
                if (!_entityDescriptionLookup.ContainsKey(type))
                {
                    var ed = new EntityDescription(type);
                    _entityDescriptionLookup.Add(type, ed);
                    return(ed);
                }

                return(_entityDescriptionLookup[type]);
            }
        }
コード例 #18
0
        public void ReadPrimaryKeyTest()
        {
            var poco = new POCOMultiTypeObject()
            {
                ID = 1
            };

            var reader = new TestSupport.ObjectDataReader <POCOMultiTypeObject>(new POCOMultiTypeObject[] { poco });

            Assert.True(reader.Read());

            var description = new EntityDescription(typeof(POCOMultiTypeObject));
            var inflator    = new EntityInflator(reader);

            inflator.ReadPrimaryKey(reader, description).Should().Be(1);
        }
コード例 #19
0
        public void ReadPrimaryKeyTest()
        {
            var poco = new POCOMultiTypeObject()
            {
                ID = 1
            };

            var reader = new TestSupport.ObjectDataReader<POCOMultiTypeObject>(new POCOMultiTypeObject[] { poco });
            Assert.True(reader.Read());

            var ed = new EntityDescription(typeof(POCOMultiTypeObject));

            ed.Inflator.CheckOrdinals(reader);
            var id = ed.Inflator.ReadPrimaryKey(reader);

            Assert.Equal(id, 1);
        }
コード例 #20
0
        public void ReadDataTest()
        {
            var poco = new POCOMultiTypeObject()
            {
                ID = 1,
                StringField = "1",
                IntField = 1
            };

            var reader = new TestSupport.ObjectDataReader<POCOMultiTypeObject>(new POCOMultiTypeObject[] { poco });
            Assert.True(reader.Read());

            var ed = new EntityDescription(typeof(POCOMultiTypeObject));

            var data = new POCOMultiTypeObject();
            ed.Inflator.CheckOrdinals(reader);
            ed.Inflator.ReadData(reader, data);

            Assert.Equal(data.StringField, "1");
            Assert.Equal(data.ID, 1);
        }
コード例 #21
0
        public void BuildInsert_With_null_pk()
        {
            var data = new POCOMultiTypeObject();

            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            using (var command = DbProvider.CreateCommand())
            {
                commandBuilder.BuildInsert(command, data, ed.SourceName, ed.Fields, OnConflictOption.Default);

                ValidateCommand(command);

                var commandText = command.CommandText;

                Output.WriteLine(commandText);
                commandText.Should().NotContain("@ID", "Insert with no keyData should not assign ID column");

                VerifyCommandSyntex(commandText);
            }
        }
コード例 #22
0
        public void FormatTest_WithAllFieldsAtOnce(string formatVariant)
        {
            var ed = new EntityDescription(typeof(DOMultiPropType));
            var formatter = new EntityFormatter(ed);
            var data = new DOMultiPropType();

            var formatString = String.Join(",",
                (from string field in TestSupport.TestSQLConstants.MULTI_PROP_TABLE_FIELDS
                 .Except(TestSupport.TestSQLConstants.NON_REFLECTED_MULTI_PROP_TABLE_FIELDS)
                 select "[" + field + formatVariant + "]"));

            _output.WriteLine(formatString);

            var formatedString = formatter.Format(formatString, data, null);
            Assert.NotNull(formatString);
            Assert.NotEmpty(formatString);

            Assert.NotEqual(formatString, formatedString);

            _output.WriteLine(formatedString);
        }
コード例 #23
0
        private void VerifyDataObjectInfoFields(EntityDescription doi)
        {
            var primaryKeyField = doi.Fields.PrimaryKeyField;


            VerifyPKField(doi, nameof(POCOMultiTypeObject.ID));
            VerifyField(doi, nameof(POCOMultiTypeObject.StringField));
            VerifyField(doi, nameof(POCOMultiTypeObject.IntField));
            VerifyField(doi, nameof(POCOMultiTypeObject.NIntField));
            VerifyField(doi, nameof(POCOMultiTypeObject.LongField));
            VerifyField(doi, nameof(POCOMultiTypeObject.NLongField));
            VerifyField(doi, nameof(POCOMultiTypeObject.BoolField));
            VerifyField(doi, nameof(POCOMultiTypeObject.NBoolField));
            VerifyField(doi, nameof(POCOMultiTypeObject.FloatField));
            VerifyField(doi, nameof(POCOMultiTypeObject.NFloatField));
            VerifyField(doi, nameof(POCOMultiTypeObject.DoubleField));
            VerifyField(doi, nameof(POCOMultiTypeObject.NDoubleField));
            VerifyField(doi, nameof(POCOMultiTypeObject.GuidField));
            VerifyField(doi, nameof(POCOMultiTypeObject.DateTimeField));
            VerifyField(doi, nameof(POCOMultiTypeObject.EnumField));

            VerifyField(doi, nameof(POCOMultiTypeObject.PartialyPublicField));
            VerifyField(doi, nameof(POCOMultiTypeObject.PartialyPublicAutomaticField));
            VerifyField(doi, nameof(POCOMultiTypeObject.AutomaticStringField));

            //VerifyField(doi, "PrivateField");

            //verify non visible field
            VerifyNonvisableField(doi, nameof(POCOMultiTypeObject.IgnoredField));
            VerifyNonvisableField(doi, nameof(POCOMultiTypeObject.ListField));
            VerifyNonvisableField(doi, nameof(POCOMultiTypeObject.ArrayField));
            VerifyNonvisableField(doi, nameof(POCOMultiTypeObject.ObjectField));

            VerifyNonvisableField(doi, "PrivateField");
            VerifyNonvisableField(doi, "PrivateIgnoredField");
            VerifyNonvisableField(doi, "PrivateAutomaticField");
            VerifyNonvisableField(doi, "IInterface.InterfaceProperty");
            VerifyNonvisableField(doi, "InterfaceProperty");
        }
コード例 #24
0
        public void BuildInsertTest_with_nonNull_PK_dont_persist_pk()
        {
            var data = new POCOMultiTypeObject()
            {
                ID = 1
            };

            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            using (var command = DbProvider.CreateCommand())
            {
                commandBuilder.BuildInsert(command, data, ed.SourceName, ed.Fields, OnConflictOption.Default, persistKeyvalue: false);
                var commandText = command.CommandText;
                Output.WriteLine(commandText);

                ValidateCommand(command);
                commandText.Should().NotContain("@ID");

                VerifyCommandSyntex(commandText);
            }
        }
コード例 #25
0
        public void FormatTest_WithSingleFieldAtaTime(string formatVariant)
        {
            var ed = new EntityDescription(typeof(DOMultiPropType));
            var formatter = new EntityFormatter(ed);
            var data = new DOMultiPropType();

            foreach (string fieldName in TestSupport.TestSQLConstants.MULTI_PROP_TABLE_FIELDS
                .Except(TestSupport.TestSQLConstants.NON_REFLECTED_MULTI_PROP_TABLE_FIELDS))
            {
                var formatString = "[" + fieldName + formatVariant + "]";

                _output.WriteLine(formatString);

                var formatedString = formatter.Format(formatString, data, null);
                Assert.NotNull(formatString);
                Assert.NotEmpty(formatString);

                Assert.NotEqual(formatString, formatedString);

                _output.WriteLine(formatedString);
            }
        }
コード例 #26
0
        public void BuildDeleteTest()
        {
            var data = new POCOMultiTypeObject()
            {
                ID = 1,
            };

            var ed             = new EntityDescription(typeof(POCOMultiTypeObject));
            var commandBuilder = new CommandBuilder();

            using (var command = DbProvider.CreateCommand())
            {
                commandBuilder.BuildDelete(command, data, ed.SourceName, ed.Fields);
                var commandText = command.CommandText;

                ValidateCommand(command);

                command.Parameters.Should().HaveCount(1);

                VerifyCommandSyntex(commandText);
                Output.WriteLine(command.CommandText);
            }
        }
コード例 #27
0
        public void ReadDataTest()
        {
            var poco = POCOMultiTypeObject.CreateWithID();

            var reader = new TestSupport.ObjectDataReader <POCOMultiTypeObject>(new POCOMultiTypeObject[] { poco });

            Assert.True(reader.Read());

            var description = new EntityDescription(typeof(POCOMultiTypeObject));
            var inflator    = new EntityInflator(reader);

            var data = new POCOMultiTypeObject();

            inflator.ReadData(reader, data, description);

            data.Should().BeEquivalentTo(poco, x =>
                                         x.Excluding(y => y.IgnoredField)
                                         .Excluding(y => y.ListField)
                                         .Excluding(y => y.ArrayField)
                                         .Excluding(y => y.ObjectField)
                                         .Excluding(y => y.StrDateTime) // for some reason this field isn't being reflected properly by the ObjectDataReader
                                         );
        }
コード例 #28
0
 public object ReadPrimaryKey(System.Data.IDataReader reader, EntityDescription discription)
 {
     return(ReadPrimaryKey(reader, OrdinalLookup, discription));
 }
コード例 #29
0
 public EntityFormatter(EntityDescription description)
 {
     _description = description;
 }
コード例 #30
0
 private void VerifyNonvisableField(EntityDescription doi, string fieldName)
 {
     doi.Fields.Should().NotContain(x => x.Name == fieldName);
 }
コード例 #31
0
        public EntityInflator(EntityDescription entity)
        {
            EntityDescription = entity;

            _constructor = EntityDescription.EntityType.GetConstructor(new Type[] { });
        }
コード例 #32
0
 public void ReadData(System.Data.IDataReader reader, Object obj, EntityDescription discription)
 {
     ReadData(reader, obj, discription, OrdinalLookup);
 }
コード例 #33
0
 public void Test_VanillaMultiTypeObject()
 {
     Type t = typeof(POCOMultiTypeObject);
     var doi = new EntityDescription(t);
     VerifyDataObjectInfo(t, doi);
 }
コード例 #34
0
 public void Test_DOMultiPropType()
 {
     var t = typeof(DOMultiPropType);
     var doi = new EntityDescription(t);
     VerifyDataObjectInfo(t, doi);
 }
コード例 #35
0
        public object ReadPrimaryKey(System.Data.IDataReader reader, IDictionary <string, int> ordinalMapping, EntityDescription discription)
        {
            var keyField = discription.Fields.PrimaryKeyField;

            if (keyField != null && ReadField(reader, OrdinalLookup, keyField, out var value))
            {
                return(value);
            }
            else
            {
                return(null);
            }
        }
コード例 #36
0
        void VerifyNonvisableField(EntityDescription doi, string fieldName, bool isPrivate)
        {
            Assert.DoesNotContain(doi.Fields, x => x.Name == fieldName);

            if (isPrivate)
            {
                Assert.DoesNotContain(doi.Properties, x => x.Key == fieldName);
            }
            else
            {
                Assert.Contains(doi.Properties, x => x.Key == fieldName);
            }
        }
コード例 #37
0
 void VerifyNonvisableField(EntityDescription doi, string fieldName)
 {
     VerifyNonvisableField(doi, fieldName, false);
 }
コード例 #38
0
        void VerifyField(EntityDescription doi, string fieldName)
        {
            _output.WriteLine("Verifying " + fieldName);
            Assert.Contains(doi.Fields, x => x.Name == fieldName);

            var field = doi.Fields[fieldName];
            Assert.NotNull(field);
            Assert.NotNull(field.Property.Getter);
            Assert.NotNull(field.Property.Setter);
            Assert.NotNull(field.RunTimeType);
            Assert.True(field.PersistanceFlags.HasFlag(PersistanceFlags.OnUpdate));
            Assert.True(field.PersistanceFlags.HasFlag(PersistanceFlags.OnInsert));

            _output.WriteLine("done");
        }