Example #1
0
        public void Insert_Test()
        {
            var model = new Models.SampleModel()
            {
                Age     = 15,
                Created = new DateTime(2016, 05, 01, 23, 23, 0),
                Id      = 56,
                IsValid = true,
                Name    = "Test"
            };

            var insert = Builder.InsertModel.Create(model);

            Assert.NotNull(insert);
            Assert.NotNull(insert.Columns);
            Assert.NotNull(insert.Values);

            Assert.Equal(5, insert.Columns.Count);
            Assert.Equal(5, insert.Values.Count);

            Assert.Equal("age", insert.Columns[0]);
            Assert.Equal("created", insert.Columns[1]);
            Assert.Equal("id", insert.Columns[2]);
            Assert.Equal("is_valid", insert.Columns[3]);
            Assert.Equal("name", insert.Columns[4]);

            Assert.Equal("15", insert.Values[0]);
            Assert.Equal("'2016-05-01 23:23:00'", insert.Values[1]);
            Assert.Equal("56", insert.Values[2]);
            Assert.Equal("true", insert.Values[3]);
            Assert.Equal("'Test'", insert.Values[4]);

            Assert.Equal("\"public\".\"sample\"", insert.FullName);

            var query = $"INSERT INTO \"public\".\"sample\"(\"age\", \"created\", \"id\", \"is_valid\", \"name\") VALUES (15, '2016-05-01 23:23:00', 56, true, 'Test') RETURNING id;";

            Assert.Equal(query, insert.Build());

            query = $"INSERT INTO \"public\".\"sample\"(\"age\", \"created\", \"is_valid\", \"name\") VALUES (15, '2016-05-01 23:23:00', true, 'Test') RETURNING id;";
            Assert.Equal(query, insert.Build(true));

            var add = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("gender", "'male'") };

            query = $"INSERT INTO \"public\".\"sample\"(\"age\", \"created\", \"is_valid\", \"name\", \"gender\") VALUES (15, '2016-05-01 23:23:00', true, 'Test', 'male') RETURNING id;";
            Assert.Equal(query, insert.Build(true, add));
        }
Example #2
0
        public void Select_Test()
        {
            var model  = new Models.SampleModel();
            var select = Builder.SelectModel.Create(model);

            Assert.NotNull(select);
            Assert.NotNull(select.Columns);
            Assert.Equal(5, select.Columns.Count);
            Assert.Equal("id", select.Columns[0]);
            Assert.Equal("name", select.Columns[1]);
            Assert.Equal("age", select.Columns[2]);
            Assert.Equal("is_valid", select.Columns[3]);
            Assert.Equal("created", select.Columns[4]);

            Assert.Equal("\"public\".\"sample\"", select.FullName);

            var query = "SELECT \"id\", \"name\", \"age\", \"is_valid\", \"created\" FROM \"public\".\"sample\";";

            Assert.Equal(query, select.Build());
        }
Example #3
0
        public async void InsertAsync()
        {
            var model = new Models.SampleModel()
            {
                Age     = 56,
                Created = DateTime.UtcNow,
                Id      = 3,
                IsValid = false,
                Name    = "AddAsync"
            };

            // Clean
            var clean = await Query.VoidAsync("DELETE FROM sample WHERE id = 3;", this.Common.ConnectionString, this.Cancellation.Token);

            Assert.True(clean);

            // Insert
            var query = await Query.InsertAsync(model, this.Common.ConnectionString, this.Cancellation.Token);

            Assert.Equal(3, query);
        }
Example #4
0
        public void Insert()
        {
            var model = new Models.SampleModel()
            {
                Age     = 56,
                Created = DateTime.UtcNow,
                Id      = 2,
                IsValid = false,
                Name    = "Add"
            };

            // Clean
            var clean = Query.Void("DELETE FROM sample WHERE id = 2;", this.Common.ConnectionString);

            Assert.True(clean);

            // Insert
            var query = Query.Insert(model, this.Common.ConnectionString);

            Assert.Equal(2, query);
        }