Exemplo n.º 1
0
        public async Task <IActionResult> Update(int id, UpdateCourseCommand command)
        {
            command.CourseId = id;
            await Mediator.Send(command);

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditPost(UpdateCourseCommand command)
        {
            try
            {
                await Mediator.Send(command);

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");

                await PopulateDepartmentsDropDownList(command.DepartmentID);

                return(View(new EditCourseVM
                {
                    CourseID = command.CourseID.Value,
                    Title = command.Title,
                    Credits = command.Credits,
                    DepartmentID = command.DepartmentID,
                }));
            }
        }
Exemplo n.º 3
0
 public UpdateCourseService(UpdateCourseCommand courseCommand, ICourseRepository courseRepository)
     : base(courseCommand)
 {
     _courseRepository = courseRepository;
     _courseCommand    = courseCommand;
     Run();
 }
Exemplo n.º 4
0
        public async Task WhenIUpdateAnInvalidCourse()
        {
            _command = new UpdateCourseCommand {
                CourseId = "invalidCourseId", Title = "course title"
            };

            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 5
0
        public async Task <Unit> Handle(UpdateCourseCommand request, CancellationToken cancellationToken)
        {
            await courseWriteOnlyRepository.Update(
                Course.CreateToUpdate(request.Id, request.Name, request.Description, request.Price, request.Video)
                );

            return(await Unit.Task);
        }
Exemplo n.º 6
0
        public void EmptyOrNullTitle_ShouldHaveError(string name)
        {
            var command = new UpdateCourseCommand {
                Title = name
            };

            _sut.ShouldHaveValidationErrorFor(x => x.Title, command);
        }
Exemplo n.º 7
0
        public void TitleLengthOver60_ShouldHaveError()
        {
            var command = new UpdateCourseCommand {
                Title = new string('*', 61)
            };

            _sut.ShouldHaveValidationErrorFor(x => x.Title, command);
        }
Exemplo n.º 8
0
        public async Task WhenIUpdateACourseWithATitleLengthOverCharacters(int maximumTitleLength)
        {
            _command = new UpdateCourseCommand {
                CourseId = "courseId", Title = new string('*', maximumTitleLength + 1)
            };

            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 9
0
        public async Task WhenIUpdateACourseWithAnEmptyOrANullTitle(string title)
        {
            _command = new UpdateCourseCommand {
                CourseId = "courseId", Title = title
            };

            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 10
0
        public void EmptyOrNullCourseId_ShouldHaveError(string courseId)
        {
            var command = new UpdateCourseCommand {
                CourseId = courseId
            };

            _sut.ShouldHaveValidationErrorFor(x => x.CourseId, command);
        }
Exemplo n.º 11
0
        public void SubtitleLengthOver120_ShouldHaveError()
        {
            var command = new UpdateCourseCommand {
                Subtitle = new string('*', 121)
            };

            _sut.ShouldHaveValidationErrorFor(x => x.Subtitle, command);
        }
Exemplo n.º 12
0
        public void CourseLearnedSkillLengthOver150_ShouldHaveError()
        {
            var command = new UpdateCourseCommand {
                CourseLearnedSkills = new List <string> {
                    new string('*', 151)
                }
            };

            _sut.ShouldHaveValidationErrorFor(x => x.CourseLearnedSkills, command);
        }
        public async Task <IActionResult> UpdateCourse(
            [FromRoute] string id,
            [FromBody] UpdateCourseCommand command,
            [FromServices] IMediator mediator)
        {
            command.AddCourseId(id);
            var result = await mediator.Send(command);

            return(StatusCode(200, result));
        }
Exemplo n.º 14
0
        public async Task WhenIUpdateAPublishedCourse()
        {
            var course = new Course("course", _instructorId, DateTime.Now);

            course.ChangeCourseStatus(PublishedStatus.Instance);
            _factory.CreateCourse(course);

            _command = new UpdateCourseCommand {
                CourseId = course.Id, Title = "course title"
            };
            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 15
0
        public async Task Update(CourseDto courses)
        {
            var updateCourseCommand = new UpdateCourseCommand
            {
                Id          = courses.Id,
                Name        = courses.Name,
                Description = courses.Description,
                ImageUrl    = courses.ImageUrl
            };

            await _bus.Send(updateCourseCommand);
        }
Exemplo n.º 16
0
        public async Task WhenIUpdateACourseWithASkillLengthOverCharacters(int maximumSkillLength)
        {
            _command = new UpdateCourseCommand
            {
                CourseId            = "courseId",
                Title               = "Course title",
                CourseLearnedSkills = new List <string> {
                    new string('*', maximumSkillLength + 1)
                }
            };

            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 17
0
        public async Task <ActionResult <CourseDto> > Update(int id, UpdateCourseCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }



            var result = await _mediator.Send(command);

            return(Ok(result));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> UpdateCourse(UpdateCourseCommand command)
        {
            Request.Headers.TryGetValue("Authorization", out var token);
            string role = await AuthHelper.GetRoleFromTokenAsync(token);

            if (role != "admin")
            {
                return(StatusCode(401, new { Error = "Unauthorized" }));
            }

            BaseResponse <int> result = (BaseResponse <int>) await Mediator.Send(command);

            return(!result.Success ? StatusCode(result.Error.StatusCode, result.Error) : Ok(result));
        }
Exemplo n.º 19
0
        public void GivenADraftCourseWith(Table table)
        {
            var course = new Course("old title", _instructorId, DateTime.Now);

            course.UpdateSubtitle("old subtitle");
            course.UpdateDescription("old description");
            course.AddLearnedSkill("old skill 1");
            course.AddLearnedSkill("old skill 2");
            _factory.CreateCourse(course);

            _command = new UpdateCourseCommand {
                CourseId = course.Id
            };
        }
Exemplo n.º 20
0
        public async Task Should_throw_not_found_exception()
        {
            var updateCourseCommand = new UpdateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var updateCourseCommandHandler = new UpdateCourseCommandHandler(this.autoMapper, this.context);

            await Assert.ThrowsAsync <NotFoundException>(() => updateCourseCommandHandler.Handle(updateCourseCommand, CancellationToken.None));
        }
        public void SetUp()
        {
            _service       = new Mock <IUpdateCourseService>();
            _commonService = new Mock <ICoursesCommonService>();
            _unitOfWork    = new Mock <IUnitOfWork>();
            _command       = new UpdateCourseCommand()
            {
                CourseId = "courseId"
            };
            _sut = new UpdateCourseCommandHandler(_service.Object, _commonService.Object, _unitOfWork.Object);

            _courseToUpdate = new Course("title", "creatorId", DateTime.Now);
            _commonService.Setup(x => x.GetCourseFromRepo(_command.CourseId, default))
            .ReturnsAsync(_courseToUpdate);
        }
Exemplo n.º 22
0
        public async Task <ValidationResult> Handle(UpdateCourseCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.ValidationResult);
            }

            var course = new Course(request.Id, request.Capacity, request.NumberOfStudents);

            _courseRepository.Update(course);

            await Bus.RaiseEvent(new CourseRegisteredEvent(request.Id, request.Capacity, request.NumberOfStudents));

            return(await Commit(_courseRepository.UnitOfWork));
        }
Exemplo n.º 23
0
        public async Task <GenericCommandResult> Handle(UpdateCourseCommand command, CancellationToken cancellationToken)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ocorreu um erro", command.Notifications));
            }

            var course = _courseRepository.GetById(command.CourseId);

            course.UpdateName(command.Name);

            _courseRepository.Update(course);

            return(new GenericCommandResult(true, "Curso atualizado com sucesso", (DTOs.Course)course));
        }
Exemplo n.º 24
0
        public void ValidParameters_ShouldNotHaveErrors()
        {
            var command = new UpdateCourseCommand
            {
                CourseId            = "courseId", Description = "description", Title = "course title",
                Subtitle            = "course subtitle",
                CourseLearnedSkills = new List <string> {
                    "courseSkill1"
                }
            };

            _sut.ShouldNotHaveValidationErrorFor(x => x.CourseId, command);
            _sut.ShouldNotHaveValidationErrorFor(x => x.Title, command);
            _sut.ShouldNotHaveValidationErrorFor(x => x.Subtitle, command);
            _sut.ShouldNotHaveValidationErrorFor(x => x.Description, command);
            _sut.ShouldNotHaveValidationErrorFor(x => x.CourseLearnedSkills, command);
        }
Exemplo n.º 25
0
        public ICommandResult Handle(UpdateCourseCommand command)
        {
            //Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, Messages.Ex_ExceptionGeneric, command.Notifications));
            }

            var course = _repository.GetById(command.Id);

            course.UpdateCourse(command.Title, command.Url, command.Value, command.Stars, command.RecomendedByEid);

            _repository.Update(course);

            return(new GenericCommandResult(true, Messages.Act_Update, course));
        }
Exemplo n.º 26
0
        public async Task WhenIUpdateACourseBelongingToAnOtherOrganization()
        {
            var otherOrganization = new Organization("other organization", SubscriptionPlans.Free);

            _factory.CreateOrganization(otherOrganization);

            var otherInstructor = new User("*****@*****.**", otherOrganization.Id);

            _factory.CreateUser(otherInstructor);

            var course = new Course("course", otherInstructor.Id, DateTime.Now);

            _factory.CreateCourse(course);

            _command = new UpdateCourseCommand {
                CourseId = course.Id, Title = "course title"
            };
            _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command));
        }
Exemplo n.º 27
0
        public async Task UpdateCourseTest_Should_Return_Id()
        {
            //Arrange
            var request = new UpdateCourseCommand
            {
                Id        = 1,
                Name      = "Math",
                Price     = 5000,
                StartTime = new DateTime(2021, 02, 02, 10, 00, 00),
                EndTime   = new DateTime(2021, 02, 04, 12, 00, 00),
            };

            var handler = new UpdateCourseHandler(_mapper, _fakeRepository);

            //Act
            var id = await handler.Handle(request, new CancellationToken());

            //Assert
            Assert.AreEqual(id, 1);
        }
Exemplo n.º 28
0
        public async Task HandleAsync(UpdateCourseCommand command)
        {
            var course = await _repository.GetByCode(command.Code);

            if (course == null)
            {
                throw new EntityNotFoundException($"Course with code '{command.Code}' Not Found.");
            }

            if (!string.IsNullOrEmpty(command.Name))
            {
                course.Name = command.Name;
            }

            if (!string.IsNullOrEmpty(command.Description))
            {
                course.Description = command.Description;
            }

            await _repository.Update(course);

            await _commandStoreService.PushAsync(command);
        }
Exemplo n.º 29
0
        protected void Reg_Mat(object sender, EventArgs e)
        {
            grades      = new Grade();
            grades.Id   = Int32.Parse(list_grades.SelectedValue);
            grades.Name = list_grades.DataTextField;
            string oldid = Session["Id_mat"].ToString();

            course             = new Course();
            course.Id          = name.Value.Substring(0, 4) + list_grades.SelectedValue + DateTime.Now.Year.ToString();
            course.Name        = name.Value;
            course.Description = desc.Value;
            course.Grade       = grades;
            UpdateCourseCommand cmd = new UpdateCourseCommand(course, oldid);

            cmd.Execute();
            if (course.Code == 201)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme_succ()", true);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true);
            }
        }
Exemplo n.º 30
0
        public async Task Should_update_student()
        {
            // create course
            var createCourseCommand = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var createCourseCommandHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);

            var result = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None);

            result.ShouldBe(true);

            var updateCourseCommand = new UpdateCourseCommand()
            {
                Id          = createCourseCommand.Id,
                Code        = 1,
                Name        = "Course 2",
                Description = "Test"
            };

            var updateCourseCommandHandler = new UpdateCourseCommandHandler(this.autoMapper, this.context);

            result = await updateCourseCommandHandler.Handle(updateCourseCommand, CancellationToken.None);

            result.ShouldBe(true);

            var dbCourse = await this.context.Course.FirstOrDefaultAsync(s => s.Id == updateCourseCommand.Id);

            dbCourse.ShouldNotBeNull();
            dbCourse.Name.ShouldBe(updateCourseCommand.Name);
        }