public async Task Handle_WhenHandlingGetInvitationQueryAndProviderIsFound_ThenShouldReturnGetInvitationQueryResult(
            ProviderRegistrationsDbContext setupContext,
            GetInvitationQueryHandler handler,
            Invitation invitation)
        {
            //arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var query = new GetInvitationQuery(invitation.Ukprn, invitation.UserRef, "EmployerOrganisation", "Desc");

            //act
            var result = await handler.Handle(query, new CancellationToken());

            //assert
            result.Should().NotBeNull();
            result.Invitations.Should().NotBeNull();
            result.Invitations.Count.Should().Be(1);
            result.Invitations.First().Should().BeEquivalentTo(
                new
            {
                invitation.Ukprn,
                invitation.Status,
                invitation.EmployerOrganisation,
                invitation.EmployerFirstName,
                invitation.EmployerLastName,
                invitation.EmployerEmail
            }
                );
        }
        public async Task Handle_WhenHandlingGetInvitationByIdQueryAndInvitationIsFound_ThenShouldReturnGetInvitationByIdQueryResult(
            ProviderRegistrationsDbContext setupContext,
            Invitation invitation,
            GetInvitationByIdQueryHandler handler
            )
        {
            //arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var query = new GetInvitationByIdQuery(invitation.Reference);

            //act
            var result = await handler.Handle(query, new CancellationToken());

            //assert
            result.Invitation.Should().NotBeNull();
            result.Invitation.Should().BeEquivalentTo(new
            {
                invitation.Ukprn,
                invitation.EmployerFirstName,
                invitation.EmployerLastName,
                invitation.EmployerEmail,
                invitation.EmployerOrganisation,
                invitation.Status,
                SentDate = invitation.CreatedDate
            });
        }
        public async Task Handle_WhenHandlingAddInvitationCommand_ThenShouldReturnReference(
            ProviderRegistrationsDbContext confirmationContext,
            AddInvitationCommandHandler handler,
            AddInvitationCommand command)
        {
            //arrange

            //act
            var result = await handler.Handle(command, new CancellationToken());

            //assert
            confirmationContext.Invitations.Should().ContainEquivalentOf(new { Reference = Guid.Parse(result) });
        }
        public async Task Handle_WhenHandlingGetUnsubscribedQueryAndParametersAreMatched_ThenShouldReturnGetATrueResult(
            ProviderRegistrationsDbContext setupContext,
            Unsubscribe entity,
            GetUnsubscribedQueryHandler handler)
        {
            //arrange
            setupContext.Unsubscribed.Add(entity);
            await setupContext.SaveChangesAsync();

            var query = new GetUnsubscribedQuery(entity.Ukprn, entity.EmailAddress);

            //act
            var result = await handler.Handle(query, new CancellationToken());

            //assert
            result.Should().BeTrue();
        }
Example #5
0
        public async Task Handle_WhenDoesntExistCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext db,
            ProviderRegistrationsDbContext confirmationContext,
            SignedAgreementCommandHandler handler,
            SignedAgreementCommand command,
            Invitation invite)
        {
            //arrange
            db.Invitations.Add(invite);
            invite.UpdateStatus((int)InvitationStatus.InvitationSent, DateTime.Now);
            await db.SaveChangesAsync();

            //act
            await((IRequestHandler <SignedAgreementCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var savedInvite = await confirmationContext.Invitations.FirstAsync(i => i.Reference == invite.Reference);

            savedInvite.Status.Should().Be((int)InvitationStatus.InvitationSent);
        }
        public async Task Handle_WhenCommandIsHandled_ThenShouldUpdateInvitationStatus(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            UnsubscribeByIdCommandHandler handler,
            Invitation invitation)
        {
            //arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var command = new UnsubscribeByIdCommand(invitation.Reference);

            //act
            await((IRequestHandler <UnsubscribeByIdCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var unsubscribe = confirmationContext.Unsubscribed.Single(s => s.EmailAddress == invitation.EmployerEmail && s.Ukprn == invitation.Ukprn);

            unsubscribe.Should().NotBeNull();
        }
Example #7
0
        public async Task Handle_WhenInvalidStatusCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            SignedAgreementCommandHandler handler,
            SignedAgreementCommand command,
            Invitation invite)
        {
            //arrange
            command.CorrelationId = invite.Reference.ToString();
            setupContext.Invitations.Add(invite);
            invite.UpdateStatus((int)InvitationStatus.InvitationComplete, DateTime.Now);
            await setupContext.SaveChangesAsync();

            //act
            await((IRequestHandler <SignedAgreementCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var savedInvite = await confirmationContext.Invitations.FirstAsync(i => i.Reference.ToString() == command.CorrelationId);

            savedInvite.Status.Should().Be((int)InvitationStatus.InvitationComplete);
        }
        public async Task Handle_WhenInvalidStatusCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            UpsertUserCommandHandler handler,
            Invitation invitation)
        {
            //arrange
            invitation.UpdateStatus((int)InvitationStatus.InvitationComplete, DateTime.Now);
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var command = new UpsertUserCommand(invitation.UserRef, DateTime.Now, invitation.Reference.ToString());

            //act
            await((IRequestHandler <UpsertUserCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var updatedInvite = await confirmationContext.Invitations.SingleAsync(s => s.Reference == invitation.Reference);

            updatedInvite.Status.Should().Be((int)InvitationStatus.InvitationComplete);
        }
        public async Task Handle_WhenDoesntExistCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            UpsertUserCommandHandler handler,
            Invitation invitation)
        {
            //arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var statusBefore = invitation.Status;
            var command      = new UpsertUserCommand(invitation.UserRef, DateTime.Now, "unknownreference");

            //act
            await((IRequestHandler <UpsertUserCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var dbInvite = await confirmationContext.Invitations.FirstAsync(f => f.Reference == invitation.Reference);

            dbInvite.Status.Should().Be(statusBefore);
        }
Example #10
0
        public async Task Handle_WhenCommandIsHandled_ThenShouldUpdateInvitationStatus(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            AddedPayeSchemeCommandHandler handler,
            AddedPayeSchemeCommand command,
            Invitation invitation)
        {
            //arrange
            invitation.UpdateStatus((int)InvitationStatus.InvitationSent, DateTime.Now);
            command.CorrelationId = invitation.Reference.ToString();
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            //act
            await((IRequestHandler <AddedPayeSchemeCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            var savedInvitation = await confirmationContext.Invitations.FirstAsync();

            savedInvitation.Status.Should().Be((int)InvitationStatus.PayeSchemeAdded);
        }
Example #11
0
        public async Task Handle_WhenInvalidStatusCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            AddedAccountProviderCommandHandler handler,
            AddedAccountProviderCommand command,
            Invitation invitation)
        {
            //Arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var statusBefore = invitation.Status;

            //act
            await((IRequestHandler <AddedAccountProviderCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            // Confirm nothing has changed.
            var invite = await confirmationContext.Invitations.FirstAsync();

            invite.Status.Should().Be(statusBefore);
        }
Example #12
0
        public async Task Handle_WhenCommandIsHandled_ThenShouldUpdateInvitationStatus(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            AddedAccountProviderCommandHandler handler,
            Invitation invitation)
        {
            //Arrange
            var command = new AddedAccountProviderCommand(invitation.Ukprn, Guid.NewGuid(), invitation.Reference.ToString());

            invitation.UpdateStatus((int)InvitationStatus.InvitationSent, DateTime.Now);
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            //act
            await((IRequestHandler <AddedAccountProviderCommand, Unit>)handler).Handle(command, new CancellationToken());


            //assert
            var savedInvitation = await confirmationContext.Invitations.FirstAsync();

            savedInvitation.Status.Should().Be((int)InvitationStatus.InvitationComplete);
        }
Example #13
0
        public async Task Handle_WhenInvalidStatusCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            AddedPayeSchemeCommandHandler handler,
            AddedPayeSchemeCommand command,
            Invitation invitation)
        {
            //arrange
            invitation.UpdateStatus((int)InvitationStatus.LegalAgreementSigned, DateTime.Now);
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            command.CorrelationId = invitation.Reference.ToString();

            //act
            await((IRequestHandler <AddedPayeSchemeCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            // Confirm nothing has changed.
            var invite = await confirmationContext.Invitations.FirstAsync();

            invite.Status.Should().Be((int)InvitationStatus.LegalAgreementSigned);
        }
        public async Task Handle_WhenHandlingAddInvitationCommand_ThenShouldAddInvitation(
            ProviderRegistrationsDbContext confirmationContext,
            AddInvitationCommandHandler handler,
            AddInvitationCommand command)
        {
            //arrange

            //act
            var result = await handler.Handle(command, new CancellationToken());

            //assert
            var invitation = confirmationContext.Invitations.First(f => f.Reference.ToString() == result);

            invitation.Should().BeEquivalentTo(new
            {
                command.Ukprn,
                command.UserRef,
                command.EmployerFirstName,
                command.EmployerLastName,
                command.EmployerEmail,
                command.EmployerOrganisation
            });
        }
Example #15
0
        public async Task Handle_WhenDoesntExistCommandIsHandled_ThenNoChangesAreMade(
            ProviderRegistrationsDbContext setupContext,
            ProviderRegistrationsDbContext confirmationContext,
            AddedPayeSchemeCommandHandler handler,
            AddedPayeSchemeCommand command,
            Invitation invitation)
        {
            //arrange
            setupContext.Invitations.Add(invitation);
            await setupContext.SaveChangesAsync();

            var statusBefore = invitation.Status;

            command.CorrelationId = invitation.Reference.ToString();

            //act
            await((IRequestHandler <AddedPayeSchemeCommand, Unit>)handler).Handle(command, new CancellationToken());

            //assert
            // Confirm nothing has changed.
            var invite = await confirmationContext.Invitations.FirstAsync();

            invite.Status.Should().Be(statusBefore);
        }