public void UnFollowPersonCommandMustToUnFollowAPersonAndUpdateWithRepository() { //Given var person = _fixture.Create <Person>(); var unfollow = _fixture.Create <Person>(); var cmd = new UnfollowPersonCommand { PersonId = person.PersonId, UnfollowId = unfollow.PersonId }; person.Following.Add(unfollow); _personRepository.GetById(person.PersonId).Returns(person); _personRepository.GetById(unfollow.PersonId).Returns(unfollow); //When _sut.Handle(cmd, CancellationToken.None); //Then _personRepository.Received(1).Update( Arg.Is <PersonAggregate>(x => !x.GetState().Following.Contains(unfollow))); }
public async Task <OkResult> Delete([FromRoute] UnfollowPerson unfollowPersonModel) { var userId = Guid.Parse(this.User.Claims.Single(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").Value); var command = new UnfollowPersonCommand(unfollowPersonModel.ReaderId, userId); await this.mediator.Send(command); return(Ok()); }
public IActionResult Unfollow(Guid id) { var person = _personRepository.GetByUserId(this.GetUserId()); var cmd = new UnfollowPersonCommand { PersonId = person.PersonId, UnfollowId = id }; _mediatorHandler.SendCommand(cmd); return(Ok()); }
public void UnFollowPersonCommandMustThrowExceptionWhenPersonIsNotFollowedByThePersonInCommand() { var person = _fixture.Create <Person>(); var unfollow = _fixture.Create <Person>(); var cmd = new UnfollowPersonCommand { PersonId = person.PersonId, UnfollowId = unfollow.PersonId }; _personRepository.GetById(person.PersonId).Returns(person); _personRepository.GetById(unfollow.PersonId).Returns(unfollow); Assert.ThrowsAsync <Exception>(() => _sut.Handle(cmd, CancellationToken.None)); }
public Task <Unit> Handle(UnfollowPersonCommand request, CancellationToken cancellationToken) { var user = _personRepository.GetById(request.PersonId); var unfollow = _personRepository.GetById(request.UnfollowId); if (!user.Following.Contains(unfollow)) { throw new Exception("Esse não está sendo seguido"); } ; var aggregate = new PersonAggregate(user); aggregate.Unfollow(unfollow); _personRepository.Update(aggregate); return(Unit.Task); }