示例#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          = ListMembershipCommandFake.Valid(expectedPageSize, expectedPage).Generate();
            var repository       = MembershipRepositoryMockBuilder.Create().Paginate(
                pageSize: command.PageSize,
                page: command.Page,
                totalItems: command.PageSize * expectedPages).Build();
            var sut = new ListMembershipHandler(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 <Membership> >();
            result.Data.As <PagedResponse <Membership> >().Items.Should().NotBeEmpty()
            .And.AllBeAssignableTo <Membership>()
            .And.HaveCount(expectedPageSize)
            .And.HaveCount(command.PageSize);
            result.Data.As <PagedResponse <Membership> >().PageSize.Should().Be(expectedPageSize)
            .And.Be(command.PageSize);
            result.Data.As <PagedResponse <Membership> >().Page.Should().Be(expectedPage)
            .And.Be(command.Page);
            result.Data.As <PagedResponse <Membership> >().Pages.Should().Be(expectedPages);
        }
示例#2
0
        public async Task Handle_Should_Succeed_With_ValidCommand_GuildMember()
        {
            // arrange
            var leavingMember              = (MemberTestProxy)MemberFake.GuildMember().Generate();
            var expectedUnchangedLeader    = leavingMember.GetGuild().GetLeader();
            var expectedFinishedMembership = leavingMember.GetActiveMembership();
            var command          = PatchMemberCommandFake.LeaveGuildValid(leavingMember.Id).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetForGuildOperationsSuccess(command.Id, leavingMember)
                                   .Update(leavingMember, leavingMember)
                                   .Update(expectedUnchangedLeader, expectedUnchangedLeader)
                                   .Build();
            var membershipRepository = MembershipRepositoryMockBuilder.Create()
                                       .Update(expectedFinishedMembership, expectedFinishedMembership).Build();
            var sut = new LeaveGuildHandler(memberRepository, membershipRepository);

            // 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 <MemberTestProxy>();
            result.Data.As <Member>().Id.Should().Be(leavingMember.Id);
            result.Data.As <Member>().IsGuildLeader.Should().BeFalse()
            .And.Be(!expectedUnchangedLeader.IsGuildLeader);
            result.Data.As <Member>().GetGuild().Should().BeOfType <NullGuild>();
            expectedFinishedMembership.Should().NotBeOfType <NullMembership>();
            expectedFinishedMembership.Id.Should().Be(leavingMember.GetLastFinishedMembership().Id);
            expectedFinishedMembership.ModifiedDate.Should().NotBeNull()
            .And.Be(leavingMember.GetLastFinishedMembership().ModifiedDate);
        }