Esempio n. 1
0
        public async Task Should_get_edit_department_details()
        {
            var adminId = await SendAsync(new Pages.Instructors.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

            var dept = new Department
            {
                Name         = "History",
                InstructorID = adminId,
                Budget       = 123m,
                StartDate    = DateTime.Today
            };

            await InsertAsync(dept);

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

            var result = await SendAsync(query);

            result.ShouldNotBeNull();
            result.Name.ShouldBe(dept.Name);
            result.Administrator.Id.ShouldBe(adminId);
        }
Esempio n. 2
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_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);
        }
Esempio n. 4
0
        public async Task <ActionResult> EditAsync(Edit.Query query)
        {
            var result = await _mediator.Send(query);

            if (result == null)
            {
                return(NotFound(query.Id));
            }
            return(View(result));
        }
Esempio n. 5
0
        // GET: /Student/Edit/5
        public async Task <ActionResult> Edit(Edit.Query query)
        {
            var student = await _mediator.SendAsync(query);

            if (student == null)
            {
                return(HttpNotFound());
            }
            return(View(student));
        }
Esempio n. 6
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);
        }
Esempio n. 7
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 <IActionResult> Edit(Edit.Query request)
        {
            var command = await _mediator.Send(request);

            if (!command.ProductCategories.Any(productCategory => productCategory.Id == request.Id))
            {
                Response.StatusCode = 404;
                return(View("AdminLTE/_PageNotFound"));
            }

            return(View(command));
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public async Task Should_get_edit_department_details(ContosoUniversityCore.Features.Instructor.CreateEdit.Command instructor, Department dept)
        {
            var adminId = await SendAsync(instructor);

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

            dept.Administrator = admin;

            await InsertAsync(dept);

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

            var result = await SendAsync(query);

            result.ShouldNotBeNull();
            result.Name.ShouldBe(dept.Name);
            result.Administrator.Id.ShouldBe(admin.Id);
        }
Esempio n. 11
0
        public async Task Should_get_edit_details()
        {
            var cmd = new Create.Command
            {
                FirstMidName   = "Joe",
                LastName       = "Schmoe",
                EnrollmentDate = DateTime.Today
            };

            var studentId = await SendAsync(cmd);

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

            var result = await SendAsync(query);

            result.FirstMidName.ShouldBe(cmd.FirstMidName);
            result.LastName.ShouldBe(cmd.LastName);
            result.EnrollmentDate.ShouldBe(cmd.EnrollmentDate);
        }
Esempio n. 12
0
        public async Task QueryReturnsCorrectResult(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

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

            var command = await fixture.SendAsync(editQuery);

            // Assert
            command.Id.ShouldBe(category.Id);
            command.Name.ShouldBe(category.Name);
        }
Esempio n. 13
0
        public async Task QueryReturnsCorrectResults(SliceFixture fixture)
        {
            // Arrange
            var role = new UserRole
            {
                Name = "Role1"
            };

            await fixture.InsertAsync(role);

            var query = new Edit.Query
            {
                RoleId = role.Id
            };

            // Act
            var model = await fixture.SendAsync(query);

            // Assert
            model.Id.ShouldBe(role.Id);
            model.Name.ShouldBe(role.Name);
        }
Esempio n. 14
0
 public async Task <IActionResult> EditAsync(Edit.Query query)
 {
     return(View(await _mediator.Send(query)));
 }
Esempio n. 15
0
        public async Task <IActionResult> Edit(Edit.Query query)
        {
            var model = await _mediator.SendAsync(query);

            return(View(model));
        }