Пример #1
0
        public static async Task <Study> CreatedByCurrentUser(
            string name     = StudyConstants.CREATED_BY_ME_NAME,
            string vendor   = StudyConstants.CREATED_BY_ME_VENDOR,
            string wbs      = StudyConstants.CREATED_BY_ME_WBS,
            bool restricted = false,
            int userId      = TestUserConstants.COMMON_CUR_USER_DB_ID,
            List <string> additionalRolesForCurrentUser = null,
            List <string> rolesForOtherUser             = null,
            bool addDatasets = false
            )
        {
            var study = StudyBasic(name, vendor, wbs, restricted);

            study.ResultsAndLearnings = "Results and learnings";
            AddParticipant(study, userId, StudyRoles.StudyOwner);

            if (additionalRolesForCurrentUser != null)
            {
                foreach (var curRoleCurrentUser in additionalRolesForCurrentUser)
                {
                    if (!String.IsNullOrWhiteSpace(curRoleCurrentUser))
                    {
                        AddParticipant(study, userId, curRoleCurrentUser);
                    }
                }
            }

            if (rolesForOtherUser != null)
            {
                foreach (var curRoleOtherUser in rolesForOtherUser)
                {
                    if (!String.IsNullOrWhiteSpace(curRoleOtherUser))
                    {
                        AddParticipant(study, TestUserConstants.COMMON_NEW_PARTICIPANT_DB_ID, curRoleOtherUser);
                    }
                }
            }

            AddDatasetsIfWanted(addDatasets, study);
            await SliceFixture.InsertAsync(study);

            return(study);
        }
Пример #2
0
        public async Task ListsAllUsers(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                UserName          = "******",
                FirstName         = "Some name",
                Password          = "******",
                ConfirmedPassword = "******"
            };

            var registerUserCommand2 = new Register.Command
            {
                UserName          = "******",
                FirstName         = "Some name",
                Password          = "******",
                ConfirmedPassword = "******"
            };

            await fixture.SendAsync(registerUserCommand);

            await fixture.SendAsync(registerUserCommand2);

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

            // Assert
            var usersInDb = await fixture.ExecuteDbContextAsync(db =>
                                                                db.Users
                                                                .Include(u => u.Roles)
                                                                .ToListAsync());

            // Order them so I can compare by index
            model     = model.OrderBy(u => u.Id);
            usersInDb = usersInDb.OrderBy(u => u.Id).ToList();

            usersInDb.Count.ShouldBe(model.Count());
            model.ElementAt(0).Id.ShouldBe(usersInDb[0].Id);
            model.ElementAt(1).Id.ShouldBe(usersInDb[1].Id);
            model.ElementAt(0).Roles.Count.ShouldBe(usersInDb[0].Roles.Count);
            model.ElementAt(0).Roles.Count.ShouldBe(usersInDb[1].Roles.Count);
        }
Пример #3
0
        public async Task ListsOnlyUnshippedOrders(SliceFixture fixture)
        {
            // Arrange
            // Add some orders
            var firstOrder = new Data.Models.Order
            {
                Name    = "Some name",
                Line1   = "An address",
                City    = "City",
                Country = "Country",
                Zip     = "Zip",
                State   = "State",
                Shipped = true
            };

            var secondOrder = new Data.Models.Order
            {
                Name         = "Some name2",
                Line1        = "An address2",
                City         = "City2",
                Country      = "Country2",
                Zip          = "Zip2",
                State        = "State2",
                Shipped      = false,
                OrderedItems = new List <Data.Models.CartItem>
                {
                    new Data.Models.CartItem()
                }
            };

            await fixture.InsertAsync(firstOrder, secondOrder);

            // Act
            var query          = new Orders.Query();
            var ordersReceived = await fixture.SendAsync(query);

            // Assert
            ordersReceived.Count().ShouldBe(1);
            ordersReceived.First().Name.ShouldBe(secondOrder.Name);
            ordersReceived.First().Zip.ShouldBe(secondOrder.Zip);
            ordersReceived.First().OrderedItems.Count.ShouldBe(secondOrder.OrderedItems.Count);
        }
Пример #4
0
        public async Task Should_edit_department(SliceFixture fixture)
        {
            var admin = new Instructor
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            };
            var admin2 = new Instructor
            {
                FirstMidName = "Jerry",
                LastName     = "Seinfeld",
                HireDate     = DateTime.Today,
            };

            var dept = new Department
            {
                Name          = "History",
                Administrator = admin,
                Budget        = 123m,
                StartDate     = DateTime.Today
            };
            await fixture.InsertAsync(admin, admin2, 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());
        }
Пример #5
0
        public async Task AddStudy_ShouldCreateResourceGroupForStudySpecificDatasets(bool isAdmin, bool isSponsor)
        {
            SetScenario(isEmployee: true, isAdmin: isAdmin, isSponsor: isSponsor);

            var createStudyApiConversation = await StudyCreator.CreateAndExpectSuccess(_restHelper);

            CreateStudyAsserts.ExpectSuccess(createStudyApiConversation.Request, createStudyApiConversation.Response);

            var databaseEntryForStudyDatasetResourceGroup = await SliceFixture.GetResource(studyId : createStudyApiConversation.Response.Content.Id);

            CloudResourceBasicAsserts.StudyDatasetResourceGroupBeforeProvisioningAssert(databaseEntryForStudyDatasetResourceGroup);

            //SETUP INFRASTRUCTURE BY RUNNING A METHOD ON THE API
            _ = await ProcessWorkQueue();

            //Get resource from database again and assert
            databaseEntryForStudyDatasetResourceGroup = await SliceFixture.GetResource(studyId : createStudyApiConversation.Response.Content.Id);

            CloudResourceBasicAsserts.StudyDatasetResourceGroupAfterProvisioningAssert(databaseEntryForStudyDatasetResourceGroup);
        }
Пример #6
0
        public static async Task <CloudResource> CreateFailed(
            Sandbox sandbox,
            string vmNameSuffix           = VirtualMachineConstants.NAME,
            string size                   = VirtualMachineConstants.SIZE,
            string osCategory             = VirtualMachineConstants.OS_CATEGORY_WINDOWS,
            string os                     = VirtualMachineConstants.OS_WINDOWS,
            string statusOfFailedResource = CloudResourceOperationState.FAILED,
            int tryCount                  = CloudResourceConstants.RESOURCE_MAX_TRY_COUNT,
            int maxTryCount               = CloudResourceConstants.RESOURCE_MAX_TRY_COUNT,
            bool deleted                  = false,
            bool deleteSucceeded          = false)
        {
            var sandboxResourceGroup = CloudResourceUtil.GetSandboxResourceGroupEntry(sandbox.Resources);

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

            var vmResource = CreateFailedVmResource(sandbox, sandboxResourceGroup, sandbox.Study.Name, vmNameSuffix, vmSettings, statusOfFailedResource, tryCount, maxTryCount, deleted: deleted, deleteSucceeded: deleteSucceeded);

            return(await SliceFixture.InsertAsync(vmResource));
        }
Пример #7
0
        public async Task CanLogout(SliceFixture fixture)
        {
            await fixture.ExecuteScopeAsync(async sp =>
            {
                await fixture.ExecuteDbContextAsync(async db =>
                {
                    // Arrange
                    var userManager   = GetFakeUserManager(sp);
                    var signInManager = GetFakeSignInManager(userManager);

                    var usersService = new UsersService(userManager, signInManager, GetFakeRoleManager(sp), db);

                    // Act
                    await usersService.LogoutAsync();

                    // Assert
                    A.CallTo(() => signInManager.SignOutAsync()).MustHaveHappened();
                });
            });
        }
Пример #8
0
        public async Task IndexReturnsAllDepartments(SliceFixture fixture)
        {
            //Arrange
            Instructor administrator = new Instructor
            {
                FirstName = "The mighty",
                LastName  = "Admin"
            };

            Department[] departmentsToInsert = new Department[]
            {
                new Department
                {
                    Name          = "Some department1",
                    Administrator = administrator
                },
                new Department
                {
                    Name          = "Some department2",
                    Administrator = administrator
                },
                new Department
                {
                    Name          = "Some department3",
                    Administrator = administrator
                }
            };

            await fixture.InsertAsync(departmentsToInsert);

            var indexQuery = new Index.Query();

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

            //Assert
            response.Departments.Count.ShouldBe(departmentsToInsert.Length);
            response.Departments.ElementAt(0).Name.ShouldBe(departmentsToInsert[0].Name);
            response.Departments.ElementAt(1).Name.ShouldBe(departmentsToInsert[1].Name);
            response.Departments.ElementAt(2).Name.ShouldBe(departmentsToInsert[2].Name);
        }
        /// <summary>
        /// creates a default user to be used in different tests
        /// </summary>
        /// <param name="fixture"></param>
        /// <returns></returns>
        public static async Task <User> CreateDefaultUser(SliceFixture fixture)
        {
            if (UserEnvelope != null)
            {
                return(UserEnvelope.User);
            }

            var command = new Create.Command()
            {
                User = new Create.UserData()
                {
                    Email    = "email",
                    Password = "******",
                    Username = DefaultUserName
                }
            };

            UserEnvelope = await fixture.SendAsync(command);

            return(UserEnvelope.User);
        }
Пример #10
0
        private static async Task <Data.Models.Product> AddProductToDatabase(SliceFixture fixture)
        {
            var createCommand = new Create.Command
            {
                Name        = "Some product",
                Description = "Some description",
                Price       = 31241.00m,
                Category    = new Data.Models.Category()
                {
                    Name = "Some category"
                },
            };

            await fixture.SendAsync(createCommand);

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

            return(addedProduct);
        }
        public async Task ShouldDeleteArticle()
        {
            await Helper.EnsureUserIsCreatedAndSetInDatabaseContext();

            var articleDto = await Helper.CreateDefaultArticle_ReturnDefaultArticleDto();

            var originalArticleCount = await SliceFixture.ExecuteDbContextAsync(db => db.Articles.CountAsync());

            Assert.AreEqual(1, originalArticleCount);

            var deleteCommand = new DeleteArticleCommand(articleDto.Slug);

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

            var actualArticleCount = await SliceFixture.ExecuteDbContextAsync(db => db.Articles.CountAsync());

            Assert.AreEqual(0, actualArticleCount);
        }
        public async Task CanRegister(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            // Act
            await fixture.SendAsync(registerUserCommand);

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

            user.ShouldNotBeNull();
            user.FirstName.ShouldBe(registerUserCommand.FirstName);
        }
Пример #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);
        }
        public async Task CannotCreateCategoryWithTheSameName(SliceFixture fixture)
        {
            // Arrange
            var category = new Category
            {
                Name = "Category"
            };

            await fixture.InsertAsync(category);

            // Act
            bool categoryDoesntExist = true;

            await fixture.ExecuteScopeAsync(async sp =>
            {
                categoryDoesntExist = await sp.GetService <ICategoryValidator>()
                                      .CategoryDoesntExistAsync(category.Name, CancellationToken.None);
            });

            // Assert
            categoryDoesntExist.ShouldBeFalse();
        }
Пример #15
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);
        }
Пример #16
0
        public async Task ListsAllStudents(SliceFixture fixture)
        {
            //Arrange
            var students = new Student[]
            {
                new Student
                {
                    FirstName      = "John",
                    LastName       = "Smith",
                    EnrollmentDate = new DateTime(2012, 01, 03)
                },
                new Student
                {
                    FirstName      = "Carlos",
                    LastName       = "Rodrigez",
                    EnrollmentDate = new DateTime(2012, 01, 03)
                },
                new Student
                {
                    FirstName      = "Peter",
                    LastName       = "Pan",
                    EnrollmentDate = new DateTime(2012, 01, 03)
                },
            };

            await fixture.InsertAsync(students);

            //Act
            var indexQuery = new Index.Query();

            var response = await fixture.SendAsync(indexQuery);

            //Assert
            response.Students.Count.ShouldBe(students.Length);
            response.Students.ElementAt(0).FullName.ShouldBe(students[0].FullName);
            response.Students.ElementAt(1).FullName.ShouldBe(students[1].FullName);
            response.Students.ElementAt(2).FullName.ShouldBe(students[2].FullName);
        }
        public static async Task EnsureUserIsCreatedAndSetInDatabaseContext()
        {
            try
            {
                var command = new RegisterUserCommand()
                {
                    User =
                        new UserData()
                    {
                        Email    = "*****@*****.**",
                        Password = "******",
                        Username = "******"
                    }
                };
                await SliceFixture.SendAsync(command);

                var user = await SliceFixture.ExecuteDbContextAsync((ctx, mediator) =>

                                                                    ctx.Users.FirstOrDefaultAsync(i => i.Login == command.User.Email)
                                                                    );

                await SliceFixture.ExecuteDbContextAsync((ctx, mediator) =>
                {
                    ctx.UserInfo = new UserInfo()
                    {
                        ProfileId = user.UserId,
                        Username  = command.User.Username,
                        Email     = command.User.Email
                    };
                    return(Task.CompletedTask);
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public async Task Should_query_for_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
            };

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

            await fixture.InsertAsync(dept, course);

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

            result.ShouldNotBeNull();
            result.Credits.ShouldBe(course.Credits);
            result.DepartmentName.ShouldBe(dept.Name);
            result.Title.ShouldBe(course.Title);
        }
Пример #19
0
        public async Task Should_get_instructor_details(SliceFixture fixture)
        {
            var englishDept = new Department
            {
                Name      = "English",
                StartDate = DateTime.Today
            };
            var english101 = new Course
            {
                Department = englishDept,
                Title      = "English 101",
                Credits    = 4,
                Id         = 123
            };
            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, instructor);

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

            result.ShouldNotBeNull();
            result.FirstMidName.ShouldBe(instructor.FirstMidName);
            result.OfficeAssignmentLocation.ShouldBe(instructor.OfficeAssignment.Location);
        }
        public async Task ResponseReturnsCorrectData(SliceFixture fixture)
        {
            //Arrange
            var createCommand = new Create.Command
            {
                FirstName      = "Some",
                LastName       = "Student",
                EnrollmentDate = new DateTime(2013, 03, 04)
            };

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

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

            studentInDb.ShouldNotBeNull();
            studentInDb.FirstName.ShouldBe(response.FirstName);
            studentInDb.LastName.ShouldBe(response.LastName);
            studentInDb.EnrollmentDate.ShouldBe(response.EnrollmentDate);
        }
Пример #21
0
        public async Task SuccessfullCreationSetsSuccessMessage(SliceFixture fixture)
        {
            // Arrange
            var controller = fixture.GetController <ProductController>();

            // Act
            var createCommand = new Create.Command()
            {
                Name        = "Some product",
                Description = "Some description",
                Category    = new Data.Models.Category()
                {
                    Name = "Some category"
                },
                Price = 120.00m
            };

            await controller.Create(createCommand);

            // Assert
            controller.TempData
            .ShouldContainSuccessMessage(SuccessMessages.SuccessfullyCreatedProduct(createCommand.Name));
        }
Пример #22
0
        public async Task Should_create_new_course(SliceFixture fixture)
        {
            var adminId = await fixture.SendAsync(new ContosoUniversityCore.Features.Instructor.CreateEdit.Command
            {
                FirstMidName = "George",
                LastName     = "Costanza",
                HireDate     = DateTime.Today,
            });

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

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

            await fixture.InsertAsync(dept);

            var command = new 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);
        }
Пример #23
0
        public async Task CanLogin(SliceFixture fixture)
        {
            await fixture.ExecuteScopeAsync(async sp =>
            {
                await fixture.ExecuteDbContextAsync(async db =>
                {
                    // Arrange
                    var registerUserCommand = new Register.Command
                    {
                        UserName = "******",
                        Password = "******"
                    };

                    await fixture.SendAsync(registerUserCommand);

                    var user = await db
                               .Users
                               .FirstOrDefaultAsync(u => u.UserName == registerUserCommand.UserName);

                    var userManager = GetFakeUserManager(sp);
                    A.CallTo(() => userManager.FindByNameAsync(registerUserCommand.UserName)).Returns(user);

                    var signInManager = GetFakeSignInManager(userManager);

                    A.CallTo(() => signInManager.PasswordSignInAsync(user, registerUserCommand.Password, false, false))
                    .Returns(SignInResult.Success);

                    var usersService = new UsersService(userManager, signInManager, GetFakeRoleManager(sp), db);

                    // Act
                    var result = await usersService.LoginAsync(registerUserCommand.UserName, registerUserCommand.Password);

                    // Assert
                    result.ShouldBeTrue();
                });
            });
        }
        public async Task CanGetDetails(SliceFixture fixture)
        {
            //Arrange
            var administrator = new Instructor
            {
                FirstName = "John",
                LastName  = "Smith",
                HireDate  = new DateTime(1953, 01, 10)
            };

            await fixture.InsertAsync(administrator);

            var createDepartmentComand = new Create.Command
            {
                Name          = "Physics",
                StartDate     = new DateTime(2013, 01, 01),
                Budget        = 12903.00m,
                Administrator = administrator
            };

            var createdDepartment = await fixture.SendAsync(createDepartmentComand);

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

            var response = await fixture.SendAsync(detailsQuery);

            //Assert
            response.Id.ShouldBe(createdDepartment.Id);
            response.Name.ShouldBe(createdDepartment.Name);
            response.StartDate.ShouldBe(createdDepartment.StartDate);
            response.Budget.ShouldBe(createdDepartment.Budget);
            response.Administrator.FullName.ShouldBe(createdDepartment.AdministratorFullName);
        }
Пример #25
0
        public async Task Should_delete(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 course = new Course
            {
                Credits    = 4,
                Department = dept,
                Id         = 1234,
                Title      = "English 101"
            };

            await fixture.InsertAsync(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 CanRemoveProduct(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
            var command = new Remove.Command() { ProductId = product.Id };

            await fixture.SendAsync(command);

            var productInDb = await fixture
                .ExecuteDbContextAsync(db => db
                .Products
                .FirstOrDefaultAsync(p => p.Id == product.Id));

            productInDb.ShouldBeNull();
        }
Пример #27
0
        public async Task ListsAllCategories(SliceFixture fixture)
        {
            // Arrange
            var categories = new List <Data.Models.Category>
            {
                new Data.Models.Category
                {
                    Name = "Category1"
                },
                new Data.Models.Category
                {
                    Name = "Category2"
                },
                new Data.Models.Category
                {
                    Name = "Category3"
                },
            };

            foreach (var category in categories)
            {
                await fixture.InsertAsync(category);
            }

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

            var result = await fixture.SendAsync(query);

            // Assert
            result.Count().ShouldBe(categories.Count);

            for (int i = 0; i < categories.Count; i++)
            {
                result.ElementAt(i).Name.ShouldBe(categories[i].Name);
            }
        }
        public async Task CanDelete(SliceFixture fixture)
        {
            //Arrange
            var administrator = new Instructor
            {
                FirstName = "John",
                LastName  = "Smith",
                HireDate  = new DateTime(1953, 01, 10)
            };

            await fixture.InsertAsync(administrator);

            var createDepartmentComand = new Create.Command
            {
                Name          = "Physics",
                StartDate     = new DateTime(2013, 01, 01),
                Budget        = 12903.00m,
                Administrator = administrator
            };

            var createdDepartment = await fixture.SendAsync(createDepartmentComand);

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

            await fixture.SendAsync(deleteCommand);

            //Assert
            var depInDb = await fixture.ExecuteDbContextAsync(context => context
                                                              .Departments
                                                              .FirstOrDefaultAsync(d => d.Id == createdDepartment.Id));

            depInDb.ShouldBeNull();
        }
        public async Task UserHasACartAfterRegistration(SliceFixture fixture)
        {
            // Arrange
            var registerUserCommand = new Register.Command
            {
                FirstName = "John",
                UserName  = "******",
                Password  = "******"
            };

            // Act
            await fixture.SendAsync(registerUserCommand);

            // 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.ShouldNotBeNull();
            user.Cart.OrderedItems.ShouldNotBeNull();
        }
Пример #30
0
        public async Task ReturnsCorrectInformation(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);

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

            var response = await fixture.SendAsync(detailsQuery);

            //Assert
            response.ShouldNotBeNull();
            response.Id.ShouldBe(createdCourse.Id);
            response.Title.ShouldBe(createdCourse.Title);
            response.Credits.ShouldBe(createdCourse.Credits);
            response.Department.Name.ShouldBe(createdCourse.DepartmentName);
        }