public void FillCommandWithCorrectArguments() { var item = new Foo { Id = 336, Plat = 1500, KrstneMeno = "Homer", PropertyGuid = new Guid("{C0DC6F49-10A5-4AB7-9B9C-4152C25238BF}"), PropertyEnum = TestEnum.Value1, PropertyEnumConv = TestEnum.Value2 }; KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>(); provider.GetCommandForCurrentTransaction().Returns(new SqlCommand()); IQuery <Foo> query = CreateFooQuery(); query.Select(p => new { p.Id, p.Plat, p.KrstneMeno, p.PropertyGuid, p.PropertyEnum, p.PropertyEnumConv }); var generator = new CommandGenerator <Foo>(GetFooTableInfo(), provider, query); DbCommand insert = generator.GetInsertCommand(); generator.FillCommand(insert, item, ValueGenerated.OnInsert); insert.Parameters["@IdRow"].Value.Should().Be(336); insert.Parameters["@Salary"].Value.Should().Be((decimal)1500); insert.Parameters["@FirstName"].Value.Should().Be("Homer"); insert.Parameters["@PropertyGuid"].Value.Should().Be(new Guid("{C0DC6F49-10A5-4AB7-9B9C-4152C25238BF}")); insert.Parameters["@PropertyEnum"].Value.Should().Be(1); insert.Parameters["@PropertyEnumConv"].Value.Should().Be("V2"); }
public void CommandShouldNotContainGeneratedValueWhenIgnored() { var item = new Foo { PropertyValueGenerator = 552 }; KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>(); provider.GetCommandForCurrentTransaction().Returns(new SqlCommand()); IQuery <Foo> query = CreateFooQuery(); query.Select(p => new { p.PropertyValueGenerator }); var generator = new CommandGenerator <Foo>(GetFooTableInfo(ValueGenerated.OnInsertOrUpdate), provider, query); DbCommand insert = generator.GetInsertCommand(); DbCommand update = generator.GetUpdateCommand(); generator.FillCommand(insert, item, ValueGenerated.OnInsert, true); insert.Parameters["@PropertyValueGenerator"].Value.Should().Be(552); generator.FillCommand(update, item, ValueGenerated.OnUpdate, true); update.Parameters["@PropertyValueGenerator"].Value.Should().Be(552); }