Ejemplo n.º 1
0
        public void IfInvalidRequest()
        {
            var command = new AcceptInvitationCommand();

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        public async Task HandleAsync(AcceptInvitationCommand message)
        {
            var invitation = await this.domainRepository.GetByKeyAsync <Guid, Invitation>(message.InvitationId);

            var user = await this.domainRepository.GetByKeyAsync <Guid, User>(message.UserId);

            user.ApproveInvitation(invitation);
            await this.domainRepository.SaveAsync <Guid, User>(user);
        }
Ejemplo n.º 3
0
 public async Task Initialize()
 {
     IsBusy = true;
     BandInvitations.ReplaceRange(await App.Database.GetUserBandInvitations(DependencyService
                                                                            .Resolve <IAuthenticationService>()
                                                                            .GetCurrentUserId()));
     IsBusy = false;
     AcceptInvitationCommand.RaiseCanExecuteChanged();
     DenyInvitationCommand.RaiseCanExecuteChanged();
 }
Ejemplo n.º 4
0
        private async Task DenyInvitation(Invitation arg)
        {
            IsBusy = true;
            AcceptInvitationCommand.RaiseCanExecuteChanged();
            DenyInvitationCommand.RaiseCanExecuteChanged();
            await App.Database.RemoveInvitation(arg);

            await Shell.Current.CurrentPage.DisplayToastAsync("Pozvánka odmítnuta!");

            await Initialize();
        }
Ejemplo n.º 5
0
        public IHttpActionResult AcceptInvitation([FromBody] dynamic model)
        {
            var currentUserId = (string)model.CurrentUserId;
            var invitationId  = (string)model.InvitationId;
            var command       = new AcceptInvitationCommand
            {
                InvitationId = Guid.Parse(invitationId),
                UserId       = Guid.Parse(currentUserId)
            };

            this.CommandSender.Publish(command);
            return(Ok());
        }
Ejemplo n.º 6
0
        public void IfUserEmailNotFound()
        {
            _invitationRepository.Setup(x => x.Get(_invitation.Id)).ReturnsAsync(_invitation);
            _userAccountRepository.Setup(x => x.Get(_invitation.Email)).ReturnsAsync(null);

            var command = new AcceptInvitationCommand
            {
                Id = _invitation.Id
            };

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 7
0
        public void IfHasExpired()
        {
            _invitation.ExpiryDate = DateTimeProvider.Current.UtcNow.AddDays(-2);

            _invitationRepository.Setup(x => x.Get(_invitation.Id)).ReturnsAsync(_invitation);

            var command = new AcceptInvitationCommand
            {
                Id = _invitation.Id
            };

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 8
0
        public void IfStatusIsNotPending()
        {
            _invitation.Status = InvitationStatus.Accepted;

            _invitationRepository.Setup(x => x.Get(_invitation.Id)).ReturnsAsync(_invitation);

            var command = new AcceptInvitationCommand
            {
                Id = _invitation.Id
            };

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 9
0
        public void IfNotExists()
        {
            const long invitationId = 1;

            _invitationRepository.Setup(x => x.Get(invitationId)).ReturnsAsync(null);

            var command = new AcceptInvitationCommand
            {
                Id = _invitation.Id
            };

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 10
0
        public void IfAlreadyAMember()
        {
            _invitationRepository.Setup(x => x.Get(_invitation.Id)).ReturnsAsync(_invitation);
            _userAccountRepository.Setup(x => x.Get(_invitation.Email)).ReturnsAsync(new User());
            _membershipRepository.Setup(x => x.GetCaller(It.IsAny <long>(), It.IsAny <string>())).ReturnsAsync(new MembershipView());

            var command = new AcceptInvitationCommand
            {
                Id = _invitation.Id
            };

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
        }
Ejemplo n.º 11
0
        private async Task AcceptInvitation(Invitation arg)
        {
            IsBusy = true;
            AcceptInvitationCommand.RaiseCanExecuteChanged();
            DenyInvitationCommand.RaiseCanExecuteChanged();
            var bandMusician = new BandMusicians
            {
                BandId     = arg.ToBandId,
                MusicianId = DependencyService.Resolve <IAuthenticationService>().GetCurrentUserId(),
                TimeStamp  = DateTime.Now
            };
            await App.Database.AddBandMember(bandMusician);

            await App.Database.RemoveInvitation(arg);

            await Shell.Current.CurrentPage.DisplayToastAsync("Pozvánka úspěšně přijata!");

            await Initialize();
        }