public async Task <OkResult> Post([FromBody] FollowPerson followPersonModel) { var userId = Guid.Parse(this.User.Claims.Single(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").Value); var command = new FollowPersonCommand(followPersonModel.ReaderId, userId); await this.mediator.Send(command); return(Ok()); }
public IActionResult Follow(Guid id) { var person = _personRepository.GetByUserId(this.GetUserId()); var cmd = new FollowPersonCommand { PersonId = person.PersonId, FollowId = id }; _mediatorHandler.SendCommand(cmd); return(Ok()); }
public void FollowPersonCommandMustThrowExceptionWhenPersonAlreadyFollowThePersonInCommand() { var person = _fixture.Create <Person>(); var follow = _fixture.Create <Person>(); var cmd = new FollowPersonCommand { PersonId = person.PersonId, FollowId = follow.PersonId }; person.Following.Add(follow); _personRepository.GetById(person.PersonId).Returns(person); _personRepository.GetById(follow.PersonId).Returns(follow); Assert.ThrowsAsync <Exception>(() => _sut.Handle(cmd, CancellationToken.None)); }
public Task <Unit> Handle(FollowPersonCommand request, CancellationToken cancellationToken) { var person = _personRepository.GetById(request.PersonId); var follow = _personRepository.GetById(request.FollowId); if (person.Following.Contains(follow)) { throw new Exception("Esse usuario já esta sendo seguido"); } ; var aggregate = new PersonAggregate(person); aggregate.Follow(follow); _personRepository.Update(aggregate); return(Unit.Task); }
public void FollowPersonCommandMustToFollowAPersonAndUpdateWithRepository() { //Given var person = _fixture.Create <Person>(); var follow = _fixture.Create <Person>(); var cmd = new FollowPersonCommand { PersonId = person.PersonId, FollowId = follow.PersonId }; _personRepository.GetById(person.PersonId).Returns(person); _personRepository.GetById(follow.PersonId).Returns(follow); //When _sut.Handle(cmd, CancellationToken.None); //Then _personRepository.Received(1).Update( Arg.Is <PersonAggregate>(x => x.GetState().Following.Contains(follow))); }