示例#1
0
        public async Task QueryReturnsCorrectCommand(SliceFixture fixture)
        {
            var category1 = new Category()
            {
                Name = "Category1"
            };
            var category2 = new Category()
            {
                Name = "Category2"
            };

            await fixture.InsertAsync(category1, category2);

            var query = new Create.Query();

            var command = await fixture.SendAsync(query);

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

            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);
        }
示例#2
0
        public async Task Should_create_new_department(SliceFixture fixture)
        {
            var admin = new Instructor
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };

            await fixture.InsertAsync(admin);

            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);
        }
示例#3
0
        public async Task CanCreate(SliceFixture fixture)
        {
            var category = new Category
            {
                Name = "A category"
            };

            await fixture.InsertAsync(category);

            var command = new Create.Command
            {
                Name        = "A product",
                Description = "A description",
                Category    = category,
                Price       = 120.00m
            };

            await fixture.SendAsync(command);

            var created = await fixture
                          .ExecuteDbContextAsync(db => db
                                                 .Products
                                                 .Include(p => p.Category)
                                                 .Where(p => p.Name == command.Name)
                                                 .SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.Name.ShouldBe(command.Name);
            created.Price.ShouldBe(command.Price);
            created.Description.ShouldBe(command.Description);
            created.Category.Name.ShouldBe(category.Name);
        }
        public async Task ResponseReturnsCorrectData(SliceFixture fixture)
        {
            //Arrange
            var department = new Department
            {
                Name      = "Physics",
                StartDate = new DateTime(2013, 01, 01),
                Budget    = 12903.00m
            };

            await fixture.InsertAsync(department);

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

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

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

            response.Id.ShouldBe(courseInDb.Id);
            response.Title.ShouldBe(courseInDb.Title);
            response.Credits.ShouldBe(courseInDb.Credits);
            response.DepartmentName.ShouldBe(courseInDb.Department.Name);
        }
        public async Task ResponseReturnsCorrectData(SliceFixture fixture)
        {
            //Arrange
            var student = new Student
            {
                FirstName      = "Another",
                LastName       = "Student",
                EnrollmentDate = new DateTime(2014, 01, 04)
            };

            await fixture.InsertAsync(student);

            var editCommand = new Edit.Command
            {
                Id             = student.Id,
                FirstName      = "Modified",
                LastName       = "Name",
                EnrollmentDate = new DateTime(2013, 01, 04)
            };

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

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

            response.ShouldNotBeNull();
            response.FirstName.ShouldBe(editCommand.FirstName);
            response.LastName.ShouldBe(editCommand.LastName);
            response.EnrollmentDate.ShouldBe((DateTime)editCommand.EnrollmentDate);
        }
        public async Task Should_delete(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
            };

            var course = new Course
            {
                Credits    = 4,
                Department = dept,
                Id         = 1234,
                Title      = "English 101"
            };

            await fixture.InsertAsync(admin, dept, course);

            await fixture.SendAsync(new Delete.Command {
                Id = course.Id
            });

            var result = await fixture.ExecuteDbContextAsync(db => db.Courses.Where(c => c.Id == course.Id).SingleOrDefaultAsync());

            result.ShouldBeNull();
        }
        public async Task Should_list_departments(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
            };
            var dept2 = new Department
            {
                Name          = "English",
                Administrator = admin,
                Budget        = 456m,
                StartDate     = DateTime.Today
            };

            await fixture.InsertAsync(admin, dept, dept2);

            var query = new Index.Query();

            var result = await fixture.SendAsync(query);

            result.ShouldNotBeNull();
            result.Count.ShouldBe(2);
        }
        private static async Task <Product> CreateSampleProduct(SliceFixture fixture)
        {
            var category = new Category
            {
                Name = "Category"
            };

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

            await fixture.InsertAsync(category);

            await fixture.SendAsync(createProductCommand);

            var productInDb = await fixture
                              .ExecuteDbContextAsync(db => db
                                                     .Products
                                                     .FirstOrDefaultAsync(p => p.Name == createProductCommand.Name));

            return(productInDb);
        }
示例#9
0
        public async Task CorrectlyDetectsIfDepartmentExists(SliceFixture fixture)
        {
            //Arrange
            var department = new Department
            {
                Name      = "Physics",
                StartDate = new DateTime(2013, 01, 01),
                Budget    = 12903.00m
            };

            await fixture.InsertAsync(department);

            //Act
            bool departmentExists = false;

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
            await fixture.ExecuteScopeAsync(async sp =>
            {
                departmentExists = sp.GetService <ICoursesValidator>()
                                   .DepartmentExistsInDb(department.Name);
            });

#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

            //Assert
            departmentExists.ShouldBeTrue();
        }
        public async Task ResponseReturnsCorrectData(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
            };

            var editedCourse = await fixture.SendAsync(editCommand);

            //Assert
            editedCourse.Id.ShouldBe(editCommand.Id);
            editedCourse.Title.ShouldBe(editCommand.Title);
            editedCourse.Credits.ShouldBe((int)editCommand.Credits);
            editedCourse.DepartmentName.ShouldBe(editCommand.Department.Name);
        }
示例#11
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);
        }
        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
            };
            var instructor = new Instructor
            {
                OfficeAssignment = new OfficeAssignment {
                    Location = "Austin"
                },
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };

            instructor.CourseInstructors.Add(new CourseInstructor {
                Course = english101, Instructor = instructor
            });

            await fixture.InsertAsync(englishDept, english101, english201, instructor);

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

            await fixture.SendAsync(command);

            var edited = await fixture.ExecuteDbContextAsync(db => db.Instructors.Where(i => i.Id == instructor.Id).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);
        }
示例#13
0
        public static async Task <CloudResource> CreateSimple(
            Sandbox sandbox,
            string vmNameSuffix = VirtualMachineConstants.NAME)
        {
            var sandboxResourceGroup = CloudResourceUtil.GetSandboxResourceGroupEntry(sandbox.Resources);
            var vmResource           = CreateVmResource(sandbox, sandboxResourceGroup, sandbox.Study.Name, vmNameSuffix);

            return(await SliceFixture.InsertAsync(vmResource));
        }
示例#14
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();
        }
示例#15
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);
        }
示例#16
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);
        }
        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);
        }
示例#18
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);
        }
示例#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 static async Task <Sandbox> Create(
            Study study,
            string sandboxName = SandboxConstants.NAME,
            string region      = TestConstants.REGION,
            SandboxPhase phase = SandboxPhase.Open,
            bool addDatasets   = false)
        {
            var sandbox = SandboxBasic(study.Id, study.Name, sandboxName, region, SandboxResources(region, study.Name, sandboxName), phase);

            AddDatasets(addDatasets, study, sandbox);

            return(await SliceFixture.InsertAsync(sandbox));
        }
示例#21
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);
        }
示例#22
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);
        }
示例#23
0
        public async Task Should_delete_instructor(SliceFixture fixture)
        {
            var instructor = new Instructor
            {
                OfficeAssignment = new OfficeAssignment {
                    Location = "Austin"
                },
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };
            var englishDept = new Department
            {
                Name          = "English",
                StartDate     = DateTime.Today,
                Administrator = instructor
            };
            var english101 = new Course
            {
                Department = englishDept,
                Title      = "English 101",
                Credits    = 4,
                Id         = 123
            };

            instructor.CourseInstructors.Add(new CourseInstructor {
                Course = english101, Instructor = instructor
            });

            await fixture.InsertAsync(instructor, englishDept, english101);

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

            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);
        }
示例#24
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();
        }
        public async Task Should_edit_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 admin2Id = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var admin2 = await fixture.FindAsync <Instructor>(admin2Id);

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

            var command = new Edit.Command
            {
                Id            = dept.Id,
                Name          = "English",
                Administrator = admin2,
                StartDate     = DateTime.Today.AddDays(-1),
                Budget        = 456m
            };

            await fixture.SendAsync(command);

            var result = await fixture.ExecuteDbContextAsync(db => db.Departments.Where(d => d.Id == dept.Id).Include(d => d.Administrator).SingleOrDefaultAsync());

            result.Name.ShouldBe(command.Name);
            result.Administrator.Id.ShouldBe(command.Administrator.Id);
            result.StartDate.ShouldBe(command.StartDate.GetValueOrDefault());
            result.Budget.ShouldBe(command.Budget.GetValueOrDefault());
        }
示例#26
0
        public async Task IndexReturnsAllCourses(SliceFixture fixture)
        {
            // Arrange
            Department someDept = new Department()
            {
                Name = "Some department"
            };

            Course[] coursesToInsert = new Course[]
            {
                new Course
                {
                    Title      = "Some course1",
                    Department = someDept
                },
                new Course
                {
                    Title      = "Some course2",
                    Department = someDept
                },
                new Course
                {
                    Title      = "Some course3",
                    Department = someDept
                },
            };

            await fixture.InsertAsync(coursesToInsert);

            var indexQuery = new Index.Query
            {
                SelectedDepartmentName = null
            };

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

            // Assert
            response.SelectedDepartmentName.ShouldBeNull();
            response.Courses.Count.ShouldBe(coursesToInsert.Length);

            for (int i = 0; i < coursesToInsert.Length; i++)
            {
                response.Courses.ElementAt(i).Title.ShouldBe(coursesToInsert[i].Title);
                response.Courses.ElementAt(i).DepartmentName.ShouldBe(coursesToInsert[i].Department.Name);
            }
        }
示例#27
0
        public async Task ResponseReturnsCorrectData(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
                    }
                }
            };

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

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

            response.Id.ShouldBe(instructorInDb.Id);
            response.FirstName.ShouldBe(instructorInDb.FirstName);
            response.LastName.ShouldBe(instructorInDb.LastName);
            response.HireDate.ShouldBe(instructorInDb.HireDate);
        }
示例#28
0
        public async Task CanEdit(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                UserName          = "******",
                FirstName         = "Some name",
                Password          = "******",
                ConfirmedPassword = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            var role = new UserRole
            {
                Name           = "Role1",
                NormalizedName = "ROLE1"
            };

            await fixture.InsertAsync(role);

            // Act
            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);

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

            updatedUser.Roles.Count.ShouldBe(1);
            updatedUser.Roles.ElementAt(0).RoleId.ShouldBe(role.Id);
        }
示例#29
0
        public static async Task Seed()
        {
            var region = new Infrastructure.Model.Region()
            {
                Created              = DateTime.UtcNow,
                CreatedBy            = "seed",
                Key                  = "norwayeast",
                Name                 = "Norway East",
                DiskSizeAssociations = new List <Infrastructure.Model.RegionDiskSize>()
                {
                    new Infrastructure.Model.RegionDiskSize()
                    {
                        DiskSize = new Infrastructure.Model.DiskSize()
                        {
                            Key = "standardssd-e1", DisplayText = "4 GB", Size = 4
                        }
                    },
                    new Infrastructure.Model.RegionDiskSize()
                    {
                        DiskSize = new Infrastructure.Model.DiskSize()
                        {
                            Key = "standardssd-e2", DisplayText = "8 GB", Size = 8
                        }
                    }
                },
                VmSizeAssociations = new List <Infrastructure.Model.RegionVmSize>()
                {
                    new Infrastructure.Model.RegionVmSize()
                    {
                        VmSize = new Infrastructure.Model.VmSize()
                        {
                            Key = "Standard_F1"
                        }
                    },
                    new Infrastructure.Model.RegionVmSize()
                    {
                        VmSize = new Infrastructure.Model.VmSize()
                        {
                            Key = "Standard_F2"
                        }
                    },
                }
            };

            await SliceFixture.InsertAsync(region);
        }
示例#30
0
        public static async Task <CloudResource> Create(
            Sandbox sandbox,
            string vmNameSuffix  = VirtualMachineConstants.NAME,
            string size          = VirtualMachineConstants.SIZE,
            string osCategory    = VirtualMachineConstants.OS_CATEGORY_WINDOWS,
            string os            = VirtualMachineConstants.OS_WINDOWS,
            bool deleted         = false,
            bool deleteSucceeded = false)
        {
            var sandboxResourceGroup = CloudResourceUtil.GetSandboxResourceGroupEntry(sandbox.Resources);

            var vmSettings = CreateVmSettingsString(size, osCategory, os);

            var vmResource = CreateVmResource(sandbox, sandboxResourceGroup, sandbox.Study.Name, vmNameSuffix, vmSettings, deleted: deleted, deleteSucceeded: deleteSucceeded);

            return(await SliceFixture.InsertAsync(vmResource));
        }