예제 #1
0
        public async Task CanAddToCart(SliceFixture fixture)
        {
            // Arrange
            var registeredUser = await RegisterUser(fixture);

            // Create him a product to add
            var createdProduct = await CreateSampleProduct(fixture);

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

            var addToCartCommand = new AddToCart.Command
            {
                CurrentUserName = registeredUser.UserName,
                ProductId       = product.Id
            };

            await fixture.SendAsync(addToCartCommand);

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

            user.Cart.OrderedItems.Count.ShouldBe(1);
            user.Cart.OrderedItems.First().Product.Name.ShouldBe(product.Name);
            user.Cart.OrderedItems.First().Quantity.ShouldBe(1);
        }
        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();
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #6
0
        public async Task Should_delete(SliceFixture fixture)
        {
            var admin = new Instructor
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };
            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Instructors.Add(admin);
                await db.SaveChangesAsync();
            });

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

            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Departments.Add(dept);
                await db.SaveChangesAsync();
            });

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

            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Courses.Add(course);
                await db.SaveChangesAsync();
            });

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

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

                result.ShouldBeNull();
            });
        }
예제 #7
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 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);
        }
예제 #9
0
        public async Task Should_query_for_command(SliceFixture fixture)
        {
            var admin = new Instructor
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };
            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Instructors.Add(admin);
                await db.SaveChangesAsync();
            });

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

            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Departments.Add(dept);
                await db.SaveChangesAsync();
            });

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

            await fixture.ExecuteDbContextAsync(async db =>
            {
                db.Courses.Add(course);
                await db.SaveChangesAsync();
            });

            var result = await fixture.SendAsync(new Edit.Query {
                Id = course.CourseID
            });

            result.ShouldNotBeNull();
            result.Credits.ShouldBe(course.Credits);
            result.Department.DepartmentID.ShouldBe(dept.DepartmentID);
            result.Title.ShouldBe(course.Title);
        }
예제 #10
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);
        }
 public static async Task <Article> QueryDefaultArticleDto()
 {
     return(await SliceFixture.ExecuteDbContextAsync(db =>
                                                     db.Articles.IncludeAllArticleInformationNotTracking()
                                                     .Include(i => i.Comments)
                                                     .SingleOrDefaultAsync()));
 }
예제 #12
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);
        }
예제 #13
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 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();
        }
예제 #15
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 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 ShouldUpdateArticle()
        {
            await Helper.EnsureUserIsCreatedAndSetInDatabaseContext();

            var originalArticle = await Helper.CreateDefaultArticle_ReturnDefaultArticleDto();

            Assert.AreEqual(2, originalArticle.ArticleTags.Count);

            var updatedTitle = originalArticle + " edited";
            var updatedTags  = originalArticle.ArticleTags.Select(i => i.Tag.Name).ToList();

            updatedTags.Add("tag3");

            var updateCommand = new UpdateArticleCommand()
            {
                Article = new UpdateArticleData()
                {
                    Slug    = originalArticle.Slug,
                    Title   = updatedTitle,
                    TagList = updatedTags
                }
            };

            await SliceFixture.ExecuteDbContextAsync(async (ctx, mediator) =>
            {
                await mediator.Send(updateCommand);
            });

            var updatedArticle = await Helper.QueryDefaultArticleDto();

            Assert.AreEqual(updatedTitle, updatedArticle.Title);
            Assert.AreEqual(3, updatedArticle.ArticleTags.Count);
        }
예제 #18
0
        public async Task Should_create_new_course(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 command = new Create.Command
            {
                Credits    = 4,
                Department = dept,
                Number     = 1234,
                Title      = "English 101"
            };
            await fixture.SendAsync(command);

            var created = await fixture.ExecuteDbContextAsync(db => db.Courses.Where(c => c.Id == command.Number).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.DepartmentID.ShouldBe(dept.Id);
            created.Credits.ShouldBe(command.Credits);
            created.Title.ShouldBe(command.Title);
        }
        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();
        }
        public async Task CanCheckout(SliceFixture fixture)
        {
            // Arrange
            var registeredUser = await RegisterUser(fixture);

            Product productInDb = await CreateSampleProduct(fixture);

            await AddProductToCart(fixture, registeredUser, productInDb);

            // Act
            var command = await Checkout(fixture, registeredUser);

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

            orderInDb.Name.ShouldBe(command.Name);
            orderInDb.Line1.ShouldBe(command.Line1);
            orderInDb.City.ShouldBe(command.City);
            orderInDb.Country.ShouldBe(command.Country);
            orderInDb.Zip.ShouldBe(command.Zip);
            orderInDb.State.ShouldBe(command.State);
        }
        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 administrator = new Instructor
            {
                FirstName = "John",
                LastName  = "Smith",
                HireDate  = new System.DateTime(1953, 01, 10)
            };

            await fixture.InsertAsync(administrator);

            var createDepartmentCommand = new Create.Command
            {
                Name          = "Some department",
                Budget        = 12000.00m,
                StartDate     = new System.DateTime(1953, 01, 10),
                Administrator = administrator
            };

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

            //Assert
            var departmentInDb = await fixture.ExecuteDbContextAsync(context => context
                                                                     .Departments
                                                                     .FirstOrDefaultAsync(d => d.Name == createDepartmentCommand.Name));

            response.ShouldNotBeNull();
            response.Id.ShouldBe(departmentInDb.Id);
            response.Name.ShouldBe(departmentInDb.Name);
            response.StartDate.ShouldBe(departmentInDb.StartDate);
            response.Budget.ShouldBe(departmentInDb.Budget);
        }
예제 #23
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));
        }
        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);
        }
        public async Task ShouldDeleteArticleComment()
        {
            await Helper.EnsureUserIsCreatedAndSetInDatabaseContext();

            var articleDto = await Helper.CreateDefaultArticle_ReturnDefaultArticleDto();

            await Helper.CreateDefaultComment(articleDto.Slug);

            var originalArticleWithComment = await Helper.QueryDefaultArticleDto();

            Assert.AreEqual(1, originalArticleWithComment.Comments.Count);

            var commentId = originalArticleWithComment.Comments.First().CommentId;

            var deleteCommand = new DeleteCommentCommand {
                Slug = originalArticleWithComment.Slug, CommentId = commentId
            };
            await SliceFixture.ExecuteDbContextAsync(async (ctx, mediator) =>
            {
                await mediator.Send(deleteCommand);
            });

            var resultArticleWithComment = await Helper.QueryDefaultArticleDto();

            var resultCommentsCount = resultArticleWithComment.Comments.Count;

            Assert.AreEqual(0, resultCommentsCount);
        }
예제 #26
0
        public async Task Should_delete_department(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 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();
        }
예제 #27
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);
        }
예제 #28
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());
        }
        /// <summary>
        /// creates an article comment based on the given Create command.
        /// Creates a default user if parameter userName is empty.
        /// </summary>
        /// <param name="fixture"></param>
        /// <param name="command"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static async Task <Domain.Comment> CreateComment(SliceFixture fixture, Create.Command command, string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                var user = await UserHelpers.CreateDefaultUser(fixture);

                userName = user.Username;
            }

            var dbContext       = fixture.GetDbContext();
            var currentAccessor = new StubCurrentUserAccessor(userName);

            var commentCreateHandler = new Create.Handler(dbContext, currentAccessor);
            var created = await commentCreateHandler.Handle(command, new System.Threading.CancellationToken());

            var dbArticleWithComments = await fixture.ExecuteDbContextAsync(
                db => db.Articles
                .Include(a => a.Comments).Include(a => a.Author)
                .Where(a => a.Slug == command.Slug)
                .SingleOrDefaultAsync()
                );

            var dbComment = dbArticleWithComments.Comments
                            .Where(c => c.ArticleId == dbArticleWithComments.ArticleId && c.Author == dbArticleWithComments.Author)
                            .FirstOrDefault();

            return(dbComment);
        }
        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);
        }