Example #1
0
        public async Task ShouldCreateCourseClass()
        {
            var createCourseCommand = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var createCourseDto = await SendWithValidationAsync(createCourseCommand, new CreateCourseItemCommandValidator());

            var locationDto = await SendWithValidationAsync(new CreateLocationItemCommand()
            {
                IsEnabled   = true,
                Name        = "location1",
                Address     = "address1",
                OpeningTime = new TimeSpan(0, 19, 0),
                ClosingTime = new TimeSpan(0, 21, 0),
            }, new CreateLocationItemCommandValidator());

            var createCourseClassCommand = new CreateCourseClassItemCommand()
            {
                Name       = $"{createCourseCommand.Name}-class1",
                CourseId   = createCourseDto.Id,
                LocationId = locationDto.Id,
                Capacity   = 40,
            };
            var createCourseClassDto = await SendWithValidationAsync(createCourseClassCommand, new CreateCourseClassItemCommandValidator());

            var created = await ExecuteDbContextAsync(db =>
                                                      db.CourseClasses.Where(c => c.Id.Equals(createCourseClassDto.Id)).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.Name.ShouldBe(createCourseClassCommand.Name);
            created.Capacity.ShouldBe(createCourseClassCommand.Capacity);
            created.CourseId.ShouldBe(createCourseClassCommand.CourseId);
        }
        private async Task <CreateCourseClassItemDto> CreateCourseClassAsync(string courseName, int classCapacity = 40)
        {
            var createCourseCommand = new CreateCourseItemCommand()
            {
                Name = courseName,
                Rate = 40,
            };
            var courseDto = await SendWithValidationAsync(createCourseCommand, new CreateCourseItemCommandValidator());

            var locationDto = await SendWithValidationAsync(new CreateLocationItemCommand()
            {
                IsEnabled   = true,
                Name        = "location1",
                Address     = "address1",
                OpeningTime = new TimeSpan(0, 19, 0),
                ClosingTime = new TimeSpan(0, 21, 0),
            }, new CreateLocationItemCommandValidator());

            var createCourseClassCommand = new CreateCourseClassItemCommand()
            {
                Name       = $"{createCourseCommand.Name}-class1",
                CourseId   = courseDto.Id,
                LocationId = locationDto.Id,
                Capacity   = classCapacity,
            };
            var courseClassDto = await SendWithValidationAsync(createCourseClassCommand, new CreateCourseClassItemCommandValidator());

            return(courseClassDto);
        }
        private async Task <CreateCourseItemDto> CreateCourseAsync()
        {
            var createCourseCommand = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };

            return(await SendWithValidationAsync(createCourseCommand, new CreateCourseItemCommandValidator()));
        }
Example #4
0
        public async Task <ActionResult <Guid> > CreatCourseItem(CreateCourseItemCommand itemCommand)
        {
            var vm = await mediator.Send(itemCommand);

            if (vm.Id != null)
            {
                var link = Url.Link("GetCourseItem", new { courseId = vm.Id });
                return(Created(link, vm));
            }
            else
            {
                return(BadRequest(vm));
            }
        }
        public async Task ShouldCreateCourse()
        {
            var command = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var dto = await SendWithValidationAsync(command, new CreateCourseItemCommandValidator());

            var created = await ExecuteDbContextAsync(db =>
                                                      db.Courses.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.Name.ShouldBe(command.Name);
            created.Rate.ShouldBe(command.Rate);
        }
        private async Task <CreateEnrollmentItemDto> CreateEnrollmentDtoAsync()
        {
            var studentDto = await SendAsync(new CreateStudentItemCommand()
            {
                FirstName = "first",
                LastName  = "last"
            });

            var createCourseCommand = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var courseDto = await SendWithValidationAsync(createCourseCommand, new CreateCourseItemCommandValidator());

            var locationDto = await SendWithValidationAsync(new CreateLocationItemCommand()
            {
                IsEnabled   = true,
                Name        = "location1",
                Address     = "address1",
                OpeningTime = new TimeSpan(0, 19, 0),
                ClosingTime = new TimeSpan(0, 21, 0),
            }, new CreateLocationItemCommandValidator());

            var createCourseClassCommand = new CreateCourseClassItemCommand()
            {
                Name       = $"{createCourseCommand.Name}-class1",
                CourseId   = courseDto.Id,
                LocationId = locationDto.Id,
                Capacity   = 40,
            };
            var courseClassDto = await SendWithValidationAsync(createCourseClassCommand, new CreateCourseClassItemCommandValidator());


            var command = new CreateEnrollmentItemCommand()
            {
                StartDate     = DateTime.UtcNow.DateTimeWithoutMilisecond(),
                StudentId     = studentDto.Id,
                CourseClassId = courseClassDto.Id,
            };
            var dto = await SendAsync(command);

            return(dto);
        }
Example #7
0
        public async Task ShouldGetCourseList()
        {
            var command = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var createCourseItemDto = await SendAsync(command);

            var created = await ExecuteDbContextAsync(db =>
                                                      db.Courses.Where(c => c.Id.Equals(createCourseItemDto.Id)).SingleOrDefaultAsync());

            GetCourseListQuery query = new GetCourseListQuery();
            GetObjectListVm <GetCourseItemDto> dto = await SendAsync(query);

            dto.ShouldNotBeNull();
            dto.Count.ShouldBeGreaterThanOrEqualTo(1);
            dto.Data.ShouldContain(d => d.Id.Equals(created.Id));
        }
Example #8
0
        public async Task ShouldGetCourseItem()
        {
            var command = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var createCourseItemDto = await SendAsync(command);

            GetCourseItemQuery query = new GetCourseItemQuery()
            {
                Id = createCourseItemDto.Id
            };
            GetCourseItemDto dto = await SendAsync(query);

            var created = await ExecuteDbContextAsync(db => db.Courses.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync());

            dto.ShouldNotBeNull();
            dto.Id.ShouldBe(created.Id);
            dto.Name.ShouldBe(created.Name);
        }