Example #1
0
        private TestDataKeys CreateTestData()
        {
            var testDataKeys = new TestDataKeys();

            // Some other user's ShoppingList and Permissions
            var userId = TestUtils.NewId();

            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(userId)))
            {
                var shoppingList = new ShoppingList {
                    Title = TestUtils.GetTestShoppingListTitle()
                };
                dbContext.ShoppingLists.Add(shoppingList);
                dbContext.SaveChanges();
                var shoppingListId = shoppingList.Id;
                dbContext.Permissions.AddRange(new List <Permission>
                {
                    new Permission {
                        PermissionTypeId = Permissions.Edit, UserId = userId, ShoppingListId = shoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.AddListItems, UserId = userId, ShoppingListId = shoppingListId
                    }
                });
                dbContext.SaveChanges();
            }

            // The user of interest's ShoppingLists and Permissions
            testDataKeys.UserId = TestUtils.NewId();
            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(testDataKeys.UserId)))
            {
                var shoppingList = new ShoppingList {
                    Title = TestUtils.GetTestShoppingListTitle()
                };
                dbContext.ShoppingLists.Add(shoppingList);
                dbContext.SaveChanges();
                testDataKeys.ShoppingListId = shoppingList.Id;
                dbContext.Permissions.AddRange(new List <Permission>
                {
                    new Permission {
                        PermissionTypeId = Permissions.Edit, UserId = testDataKeys.UserId, ShoppingListId = testDataKeys.ShoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.PickOrUnpickListItems, UserId = testDataKeys.UserId, ShoppingListId = testDataKeys.ShoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.View, UserId = testDataKeys.UserId, ShoppingListId = testDataKeys.ShoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.AddListItems, UserId = testDataKeys.UserId, ShoppingListId = testDataKeys.ShoppingListId
                    }
                });
                dbContext.SaveChanges();

                shoppingList = new ShoppingList {
                    Title = TestUtils.GetTestShoppingListTitle()
                };
                dbContext.ShoppingLists.Add(shoppingList);
                dbContext.SaveChanges();
                var shoppingListId2 = shoppingList.Id;
                dbContext.Permissions.AddRange(new List <Permission>
                {
                    new Permission {
                        PermissionTypeId = Permissions.Edit, UserId = testDataKeys.UserId, ShoppingListId = shoppingListId2
                    },
                    new Permission {
                        PermissionTypeId = Permissions.View, UserId = testDataKeys.UserId, ShoppingListId = shoppingListId2
                    },
                    new Permission {
                        PermissionTypeId = Permissions.AddListItems, UserId = testDataKeys.UserId, ShoppingListId = shoppingListId2
                    }
                });
                dbContext.SaveChanges();
            }

            // Yet another user's ShoppingList and Permissions
            userId = TestUtils.NewId();
            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(userId)))
            {
                var shoppingList = new ShoppingList {
                    Title = TestUtils.GetTestShoppingListTitle()
                };
                dbContext.ShoppingLists.Add(shoppingList);
                dbContext.SaveChanges();
                var shoppingListId = shoppingList.Id;
                dbContext.Permissions.AddRange(new List <Permission>
                {
                    new Permission {
                        PermissionTypeId = Permissions.Share, UserId = userId, ShoppingListId = shoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.Edit, UserId = userId, ShoppingListId = shoppingListId
                    },
                    new Permission {
                        PermissionTypeId = Permissions.AddListItems, UserId = userId, ShoppingListId = shoppingListId
                    }
                });
                dbContext.SaveChanges();
            }

            return(testDataKeys);
        }
Example #2
0
        private TestDataKeys CreateTestData()
        {
            var testDataKeys = new TestDataKeys();

            testDataKeys.Marker = "Shopping list to find";
            var userId = TestUtils.NewId();

            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(userId)))
            {
                dbContext.ShoppingLists.AddRange(new List <ShoppingList>
                {
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    }
                });
                dbContext.SaveChanges();
            }

            testDataKeys.UserId = TestUtils.NewId();
            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(testDataKeys.UserId)))
            {
                var shoppingList = new ShoppingList {
                    Title = testDataKeys.Marker
                };
                dbContext.ShoppingLists.Add(shoppingList);
                dbContext.ShoppingLists.Add(new ShoppingList {
                    Title = TestUtils.GetTestShoppingListTitle()
                });
                dbContext.SaveChanges();
                testDataKeys.ShoppingListId = shoppingList.Id;

                dbContext.ListItems.Add(new ListItem {
                    ShoppingListId = testDataKeys.ShoppingListId
                });
                dbContext.ListItems.Add(new ListItem {
                    ShoppingListId = testDataKeys.ShoppingListId
                });
                dbContext.SaveChanges();
            }

            userId = TestUtils.NewId();
            using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(userId)))
            {
                dbContext.ShoppingLists.AddRange(new List <ShoppingList>
                {
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                    new ShoppingList {
                        Title = TestUtils.GetTestShoppingListTitle()
                    },
                });
                dbContext.SaveChanges();
            }

            return(testDataKeys);
        }