public async Task <OperationResult <UpdateCommentResponse> > Handle(UpdateCommentRequest request) { var retro = await this.retroReposirotory.Get(request.RetroId); if (retro == null) { return(OperationResultCreator.Failed <UpdateCommentResponse>("Retro not found")); } var comment = retro.Groups .SingleOrDefault(g => g.Id == request.GroupId)? .Comments.SingleOrDefault(c => c.Id == request.Comment.Id); if (comment == null) { return(OperationResultCreator.Failed <UpdateCommentResponse>("Comment not found")); } comment.Text = request.Comment.Text; removedActions(request, comment); addActions(request, comment); await this.retroReposirotory.Update(retro); var response = new UpdateCommentResponse { Comment = new CommentDTO(comment, this.userContextProvider.GetUserId()), GroupId = request.GroupId, RetroId = request.RetroId }; return(OperationResultCreator.Suceeded(response)); }
public async Task <OperationResult <IEnumerable <RetroDTO> > > Handle(GetRetrosRequest request) { var userId = this.userContextProvider.GetUserId(); var result = await this.retroRepository.GetByUserId(userId); var response = result.OrderByDescending(r => r.WhenCreated) .Select(r => new RetroDTO(r, userId)); return(OperationResultCreator.Suceeded(response)); }
public async Task <OperationResult <RetroDTO> > Handle(GetRetroRequest request) { var result = await this.retroRepository.Get(request.RetroId); if (result == null) { return(OperationResultCreator.Failed <RetroDTO>($"Could not find a retro with the id: '{request.RetroId}'")); } return(OperationResultCreator.Suceeded(new RetroDTO(result, this.userContextProvider.GetUserId()))); }
public async Task <OperationResult> Handle(DeleteRetroRequest request) { var retro = await this.retroReposirotory.Get(request.RetroId); if (retro == null) { throw new InvalidOperationException("Retro was not found"); } await this.retroReposirotory.Delete(retro); return(OperationResultCreator.Suceeded()); }
public async Task <OperationResult <CommentDTO> > Handle(AddCommentRequest request) { var retro = await this.retroReposirotory.Get(request.RetroId); var activeUserId = this.userContextProvider.GetUserId(); var comment = new Comment(request.Comment.Text, activeUserId); retro.AddComment(request.GroupId, comment); await this.retroReposirotory.Update(retro); return(OperationResultCreator.Suceeded(new CommentDTO(comment, activeUserId))); }
public async Task Execute_GivenThatIntractorFailes_ReturnsFailedOperationResult() { // Arrange this.interactor.Handle(Arg.Any <TestRequest>()).Returns(OperationResultCreator.Failure()); var request = this.fixture.Create <TestRequest>(); // Act var result = await this.sut.Execute(request); // Assert Assert.False(result.Succeeded); }
public async Task HandleRequest_GivenThatMediatorExecutionFailed_ReturnsOkResponse() { // Arrange var request = this.fixture.Create <TestRequest>(); this.mediator.Execute <TestRequest, OperationResult>(request) .Returns(OperationResultCreator.Failure()); // Act var response = await this.sut.TestHandleResuest <TestRequest, OperationResult>(request); // Assert Assert.IsType <OkObjectResult>(response); }
public async Task Execute_GivenThatAuthorizationFailes_ReturnsForbiddenOperationResult() { // Arrange this.interactor.HasAuthorizer.Returns(true); this.authorizer.Authorize(Arg.Any <TestRequest>()).Returns(OperationResultCreator.Failure()); var request = this.fixture.Create <TestRequest>(); // Act var result = await this.sut.Execute(request); // Assert Assert.IsType <ForbiddenOperationResult>(result); }
public RequestPipelineTests() { this.interactor = Substitute.For <IInteractor <TestRequest, OperationResult> >(); this.interactor.Handle(Arg.Any <TestRequest>()).Returns(OperationResultCreator.Success()); this.logger = Substitute.For <ILogger <RequestPipeline <TestRequest, OperationResult> > >(); this.authorizer = Substitute.For <IAuthorizer <TestRequest> >(); this.authorizer.Authorize(Arg.Any <TestRequest>()).Returns(OperationResultCreator.Success()); this.validator = Substitute.For <IValidator <TestRequest> >(); this.validator.Validate(Arg.Any <TestRequest>()).Returns(OperationResultCreator.Success()); this.sut = new RequestPipeline <TestRequest, OperationResult>(this.interactor, this.logger, this.authorizer, this.validator); }
public async Task <OperationResult> Execute(TRequest request) { var requestName = typeof(TRequest).Name; if (this.interactor == null) { throw new InvalidOperationException($"There is no interactor for [{requestName}]"); } if (this.authorizer == null && interactor.HasAuthorizer) { throw new InvalidOperationException($"There is no authorizer for [{requestName}]"); } if (this.validator == null && interactor.HasValidator) { throw new InvalidOperationException($"There is no validator for [{requestName}]"); } if (interactor.HasAuthorizer) { logger.LogInformation($"Authorizing [{requestName}]"); var authorizationResult = await this.authorizer.Authorize(request); if (!authorizationResult.Succeeded) { return(OperationResultCreator.Forbidden(authorizationResult.Errors)); } } if (interactor.HasValidator) { logger.LogInformation($"Validating [{requestName}]"); var validationResult = await this.validator.Validate(request); if (!validationResult.Succeeded) { return(validationResult); } } logger.LogInformation($"Handling [{requestName}]"); return(await this.interactor.Handle(request)); }
public async Task <OperationResult <RetroDTO> > Handle(CreateRetroRequest request) { Retro newRetro; do { newRetro = new Retro(request.RetroName, this.userContextProvider.GetUserId()); }while(this.retroReposirotory.GetByReference(newRetro.Reference).Result != null); if (request.WithDefaultGroups) { newRetro.WithDefaultGroups(); } var retro = await this.retroReposirotory.Add(newRetro); return(OperationResultCreator.Suceeded(new RetroDTO(retro, userContextProvider.GetUserId()))); }