Пример #1
0
        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);
        }
Пример #2
0
        public void ThrowMissingPrimaryKeyExceptionWhenGetUpdateCommand()
        {
            KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>();
            provider.GetCommandForCurrentTransaction().Returns(new SqlCommand());

            IQuery <Foo> query = CreateFooQuery();

            query.Select(p => new { p.Plat, p.KrstneMeno, p.PropertyGuid, p.PropertyEnum, p.PropertyEnumConv });

            var generator = new CommandGenerator <Foo>(GetFooTableInfo(false), provider, query);

            Action action = () =>
            {
                DbCommand update = generator.GetUpdateCommand();
            };

            action.Should().Throw <KORM.Exceptions.MissingPrimaryKeyException>();
        }