Пример #1
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedPage     = new Random().Next(1, 5);
            var expectedPages    = new Random().Next(expectedPage, expectedPage + 1);
            var expectedPageSize = new Random().Next(5, 10);
            var command          = ListInviteCommandFake.Valid(expectedPageSize, expectedPage).Generate();
            var repository       = InviteRepositoryMockBuilder.Create().Paginate(
                pageSize: command.PageSize,
                page: command.Page,
                totalItems: command.PageSize * expectedPages).Build();
            var sut = new ListInviteHandler(repository);

            // act
            var result = await sut.Handle(command, default);

            // assert
            result.Should().NotBeNull().And.BeOfType <SuccessResult>();
            result.Success.Should().BeTrue();
            result.Errors.Should().BeEmpty();
            result.As <SuccessResult>().StatusCode.Should().Be(StatusCodes.Status200OK);
            result.Data.Should().NotBeNull().And.BeOfType <PagedResponse <Invite> >();
            result.Data.As <PagedResponse <Invite> >().Items.Should().NotBeEmpty()
            .And.AllBeAssignableTo <Invite>()
            .And.HaveCount(expectedPageSize)
            .And.HaveCount(command.PageSize);
            result.Data.As <PagedResponse <Invite> >().PageSize.Should().Be(expectedPageSize)
            .And.Be(command.PageSize);
            result.Data.As <PagedResponse <Invite> >().Page.Should().Be(expectedPage)
            .And.Be(command.Page);
            result.Data.As <PagedResponse <Invite> >().Pages.Should().Be(expectedPages);
        }
Пример #2
0
        public void Should_Fail_Deny_By_Empty_Id()
        {
            // arrange
            var command          = PatchInviteCommandFake.DenyInvalidByEmptyId().Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create().Build();
            var sut = new DenyInviteValidator(inviteRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
Пример #3
0
        public void Should_Fail_Deny_By_Invite_NotPending()
        {
            // arrange
            var invite           = InviteFake.ValidWithStatus(InviteStatuses.Denied).Generate();
            var command          = PatchInviteCommandFake.DenyValid(invite.Id).Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create().GetByIdSuccess(output: invite).Build();
            var sut = new DenyInviteValidator(inviteRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
Пример #4
0
        public void Should_Fail_Cancel_By_Invite_NotFound()
        {
            // arrange
            var invite           = Invite.Null;
            var command          = PatchInviteCommandFake.CancelValid(invite.Id).Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create().GetByIdFail(command.Id).Build();
            var sut = new CancelInviteValidator(inviteRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
Пример #5
0
        public void Should_Fail_Accept_By_Guild_NotFound()
        {
            // arrange
            var invite           = InviteFake.InvalidWithoutGuild().Generate();
            var command          = PatchInviteCommandFake.AcceptValid(invite.Id).Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create().GetByIdSuccess(output: invite).Build();
            var sut = new AcceptInviteValidator(inviteRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
Пример #6
0
        public void Should_Succeed_Deny()
        {
            // arrange
            var invite           = InviteFake.ValidWithStatus().Generate();
            var command          = PatchInviteCommandFake.DenyValid(invite.Id).Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create().GetByIdSuccess(output: invite).Build();
            var sut = new DenyInviteValidator(inviteRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.Should().NotBeNull().And.BeOfType <ValidationResult>();
            result.IsValid.Should().BeTrue();
        }
Пример #7
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedInvite = InviteFake.ValidWithStatus(InviteStatuses.Accepted).Generate();
            var command        = GetInviteCommandFake.Valid(expectedInvite.Id).Generate();
            var repository     = InviteRepositoryMockBuilder.Create()
                                 .GetByIdSuccess(input: command.Id, output: expectedInvite).Build();
            var sut = new GetInviteHandler(repository);

            // act
            var result = await sut.Handle(command, default);

            // assert
            result.Should().NotBeNull().And.BeOfType <SuccessResult>();
            result.Success.Should().BeTrue();
            result.Errors.Should().BeEmpty();
            result.As <SuccessResult>().StatusCode.Should().Be(StatusCodes.Status200OK);
            result.Data.Should().NotBeNull().And.BeOfType <InviteTestProxy>();
            result.Data.As <Invite>().Id.Should().Be(expectedInvite.Id);
            result.Data.As <Invite>().GetGuild().Id.Should().Be(expectedInvite.GuildId.Value);
            result.Data.As <Invite>().GetMember().Id.Should().Be(expectedInvite.MemberId.Value);
        }
Пример #8
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var deniedInvite     = InviteFake.ValidWithStatus(InviteStatuses.Pending).Generate();
            var command          = PatchInviteCommandFake.DenyValid(deniedInvite.Id).Generate();
            var inviteRepository = InviteRepositoryMockBuilder.Create()
                                   .GetByIdSuccess(command.Id, deniedInvite)
                                   .Update(deniedInvite, deniedInvite)
                                   .Build();
            var sut = new DenyInviteHandler(inviteRepository);

            // act
            var result = await sut.Handle(command, default);

            // assert
            result.Should().NotBeNull().And.BeOfType <SuccessResult>();
            result.Success.Should().BeTrue();
            result.Errors.Should().BeEmpty();
            result.As <SuccessResult>().StatusCode.Should().Be(StatusCodes.Status200OK);
            result.Data.Should().NotBeNull().And.BeOfType <InviteTestProxy>();
            result.Data.As <Invite>().Id.Should().Be(deniedInvite.Id);
            result.Data.As <Invite>().Status.Should().Be(InviteStatuses.Denied)
            .And.Be(deniedInvite.Status);
        }