Beispiel #1
0
        /// <summary>
        /// Gets the automatically generated DbCommand object required to perform insertions on the database.
        /// </summary>
        /// <returns>Insert command.</returns>
        public DbCommand GetInsertCommand()
        {
            var columns = GetQueryColumns();
            var cmd     = _provider.GetCommandForCurrentTransaction();

            AddParametersToCommand(cmd, columns);
            cmd.CommandText = GetInsertCommandText(columns);
            return(cmd);
        }
Beispiel #2
0
        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");
        }
Beispiel #3
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);
        }
Beispiel #4
0
        private CommandGenerator <FooIdentity> GetFooIdentityGenerator()
        {
            KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>();
            provider.GetCommandForCurrentTransaction().Returns(a => { return(new SqlCommand()); });

            IQuery <FooIdentity> query = CreateFooIdentityQuery();

            query.Select(p => new { p.Id, p.Plat });
            return(new CommandGenerator <FooIdentity>(GetFooIdentityTableInfo(), provider, query));
        }
Beispiel #5
0
        private CommandGenerator <Foo> GetUpsertFooGenerator()
        {
            KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>();
            provider.GetCommandForCurrentTransaction().Returns(a => { return(new SqlCommand()); });

            IQuery <Foo> query = CreateFooQuery();

            query.Select(p => new { p.Id, p.KrstneMeno, p.PropertyEnum, p.Plat, p.PropertyValueGenerator });
            return(new CommandGenerator <Foo>(GetFooTableInfo(), provider, query));
        }
Beispiel #6
0
        private CommandGenerator <FooPrimaryKeys> GetFooPrimaryKeyGenerator()
        {
            KORM.Query.IQueryProvider provider = Substitute.For <KORM.Query.IQueryProvider>();
            provider.GetCommandForCurrentTransaction().Returns(a => { return(new SqlCommand()); });

            IQuery <FooPrimaryKeys> query = CreateQuery <FooPrimaryKeys>();

            query.Select(p => new { FK1 = 1, FK2 = 2 });
            TableInfo tableInfo = CreateTableInfoFromDto <FooPrimaryKeys>();

            return(new CommandGenerator <FooPrimaryKeys>(tableInfo, provider, query));
        }
Beispiel #7
0
        public void ThrowMissingPrimaryKeyExceptionWhenGetDeleteCommand()
        {
            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.GetDeleteCommand();
            };

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