private POCOMultiTypeObject CreateRandomPoco(bool nullableSetNull = false) { var randomizer = new Bogus.Randomizer(); var poco = new POCOMultiTypeObject() { BoolField = randomizer.Bool(), DateTimeField = DateTime.Now, NDateTimeField = (nullableSetNull) ? (DateTime?)null : DateTime.Now, StrDateTime = (nullableSetNull) ? (string)null : DateTime.Now.ToShortTimeString(), DoubleField = randomizer.Double(), FloatField = randomizer.Float(), GuidField = randomizer.Guid(), NGuidField = (nullableSetNull) ? (Guid?)null : randomizer.Guid(), ID = randomizer.Int(), IntField = randomizer.Int(), LongField = randomizer.Long(), NBoolField = (nullableSetNull) ? (bool?)null : randomizer.Bool(), NDoubleField = (nullableSetNull) ? (double?)null : randomizer.Double(), NFloatField = (nullableSetNull) ? (float?)null : randomizer.Float(), NIntField = (nullableSetNull) ? (int?)null : randomizer.Int(), NLongField = (nullableSetNull) ? (long?)null : randomizer.Long(), //RowID = randomizer.Int(), StringField = randomizer.String2(16), }; return(poco); }
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)); }
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); } }
public void Insert() { using (var ds = new SQLiteDatastore()) { ds.CreateDatastore(new TestDBBuilder()); var ent = POCOMultiTypeObject.CreateWithNullID(); ent.ID.Should().BeNull(); ds.Insert(ent); ent.ID.Should().NotBeNull(); var entAgain = ds.From <POCOMultiTypeObject>().Query().Single(); ent.Should().BeEquivalentTo(entAgain); } }
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); }
public void FluentInterfaceTest_Single_Record(bool nulls) { using (var ds = new SQLiteDatastore()) { ds.Execute(TestDBBuilder.CREATE_MULTIPROPTABLE); var poco = POCOMultiTypeObject.CreateWithNullID(); ds.Insert(poco); var result = ds.From <MultiPropTypeWithAliases>().Query() .SingleOrDefault(); result.Should().NotBeNull(); poco.Should().BeEquivalentTo(result, config => config.ExcludingMissingMembers()); result.AliasForStringField.Should().Be(result.StringField); } }
public void FormatTest_WithSingleFieldAtaTime(string formatVariant) { var formatter = new EntityFormatter(typeof(POCOMultiTypeObject)); var data = new POCOMultiTypeObject(); 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); } }
public void FormatTest_WithAllFieldsAtOnce(string formatVariant) { var formatter = new EntityFormatter(typeof(POCOMultiTypeObject)); var data = new POCOMultiTypeObject(); 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); }
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); } }
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); } }
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 ); }
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); } }