コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: PeopleController.cs プロジェクト: fraidev/Flue
        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());
        }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: PersonCommandHandler.cs プロジェクト: fraidev/Flue
        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);
        }
コード例 #5
0
        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)));
        }