Пример #1
0
        public async Task PaginationIsCorrect(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            var createCommands = new List <Create.Command>
            {
                new Create.Command
                {
                    Name        = "Product1",
                    Description = "Description",
                    Price       = 12.00m,
                    Category    = category,
                },
                new Create.Command
                {
                    Name        = "Product2",
                    Description = "Description",
                    Price       = 12.00m,
                    Category    = category,
                },
                new Create.Command
                {
                    Name        = "Product3",
                    Description = "Description",
                    Price       = 12.00m,
                    Category    = category,
                },
            };

            foreach (var command in createCommands)
            {
                await fixture.SendAsync(command);
            }

            // Act
            var query = new List.Query()
            {
                PageSize = 2, Page = 1
            };

            var result = await fixture.SendAsync(query);

            // Assert
            var productsInDb = await fixture
                               .ExecuteDbContextAsync(db => db
                                                      .Products
                                                      .ToListAsync());

            result.PagingInfo.CurrentPage.ShouldBe(query.Page);
            result.PagingInfo.ItemsPerPage.ShouldBe((int)query.PageSize);
            result.PagingInfo.TotalItems.ShouldBe(productsInDb.Count);
            result.Products.Count().ShouldBe((int)query.PageSize);
            result.PagingInfo.TotalPages.ShouldBe((int)Math.Ceiling((decimal)productsInDb.Count / (int)query.PageSize));
        }
Пример #2
0
        public async Task Should_create_new_department(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var command = new Create.Command
            {
                Budget        = 10m,
                Name          = "Engineering",
                StartDate     = DateTime.Now.Date,
                Administrator = admin
            };

            await fixture.SendAsync(command);

            var created = await fixture.ExecuteDbContextAsync(db => db.Departments.Where(d => d.Name == command.Name).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.Budget.ShouldBe(command.Budget.GetValueOrDefault());
            created.StartDate.ShouldBe(command.StartDate.GetValueOrDefault());
            created.InstructorID.ShouldBe(admin.Id);
        }
        public async Task Should_delete_department(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            await fixture.InsertAsync(dept);

            var command = new Delete.Command
            {
                Id         = dept.Id,
                RowVersion = dept.RowVersion
            };

            await fixture.SendAsync(command);

            var any = await fixture.ExecuteDbContextAsync(db => db.Departments.AnyAsync());

            any.ShouldBeFalse();
        }
Пример #4
0
        public async Task Should_list_departments(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            var dept2 = new Department
            {
                Name          = "English",
                Administrator = admin,
                Budget        = 456m,
                StartDate     = DateTime.Today
            };

            await fixture.InsertAsync(dept, dept2);

            var query = new Index.Query();

            var result = await fixture.SendAsync(query);

            result.ShouldNotBeNull();
            result.Count.ShouldBe(2);
        }
        private static async Task <Checkout.Command> Checkout(SliceFixture fixture, Register.Command registerUserCommand)
        {
            var userName = await fixture
                           .ExecuteDbContextAsync(db => db
                                                  .Users
                                                  .Select(u => u.UserName)
                                                  .FirstOrDefaultAsync(un => un == registerUserCommand.UserName));

            var query = new Checkout.Query
            {
                SenderUserName = userName
            };

            var command = await fixture.SendAsync(query);

            command.Name    = "Some name";
            command.Line1   = "An address";
            command.City    = "City";
            command.Country = "Country";
            command.Zip     = "Zip";
            command.State   = "State";

            await fixture.SendAsync(command);

            return(command);
        }
Пример #6
0
        public async Task CanEdit(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            // Act
            var editQuery = new Edit.Query
            {
                CategoryId = category.Id
            };

            CategoryEditViewModel viewModel = await fixture.SendAsync(editQuery);

            var command = Mapper.Map <Edit.Command>(viewModel);

            command.Name = "New category name";

            await fixture.SendAsync(command);

            // Assert
            var categoryInDb = await fixture
                               .ExecuteDbContextAsync(db => db
                                                      .Categories
                                                      .FirstOrDefaultAsync(c => c.Id == category.Id));

            categoryInDb.Name.ShouldBe(command.Name);
        }
        public async Task Should_get_instructor_details(SliceFixture fixture)
        {
            var englishDept = new Department
            {
                Name      = "English",
                StartDate = DateTime.Today
            };
            var english101 = new Course
            {
                Department = englishDept,
                Title      = "English 101",
                Credits    = 4,
                Id         = 123
            };
            await fixture.InsertAsync(englishDept, english101);

            var command = new CreateEdit.Command
            {
                FirstMidName             = "George",
                LastName                 = "Costanza",
                OfficeAssignmentLocation = "Austin",
                HireDate                 = DateTime.Today,
                SelectedCourses          = new[] { english101.Id.ToString() }
            };
            var instructorId = await fixture.SendAsync(command);

            var result = await fixture.SendAsync(new Details.Query {
                Id = instructorId
            });

            result.ShouldNotBeNull();
            result.FirstMidName.ShouldBe(command.FirstMidName);
            result.OfficeAssignmentLocation.ShouldBe(command.OfficeAssignmentLocation);
        }
Пример #8
0
        public async Task Should_get_edit_department_details(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            await fixture.InsertAsync(dept);

            var query = new Edit.Query
            {
                Id = dept.Id
            };

            var result = await fixture.SendAsync(query);

            result.ShouldNotBeNull();
            result.Name.ShouldBe(dept.Name);
            result.Administrator.Id.ShouldBe(admin.Id);
        }
        public async Task CanRemove(SliceFixture fixture)
        {
            // Arrange
            var createCommand = new Create.Command {
                Name = "Some role"
            };
            await fixture.SendAsync(createCommand);

            var addedRole = await fixture.ExecuteDbContextAsync(db => db
                                                                .Roles
                                                                .FirstOrDefaultAsync(r => r.Name == createCommand.Name));

            var removeCommand = new Remove.Command
            {
                RoleId = addedRole.Id
            };

            // Act
            await fixture.SendAsync(removeCommand);

            // Assert
            var roleAfterDeletion = await fixture.ExecuteDbContextAsync(db => db
                                                                        .Roles
                                                                        .FirstOrDefaultAsync(r => r.Id == removeCommand.RoleId));

            roleAfterDeletion.ShouldBeNull();
        }
Пример #10
0
        public async Task CanGetDetails(SliceFixture fixture)
        {
            //Arrange
            var department = new Department
            {
                Name = "Some department"
            };

            var course = new Course
            {
                Title      = "Course",
                Credits    = 3,
                Department = department
            };

            await fixture.InsertAsync(course);

            var createInstructorCommand = new CreateEdit.Command
            {
                FirstName       = "John",
                LastName        = "Smith",
                HireDate        = new DateTime(2012, 03, 01),
                SelectedCourses = new List <CourseInstructor>()
                {
                    new CourseInstructor()
                    {
                        Course = course, CourseId = course.Id
                    }
                }
            };

            var createdInstructor = await fixture.SendAsync(createInstructorCommand);

            //Act
            var detailsQuery = new Details.Query
            {
                Id = createdInstructor.Id
            };

            var response = await fixture.SendAsync(detailsQuery);

            //Assert
            var instructorInDb = await fixture.ExecuteDbContextAsync(context => context
                                                                     .Instructors
                                                                     .Include(i => i.CourseInstructors)
                                                                     .ThenInclude(c => c.Course)
                                                                     .FirstOrDefaultAsync(i => i.Id == createdInstructor.Id));

            response.ShouldNotBeNull();
            response.Id.ShouldBe(instructorInDb.Id);
            response.FirstName.ShouldBe(instructorInDb.FirstName);
            response.LastName.ShouldBe(instructorInDb.LastName);
            response.HireDate.ShouldBe(instructorInDb.HireDate);

            response.Courses.ElementAt(0).Id
            .ShouldBe(instructorInDb.CourseInstructors.ElementAt(0).CourseId);
            response.Courses.ElementAt(0).Title
            .ShouldBe(instructorInDb.CourseInstructors.ElementAt(0).Course.Title);
        }
Пример #11
0
        public async Task ListsAllProductsByDate(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            List <Create.Command> createProductsCommands = new List <Create.Command>
            {
                new Create.Command
                {
                    Name        = "Product",
                    Description = "Description",
                    Category    = category,
                    Price       = 100.00m
                },
                new Create.Command
                {
                    Name        = "Product1",
                    Description = "Description",
                    Category    = category,
                    Price       = 100.00m
                },
                new Create.Command
                {
                    Name        = "Product2",
                    Description = "Description",
                    Category    = category,
                    Price       = 100.00m
                },
            };

            foreach (var command in createProductsCommands)
            {
                await fixture.SendAsync(command);
            }

            // Act
            var query = new Products.Query();

            var result = await fixture.SendAsync(query);

            // Assert
            var productsInDb = await fixture
                               .ExecuteDbContextAsync(db => db
                                                      .Products
                                                      .OrderByDescending(p => p.DateAdded)
                                                      .ToListAsync());

            result.Count().ShouldBe(createProductsCommands.Count);
            result.Select(p => p.DateAdded)
            .SequenceEqual(productsInDb.Select(p => p.DateAdded))
            .ShouldBeTrue();
        }
Пример #12
0
        public async Task QueryReturnsCorrectResults(SliceFixture fixture)
        {
            // Arrange
            // Register a user and add him a role
            var registerUserCommand = new Register.Command
            {
                UserName          = "******",
                FirstName         = "Some name",
                Password          = "******",
                ConfirmedPassword = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            var role = new UserRole
            {
                Name = "Role1"
            };

            await fixture.InsertAsync(role);

            var registeredUser = await fixture.ExecuteDbContextAsync(db => db
                                                                     .Users
                                                                     .Include(u => u.Roles)
                                                                     .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName));

            var editCommand = new Edit.Command
            {
                Id            = registeredUser.Id,
                SelectedRoles = new List <string> {
                    role.Name
                }
            };

            await fixture.SendAsync(editCommand);

            // Act
            var query = new Edit.Query
            {
                UserId = registeredUser.Id
            };

            var response = await fixture.SendAsync(query);

            // Assert
            var updatedUser = await fixture.ExecuteDbContextAsync(db => db
                                                                  .Users
                                                                  .Include(u => u.Roles)
                                                                  .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName));

            response.AvailableRoles.Count.ShouldBe(1);
            response.User.Id.ShouldBe(updatedUser.Id);
            response.User.UserName.ShouldBe(updatedUser.UserName);
            response.User.Roles.Count.ShouldBe(updatedUser.Roles.Count);
        }
Пример #13
0
        public async Task CanEditProduct(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            var createCommand = new Create.Command
            {
                Name        = "Product",
                Description = "Description",
                Price       = 12.00m,
                Category    = category,
            };

            await fixture.SendAsync(createCommand);

            var product = await fixture
                          .ExecuteDbContextAsync(db => db
                                                 .Products
                                                 .FirstOrDefaultAsync(p => p.Name == createCommand.Name));

            // Act
            // Send the query with the product's id
            var query = new Edit.Query()
            {
                ProductId = product.Id
            };

            ProductEditViewModel viewModel = await fixture.SendAsync(query);

            var command = Mapper.Map <Edit.Command>(viewModel);

            // Change up some values
            command.Name        = "New product name";
            command.Description = "New description";
            command.Price       = 100.00m;

            // Send the command
            await fixture.SendAsync(command);

            // Assert
            // Get the now updated product
            var modifiedProduct = await fixture
                                  .ExecuteDbContextAsync(db => db
                                                         .Products
                                                         .FirstOrDefaultAsync(p => p.Id == product.Id));

            modifiedProduct.Name.ShouldBe(command.Name);
            modifiedProduct.Description.ShouldBe(command.Description);
            modifiedProduct.Price.ShouldBe(command.Price);
        }
Пример #14
0
        public async Task Should_delete_instructor(SliceFixture fixture)
        {
            var instructorId = await fixture.SendAsync(new CreateEdit.Command
            {
                FirstMidName             = "George",
                LastName                 = "Costanza",
                OfficeAssignmentLocation = "Austin",
                HireDate                 = DateTime.Today,
            });

            var englishDept = new Department
            {
                Name         = "English",
                StartDate    = DateTime.Today,
                InstructorID = instructorId
            };
            var english101 = new Course
            {
                Department = englishDept,
                Title      = "English 101",
                Credits    = 4,
                Id         = 123
            };

            await fixture.InsertAsync(englishDept, english101);

            await fixture.SendAsync(new CreateEdit.Command
            {
                Id                       = instructorId,
                FirstMidName             = "George",
                LastName                 = "Costanza",
                OfficeAssignmentLocation = "Austin",
                HireDate                 = DateTime.Today,
                SelectedCourses          = new[] { english101.Id.ToString() }
            });

            await fixture.SendAsync(new Delete.Command {
                ID = instructorId
            });

            var instructorCount = await fixture.ExecuteDbContextAsync(db => db.Instructors.CountAsync());

            instructorCount.ShouldBe(0);

            var englishDeptId = englishDept.Id;

            englishDept = await fixture.ExecuteDbContextAsync(db => db.Departments.FindAsync(englishDeptId));

            englishDept.InstructorID.ShouldBeNull();

            var courseInstructorCount = await fixture.ExecuteDbContextAsync(db => db.CourseInstructors.CountAsync());

            courseInstructorCount.ShouldBe(0);
        }
        public async Task Should_merge_course_instructors(SliceFixture fixture)
        {
            var englishDept = new Department
            {
                Name      = "English",
                StartDate = DateTime.Today
            };
            var english101 = new Course
            {
                Department = englishDept,
                Title      = "English 101",
                Credits    = 4,
                Id         = 123
            };
            var english201 = new Course
            {
                Department = englishDept,
                Title      = "English 201",
                Credits    = 4,
                Id         = 456
            };
            await fixture.InsertAsync(englishDept, english101, english201);

            var instructorId = await fixture.SendAsync(new CreateEdit.Command
            {
                FirstMidName             = "George",
                LastName                 = "Costanza",
                OfficeAssignmentLocation = "Austin",
                HireDate                 = DateTime.Today,
                SelectedCourses          = new[] { english101.Id.ToString() }
            });

            var command = new CreateEdit.Command
            {
                FirstMidName             = "Jerry",
                LastName                 = "Seinfeld",
                HireDate                 = DateTime.Today,
                OfficeAssignmentLocation = "Houston",
                SelectedCourses          = new[] { english201.Id.ToString() },
                Id = instructorId
            };

            await fixture.SendAsync(command);

            var edited = await fixture.ExecuteDbContextAsync(db => db.Instructors.Where(i => i.Id == instructorId).Include(i => i.CourseInstructors).Include(i => i.OfficeAssignment).SingleOrDefaultAsync());

            edited.FirstMidName.ShouldBe(command.FirstMidName);
            edited.LastName.ShouldBe(command.LastName);
            edited.HireDate.ShouldBe(command.HireDate.GetValueOrDefault());
            edited.OfficeAssignment.ShouldNotBeNull();
            edited.OfficeAssignment.Location.ShouldBe(command.OfficeAssignmentLocation);
            edited.CourseInstructors.Count.ShouldBe(1);
            edited.CourseInstructors.First().CourseID.ShouldBe(english201.Id);
        }
        public async Task CanRemoveFromCart(SliceFixture fixture)
        {
            // Arrange
            // Create a user who is going to remove his item
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            // Create him a product to add
            var createProductCommand = new Create.Command
            {
                Name        = "Product",
                Description = "Description",
                Category    = new Category {
                    Name = "Category"
                },
                Price = 100.00m
            };

            await fixture.SendAsync(createProductCommand);

            // Act
            // Get the product that was created by the command
            var product = await fixture
                          .ExecuteDbContextAsync(db => db
                                                 .Products
                                                 .FirstOrDefaultAsync(p => p.Name == createProductCommand.Name));

            // Send a remove command for the user and product
            var removeFromCartCommand = new RemoveFromCart.Command
            {
                CurrentUserName = registerUserCommand.UserName,
                ProductId       = product.Id
            };

            await fixture.SendAsync(removeFromCartCommand);

            // Assert
            var user = await fixture
                       .ExecuteDbContextAsync(db => db
                                              .Users
                                              .Include(u => u.Cart)
                                              .ThenInclude(c => c.OrderedItems)
                                              .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName));

            user.Cart.OrderedItems.Count.ShouldBe(0);
        }
Пример #17
0
        public async Task QueryReturnsCorrectCommand(SliceFixture fixture)
        {
            // Arrange
            var category = new Category()
            {
                Name = "Category1"
            };
            var secondCategory = new Category()
            {
                Name = "Category2"
            };

            await fixture.InsertAsync(category, secondCategory);

            var createCommand = new Create.Command
            {
                Name        = "Product",
                Description = "Description",
                Price       = 12.00m,
                Category    = category,
            };

            await fixture.SendAsync(createCommand);

            var product = await fixture
                          .ExecuteDbContextAsync(db => db
                                                 .Products
                                                 .Include(p => p.Category)
                                                 .FirstOrDefaultAsync(p => p.Name == createCommand.Name));

            // Act
            var query = new Edit.Query()
            {
                ProductId = product.Id
            };
            var command = await fixture.SendAsync(query);

            // Assert
            var categoriesInDb = new SelectList(await fixture
                                                .ExecuteDbContextAsync(db => db
                                                                       .Categories
                                                                       .Select(c => c.Name)
                                                                       .ToListAsync()));

            command.Name.ShouldBe(product.Name);
            command.Description.ShouldBe(product.Description);
            command.Price.ShouldBe(product.Price);
            command.Category.Name.ShouldBe(product.Category.Name);
            command.Categories.Count().ShouldBe(categoriesInDb.Count());
            command.Categories.First().Value.ShouldBe(categoriesInDb.First().Value);
            command.Categories.Skip(1).First().Value.ShouldBe(categoriesInDb.Skip(1).First().Value);
        }
        public async Task CanEdit(SliceFixture fixture)
        {
            //Arrange
            var department = new Department
            {
                Name      = "Physics",
                StartDate = new DateTime(2013, 01, 01),
                Budget    = 12903.00m
            };

            await fixture.InsertAsync(department);

            var createCourseCommand = new Create.Command
            {
                Title      = "New course",
                Credits    = 3,
                Department = department
            };

            var createdCourse = await fixture.SendAsync(createCourseCommand);

            var anotherDepartment = new Department
            {
                Name      = "Mathematics",
                StartDate = new DateTime(2011, 01, 01),
                Budget    = 12912.00m
            };

            await fixture.InsertAsync(anotherDepartment);

            //Act
            var editCommand = new Edit.Command
            {
                Id         = createdCourse.Id,
                Credits    = 5,
                Title      = "New course title",
                Department = anotherDepartment
            };

            await fixture.SendAsync(editCommand);

            //Assert
            var courseInDb = await fixture.ExecuteDbContextAsync(context => context
                                                                 .Courses
                                                                 .Include(c => c.Department)
                                                                 .FirstOrDefaultAsync(c => c.Title == editCommand.Title));

            courseInDb.Id.ShouldBe(editCommand.Id);
            courseInDb.Title.ShouldBe(editCommand.Title);
            courseInDb.Credits.ShouldBe((int)editCommand.Credits);
            courseInDb.Department.Name.ShouldBe(editCommand.Department.Name);
        }
Пример #19
0
        public async Task ClearsUserCartOnCompletion(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            var product = new Product
            {
                Name        = "Product",
                Description = "Description",
                DateAdded   = DateTime.Now,
                Category    = new Category()
                {
                    Name = "Category"
                },
                Price = 100.00m
            };

            await fixture.InsertAsync(product);

            var addItemQuery = new AddToCart.Command
            {
                CurrentUserName = registerUserCommand.UserName,
                ProductId       = product.Id
            };

            await fixture.SendAsync(addItemQuery);

            // Act
            var command = new Completed.Command
            {
                CurrentUserName = registerUserCommand.UserName
            };

            await fixture.SendAsync(command);

            // Assert
            var userInDb = await fixture
                           .ExecuteDbContextAsync(db => db
                                                  .Users
                                                  .Include(u => u.Cart)
                                                  .ThenInclude(c => c.OrderedItems)
                                                  .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName));

            userInDb.Cart.OrderedItems.Count.ShouldBe(0);
        }
Пример #20
0
        public async Task Should_edit(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            var newDept = new Department
            {
                Name          = "English",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };

            var course = new Course
            {
                Credits    = 4,
                Department = dept,
                Id         = 1234,
                Title      = "English 101"
            };
            await fixture.InsertAsync(dept, newDept, course);

            var command = new Edit.Command
            {
                Id         = course.Id,
                Credits    = 5,
                Department = newDept,
                Title      = "English 202"
            };
            await fixture.SendAsync(command);

            var edited = await fixture.FindAsync <Course>(course.Id);

            edited.ShouldNotBeNull();
            edited.DepartmentID.ShouldBe(newDept.Id);
            edited.Credits.ShouldBe(command.Credits.GetValueOrDefault());
            edited.Title.ShouldBe(command.Title);
        }
Пример #21
0
        public async Task Should_filter_courses(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin = await fixture.FindAsync <Instructor>(adminId);

            var englishDept = new Department
            {
                Name          = "English",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            var historyDept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };

            var english = new Course
            {
                Credits    = 4,
                Department = englishDept,
                Id         = 1235,
                Title      = "English 101"
            };
            var history = new Course
            {
                Credits    = 4,
                Department = historyDept,
                Id         = 4312,
                Title      = "History 101"
            };
            await fixture.InsertAsync(englishDept, historyDept, english, history);

            var result = await fixture.SendAsync(new Index.Query {
                SelectedDepartment = englishDept
            });

            result.ShouldNotBeNull();
            result.Courses.Count.ShouldBe(1);
            result.Courses[0].Id.ShouldBe(english.Id);
        }
Пример #22
0
        public async Task CanDelete(SliceFixture fixture)
        {
            //Arrange
            var department = new Department
            {
                Name = "Some department"
            };

            var course = new Course
            {
                Title      = "Course",
                Credits    = 3,
                Department = department
            };

            await fixture.InsertAsync(course);

            var createInstructorCommand = new CreateEdit.Command
            {
                FirstName       = "John",
                LastName        = "Smith",
                HireDate        = new DateTime(2012, 03, 01),
                SelectedCourses = new List <CourseInstructor>()
                {
                    new CourseInstructor()
                    {
                        Course = course, Instructor = new Instructor()
                    }
                }
            };

            var createdInstructor = await fixture.SendAsync(createInstructorCommand);

            //Act
            var deleteCommand = new Delete.Command
            {
                Id = createdInstructor.Id
            };

            await fixture.SendAsync(deleteCommand);

            //Assert
            var instructorInDb = await fixture.ExecuteDbContextAsync(context => context
                                                                     .Instructors
                                                                     .FirstOrDefaultAsync(i => i.Id == createdInstructor.Id));

            instructorInDb.ShouldBeNull();
        }
Пример #23
0
        public async Task FindsIfNameIsTaken(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            // Act
            var anotherRegisterCommand = new Register.Command
            {
                FirstName = "Mark",
                UserName  = "******",
                Password  = "******"
            };

            var nameNotTaken = true;

            await fixture.ExecuteScopeAsync(async sp =>
            {
                nameNotTaken = await sp.GetService <IUserValidator>()
                               .NameNotTakenAsync(anotherRegisterCommand.UserName, CancellationToken.None);
            });

            nameNotTaken.ShouldBeFalse();
        }
        public async Task CanMarkAsShipped(SliceFixture fixture)
        {
            // Arrange
            var order = new Order
            {
                Name    = "Some name",
                Line1   = "An address",
                City    = "City",
                Country = "Country",
                Zip     = "Zip",
                State   = "State",
                Shipped = false
            };

            await fixture.InsertAsync(order);

            // Act
            var command = new MarkShipped.Command()
            {
                OrderId = order.Id
            };

            await fixture.SendAsync(command);

            // Assert
            var orderInDb = await fixture
                            .ExecuteDbContextAsync(db => db
                                                   .Orders
                                                   .FirstOrDefaultAsync(o => o.Name == order.Name));

            orderInDb.Shipped.ShouldBeTrue();
        }
        public async Task CannotCheckoutWithEmptyCart(SliceFixture fixture)
        {
            // Arrange
            // Create a user
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            // Act
            var user = await fixture
                       .ExecuteDbContextAsync(db => db
                                              .Users
                                              .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName));

            bool canCheckout = true;

            // Get the custom validator and check whether it allows for checkout
            await fixture.ExecuteScopeAsync(async sp =>
            {
                canCheckout = await sp.GetService <IOrderValidator>()
                              .UserHasItemsInCartAsync(user.UserName, CancellationToken.None);
            });

            // Assert
            canCheckout.ShouldBeFalse();
        }
Пример #26
0
        public async Task CanDelete(SliceFixture fixture)
        {
            //Arrange
            var student = new Student
            {
                FirstName      = "Another",
                LastName       = "Student",
                EnrollmentDate = new DateTime(2014, 01, 04)
            };

            await fixture.InsertAsync(student);

            var deleteCommand = new Delete.Command
            {
                Id = student.Id
            };

            //Act
            await fixture.SendAsync(deleteCommand);

            //Assert
            var studentInDb = await fixture.ExecuteDbContextAsync(context => context
                                                                  .Students
                                                                  .FirstOrDefaultAsync(s => s.Id == student.Id));

            studentInDb.ShouldBeNull();
        }
        public async Task CanRemove(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            // Act
            var removeCommand = new Remove.Command
            {
                Id   = category.Id,
                Name = category.Name,
                ProductsInCategoryCount = 0
            };

            await fixture.SendAsync(removeCommand);

            // Assert
            var areThereCategoriesInTheDb = await fixture
                                            .ExecuteDbContextAsync(db => db
                                                                   .Categories
                                                                   .AnyAsync());

            areThereCategoriesInTheDb.ShouldBeFalse();
        }
Пример #28
0
        public async Task Should_get_department_details(SliceFixture fixture)
        {
            var admin = new Instructor
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            await fixture.InsertAsync(admin, dept);

            var query = new Details.Query
            {
                Id = dept.Id
            };

            var result = await fixture.SendAsync(query);

            result.ShouldNotBeNull();
            result.Name.ShouldBe(dept.Name);
            result.AdministratorFullName.ShouldBe(admin.FullName);
        }
        public async Task CanGetDetails(SliceFixture fixture)
        {
            //Arrange
            var student = new Student
            {
                FirstName      = "Another",
                LastName       = "Student",
                EnrollmentDate = new DateTime(2014, 01, 04)
            };

            await fixture.InsertAsync(student);

            var detailsQuery = new Details.Query
            {
                Id = student.Id
            };

            //Act
            var response = await fixture.SendAsync(detailsQuery);

            //Assert
            response.ShouldNotBeNull();
            response.FirstName.ShouldBe(student.FirstName);
            response.LastName.ShouldBe(student.LastName);
            response.EnrollmentDate.ShouldBe(student.EnrollmentDate);
        }
Пример #30
0
        public async Task CanEdit(SliceFixture fixture)
        {
            // Arrange
            var role = new UserRole
            {
                Name = "Role1"
            };

            await fixture.InsertAsync(role);

            // Act
            var editCommand = new Edit.Command
            {
                Id             = role.Id,
                Name           = role.Name + "Edited",
                SelectedClaims = new List <string>()
            };

            await fixture.SendAsync(editCommand);

            // Assert
            var editedRole = await fixture.ExecuteDbContextAsync(db => db.Roles
                                                                 .FirstOrDefaultAsync(r => r.Id == editCommand.Id));

            editedRole.Name.ShouldBe(editCommand.Name);
            editedRole.NormalizedName.ShouldBe(editedRole.Name.ToUpper());
        }