Example #1
0
        public async Task Handle_Should_Succeed_With_ValidCommandAsync()
        {
            // arrange
            var leader           = MemberFake.GuildLeader().Generate();
            var command          = CreateGuildCommandFake.Valid(leader.Id).Generate();
            var expectedNewGuild = leader.GetGuild();
            var unit             = UnitOfWorkMockBuilder.Create()
                                   .SetupMembers(
                x => x.GetForGuildOperationsSuccess(leader.Id, leader)
                .Update(output: leader)
                .Build())
                                   .SetupMemberships(
                x => x.Insert(output: leader.GetActiveMembership())
                .Update(output: leader.GetLastFinishedMembership())
                .Build())
                                   .SetupGuilds(x => x.Insert(output: leader.GetGuild()).Build())
                                   .SetupInvites(x => x.Insert(output: leader.GetGuild().GetLatestInvite()).Build())
                                   .Build();
            var factory = ModelFactoryMockBuilder.Create().CreateGuild(command.Name, leader, expectedNewGuild).Build();
            var sut     = new CreateGuildHandler(unit, factory);

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

            // assert
            result.Should().NotBeNull().And.BeOfType <SuccessCreatedResult>();
            result.Success.Should().BeTrue();
            result.Errors.Should().BeEmpty();
            result.As <SuccessCreatedResult>().StatusCode.Should().Be(StatusCodes.Status201Created);
            result.Data.Should().NotBeNull().And.BeOfType <GuildTestProxy>().And.Be(expectedNewGuild);
        }
Example #2
0
        public async Task Handle_Should_Succeed_With_ValidCommand_GuildLeader()
        {
            // arrange
            var leavingMaster              = (MemberTestProxy)MemberFake.GuildLeader().Generate();
            var expectedNewLeader          = leavingMaster.GetGuild().GetVice();
            var expectedFinishedMembership = leavingMaster.GetActiveMembership();
            var command          = PatchMemberCommandFake.LeaveGuildValid(leavingMaster.Id).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetForGuildOperationsSuccess(command.Id, leavingMaster)
                                   .Update(leavingMaster, leavingMaster)
                                   .Update(expectedNewLeader, expectedNewLeader)
                                   .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(leavingMaster.Id);
            result.Data.As <Member>().GetGuild().Should().BeOfType <NullGuild>();
            result.Data.As <Member>().IsGuildLeader.Should().BeFalse()
            .And.Be(!expectedNewLeader.IsGuildLeader);
            expectedFinishedMembership.Should().BeOfType <MembershipTestProxy>();
            expectedFinishedMembership.Id.Should().Be(leavingMaster.GetLastFinishedMembership().Id);
            expectedFinishedMembership.ModifiedDate.Should().NotBeNull()
            .And.Be(leavingMaster.GetLastFinishedMembership().ModifiedDate);
        }
Example #3
0
        public void Leave_Should_Change_Guild()
        {
            // arrange
            var leader            = (MemberTestProxy)MemberFake.GuildLeader().Generate();
            var monitor           = leader.Monitor();
            var membership        = (MembershipTestProxy)leader.GetActiveMembership();
            var membershipMonitor = membership.Monitor();
            var sut = leader.GetState();

            // act
            sut.Leave();

            // assert
            sut.Guild.Should().BeOfType <GuildTestProxy>().And.NotBe(leader.GetGuild());
            sut.Guild.Members.Should().Contain(leader);
            sut.IsGuildLeader.Should().BeTrue().And.Be(!leader.IsGuildLeader);
            leader.GetGuild().Should().BeOfType <NullGuild>();
            leader.GuildId.Should().BeNull();
            leader.Memberships.Should().Contain(membership);

            monitor.AssertPropertyChanged(
                nameof(Guild),
                nameof(Member.GuildId),
                nameof(Member.IsGuildLeader));

            monitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.Name));
            monitor.AssertCollectionNotChanged(leader.Memberships);

            membershipMonitor.AssertPropertyChanged(nameof(Membership.ModifiedDate));
        }
Example #4
0
        public void Constructor_Should_CreateWith_GivenStatus()
        {
            // arrange
            var leader = (MemberTestProxy)MemberFake.GuildLeader().Generate();

            // act
            var sut = new GuildLeaderState(leader, leader.GetGuild());

            // assert
            sut.Guild.Should().BeOfType <GuildTestProxy>().And.Be(leader.GetGuild());
            sut.IsGuildLeader.Should().BeTrue().And.Be(leader.IsGuildLeader);
            sut.Guild.Members.Should().Contain(leader);
        }
Example #5
0
        public MemberRepositoryMockBuilder GetForGuildOperationsSuccess(Guid?input = null, Member output = null)
        {
            var result = output ?? MemberFake.GuildLeader().Generate();

            if (input == null)
            {
                _mock.Setup(x => x.GetForGuildOperationsAsync(It.IsAny <Guid>(), default)).ReturnsAsync(result);
            }
            else
            {
                _mock.Setup(x => x.GetForGuildOperationsAsync(input.Value, default)).ReturnsAsync(result);
            }

            return(this);
        }
Example #6
0
        public MemberRepositoryMockBuilder Update(Member input = null, Member output = null)
        {
            var result = output ?? MemberFake.GuildLeader().Generate();

            if (input == null)
            {
                _mock.Setup(x => x.Update(It.IsAny <Member>())).Returns(result);
            }
            else
            {
                _mock.Setup(x => x.Update(input)).Returns(result);
            }

            return(this);
        }
Example #7
0
        public void Should_Fail_By_Member_NotFound()
        {
            // arrange
            var member           = MemberFake.GuildLeader().Generate();
            var command          = PatchMemberCommandFake.DemoteMemberValid(member.Id).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetByIdFail(member.Id).Build();
            var sut = new DemoteMemberValidator(memberRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

            // assert
            result.AssertErrorsCount(1);
        }
Example #8
0
        public void Should_Succeed()
        {
            // arrange
            var member           = MemberFake.GuildLeader().Generate();
            var command          = PatchMemberCommandFake.DemoteMemberValid(member.Id).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetByIdSuccess(member.Id, member).Build();
            var sut = new DemoteMemberValidator(memberRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

            // assert
            result.Should().NotBeNull().And.BeOfType <ValidationResult>();
            result.IsValid.Should().BeTrue();
        }
Example #9
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedMember = MemberFake.GuildLeader().Generate();
            var command        = GetMemberCommandFake.Valid(expectedMember.Id).Generate();
            var repository     = MemberRepositoryMockBuilder.Create()
                                 .GetByIdSuccess(input: command.Id, output: expectedMember).Build();
            var sut = new GetMemberHandler(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 <MemberTestProxy>();
            result.Data.As <Member>().Id.Should().Be(expectedMember.Id);
            result.Data.As <Member>().GetGuild().Id.Should().Be(expectedMember.GuildId.Value);
        }
Example #10
0
        public void BeDemoted_Should_Change_Nothing()
        {
            // arrange
            var leader  = (MemberTestProxy)MemberFake.GuildLeader().Generate();
            var monitor = leader.Monitor();
            var sut     = leader.GetState();

            // act
            sut.BeDemoted();

            // assert
            sut.Guild.Should().NotBeNull().And.BeOfType <GuildTestProxy>().And.Be(leader.GetGuild());
            sut.IsGuildLeader.Should().BeTrue().And.Be(!leader.IsGuildLeader);
            sut.Guild.Members.Should().Contain(leader);

            monitor.AssertPropertyChanged(nameof(Member.IsGuildLeader));
            monitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.Name),
                nameof(Guild),
                nameof(Member.GuildId),
                nameof(Member.Memberships));
        }
Example #11
0
        public async Task Handle_Should_Succeed_With_ValidCommandAsync()
        {
            // arrange
            const int canceledCount   = 2;
            var       invitedMember   = MemberFake.GuildLeader().Generate();
            var       promotedMember  = invitedMember.GetGuild().GetVice();
            var       invitingGuild   = GuildFake.Complete().Generate();
            var       acceptedInvite  = InviteFake.ValidToAcceptWithInvitesToCancel(canceledCount, invitingGuild, invitedMember).Generate();
            var       command         = PatchInviteCommandFake.AcceptValid(acceptedInvite.Id).Generate();
            var       canceledInvites = acceptedInvite.GetInvitesToCancel().ToArray();

            var startedMembership  = MembershipFake.Active(invitingGuild, invitedMember).Generate();
            var finishedMembership = invitedMember.GetActiveMembership();

            var unit = UnitOfWorkMockBuilder.Create()
                       .SetupMembers(x => x.Update(input: invitedMember, output: invitedMember)
                                     .Update(input: promotedMember, output: promotedMember).Build())
                       .SetupMemberships(x => x.Insert(output: startedMembership).Update(output: finishedMembership).Build())
                       .SetupInvites(x =>
            {
                x.GetForAcceptOperationSuccess(input: command.Id, output: acceptedInvite)
                .Update(output: acceptedInvite);

                foreach (var i in canceledInvites)
                {
                    x.Update(i, i);
                }

                return(x.Build());
            }).Build();
            var factory = ModelFactoryMockBuilder.Create()
                          .CreateMembership(invitingGuild, invitedMember, startedMembership).Build();
            var sut = new AcceptInviteHandler(unit, factory);

            // 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(acceptedInvite.Id);
            result.Data.As <Invite>().Status.Should().Be(InviteStatuses.Accepted)
            .And.Be(acceptedInvite.Status);

            invitedMember.Should().NotBeOfType <NullMember>();
            invitedMember.IsGuildLeader.Should().BeFalse();
            invitedMember.GetGuild().Should().Be(invitingGuild);

            invitingGuild.Should().NotBeOfType <NullGuild>();
            invitingGuild.Members.Should().Contain(invitedMember);

            finishedMembership.ModifiedDate.Should().NotBeNull()
            .And.Be(invitedMember.GetLastFinishedMembership().ModifiedDate);
            canceledInvites.Should().HaveCount(canceledCount)
            .And.OnlyContain(x => x.Status == InviteStatuses.Canceled);
            promotedMember.Should().NotBeNull().And.BeOfType <MemberTestProxy>();
            promotedMember.IsGuildLeader.Should().Be(!invitedMember.IsGuildLeader);
        }