Exemple #1
0
        public async Task Update()
        {
            var fixture = new DbFixtureInitDb();
            await fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer(0);

            await Update(container);

            await container.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer(0);

            var category = await container.Categories.Where(t => t.Name == "sombrero jacket").SingleAsync();

            Assert.Equal("jackets", (await container.Categories.Where(t => t.Id == category.ParentId).SingleAsync()).Name);

            Assert.Equal(4, (await container.Customers.ToListAsync()).Count);
            Assert.Equal(4, (await container.Orders.ToListAsync()).Count);
            Assert.Equal(7, (await container.OrderItems.ToListAsync()).Count);

            var order1 = await container.Orders.ByKey(1).Expand(t => t.Items).GetValueAsync();

            Assert.Equal("New Order 1", order1.Name);
            Assert.Equal("New Product order 1 item 3", order1.Items.Single(t => t.Id == 3).Product);

            Assert.Equal(Sex.Female, (await container.Customers.ByKey("RU", 1).GetValueAsync()).Sex);
            Assert.Equal(null, (await container.Customers.ByKey("EN", 1).GetValueAsync()).Sex);
        }
        public async Task Add()
        {
            var fixture = new DbFixtureInitDb(true);
            await fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer(0);

            Add(container);
            await container.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer(0);

            Assert.Equal(8, (await container.Categories.ToListAsync()).Count);
            Assert.Equal(4, (await container.Customers.ToListAsync()).Count);
            Assert.Equal(3, (await container.Orders.ToListAsync()).Count);
            Assert.Equal(7, (await container.OrderItems.ToListAsync()).Count);

            var category = await container.Categories.Where(t => t.Name == "jackets").SingleAsync();

            Assert.Equal("clothes", (await container.Categories.Where(t => t.Id == category.ParentId).SingleAsync()).Name);
            Assert.Equal(2, (await container.Categories.Where(t => t.ParentId == category.Id).ToListAsync()).Count);

            var order1 = await container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 1").SingleAsync();

            Assert.Equal(3, order1.Items.Count());

            var order2 = await container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 2").SingleAsync();

            Assert.Equal(2, order2.Items.Count());

            var order3 = await container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order unknown").SingleAsync();

            Assert.Equal(2, order3.Items.Count());
        }
Exemple #3
0
        public Task Update()
        {
            var fixture = new DbFixtureInitDb();

            fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer();

            Update(container);
            container.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer();

            var category = container.Categories.Where(t => t.Name == "sombrero jacket").Single();

            Assert.Equal("jackets", container.Categories.Where(t => t.Id == category.ParentId).Single().Name);

            Assert.Equal(4, container.Customers.Count());
            Assert.Equal(3, container.Orders.Count());
            Assert.Equal(7, container.OrderItems.Count());

            var order1 = container.Orders.ByKey(1).Expand(t => t.Items).GetValue();

            Assert.Equal("New Order 1", order1.Name);
            Assert.Equal("New Product order 1 item 3", order1.Items.Single(t => t.Id == 3).Product);

            Assert.Equal(Sex.Female, container.Customers.ByKey(1).GetValue().Sex);
            Assert.Equal(null, container.Customers.ByKey(2).GetValue().Sex);

            return(Task.CompletedTask);
        }
Exemple #4
0
        public async Task ScalarFunctionWithParameters_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);
            int       value     = await container.ScalarFunctionWithParameters(1, "Order 1", null).GetValueAsync();

            int expected = Execute(c => c.ScalarFunctionWithParameters(1, "Order 1", null));

            Assert.Equal(expected, value);
        }
Exemple #5
0
        public async Task ScalarFunction_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);
            int       value     = await container.ScalarFunction().GetValueAsync();

            int expected = Execute(c => c.ScalarFunction());

            Assert.Equal(expected, value);
        }
Exemple #6
0
        public async Task TableFunctionWithCollectionParameter_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);

            String[] items = await container.TableFunctionWithCollectionParameter(new[] { "Foo", "Bar", "Baz" }).ToArrayAsync();

            var expected = Execute(c => c.TableFunctionWithCollectionParameter(new[] { "Foo", "Bar", "Baz" }));

            Assert.Equal(expected.Length, items.Length);
        }
Exemple #7
0
        public async Task TableFunction_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);

            Order[] orders = await container.TableFunction().ToArrayAsync();

            var expected = Execute(c => c.TableFunction());

            Assert.Equal(expected.Length, orders.Length);
        }
Exemple #8
0
        public async Task GetOrders_status_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);

            Order[] orders = await container.GetOrders(null, null, OrderStatus.Processing).ToArrayAsync();

            var expected = Execute(c => c.GetOrders(null, null, Model.OrderStatus.Processing));

            Assert.Equal(expected.Length, orders.Length);
        }
Exemple #9
0
        public async Task GetOrders_name_get()
        {
            Container container = DbFixtureInitDb.CreateContainer(0);

            Order[] orders = await container.GetOrders(null, "Order 1", null).ToArrayAsync();

            var expected = Execute(c => c.GetOrders(null, "Order 1", null));

            Assert.Equal(expected.Length, orders.Length);
        }
        public async Task Delete()
        {
            var fixture = new DbFixtureInitDb();
            await fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer(0);

            Delete(container);
            await container.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer(0);

            Assert.Equal(5, (await container.Categories.ToListAsync()).Count);
            Assert.Equal(4, (await container.Customers.ToListAsync()).Count);
            Assert.Equal(2, (await container.Orders.ToListAsync()).Count);
            Assert.Equal(3, (await container.OrderItems.ToListAsync()).Count);

            var order1 = await container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 1").SingleAsync();

            Assert.Equal("Product order 1 item 3", order1.Items.Single().Product);
        }
Exemple #11
0
        public Task Add()
        {
            var fixture = new DbFixtureInitDb(true);

            fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer();

            Add(container);
            container.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer();

            Assert.Equal(8, container.Categories.Count());
            Assert.Equal(4, container.Customers.Count());
            Assert.Equal(3, container.Orders.Count());
            Assert.Equal(7, container.OrderItems.Count());

            var category = container.Categories.Where(t => t.Name == "jackets").Single();

            Assert.Equal("clothes", container.Categories.Where(t => t.Id == category.ParentId).Single().Name);
            Assert.Equal(2, container.Categories.Where(t => t.ParentId == category.Id).Count());

            var order1 = container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 1").Single();

            Assert.Equal(3, order1.Items.Count());

            var order2 = container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 2").Single();

            Assert.Equal(2, order2.Items.Count());

            var order3 = container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order unknown").Single();

            Assert.Equal(2, order3.Items.Count());

            return(Task.CompletedTask);
        }
Exemple #12
0
        public Task Delete()
        {
            var fixture = new DbFixtureInitDb();

            fixture.Initalize();

            Container container = DbFixtureInitDb.CreateContainer();

            Delete(container);
            container.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            container = DbFixtureInitDb.CreateContainer();

            Assert.Equal(5, container.Categories.Count());
            Assert.Equal(4, container.Customers.Count());
            Assert.Equal(2, container.Orders.Count());
            Assert.Equal(5, container.OrderItems.Count());

            var order1 = container.Orders.Expand(t => t.Items).Where(t => t.Name == "Order 1").Single();

            Assert.Equal("Product order 1 item 3", order1.Items.Single().Product);

            return(Task.CompletedTask);
        }