Example #1
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);
        }
Example #2
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var promotedMember        = MemberFake.GuildMember().Generate();
            var guild                 = promotedMember.GetGuild();
            var expectedDemotedMember = promotedMember.GetGuild().GetLeader();
            var command               = PatchMemberCommandFake.PromoteMemberValid(promotedMember.Id).Generate();
            var memberRepository      = MemberRepositoryMockBuilder.Create()
                                        .GetForGuildOperationsSuccess(command.Id, promotedMember)
                                        .Update(promotedMember, promotedMember)
                                        .Update(expectedDemotedMember, expectedDemotedMember)
                                        .Build();
            var sut = new PromoteMemberHandler(memberRepository);

            // 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(promotedMember.Id);
            result.Data.As <Member>().IsGuildLeader.Should().BeTrue()
            .And.Be(!expectedDemotedMember.IsGuildLeader);
            result.Data.As <Member>().GetGuild().Should().NotBeNull();
            result.Data.As <Member>().GetGuild().Id.Should().Be(guild.Id);
        }
Example #3
0
        public void Join_Should_Change_Guild_And_Memberships()
        {
            // arrange
            var member  = (MemberTestProxy)MemberFake.GuildMember().Generate();
            var guild   = (GuildTestProxy)GuildFake.Complete().Generate();
            var monitor = member.Monitor();
            var sut     = member.GetState();
            var factory = TestModelFactoryHelper.Factory;

            // act
            sut.Join(guild, factory);

            // assert
            sut.Guild.Should().NotBeNull().And.BeOfType <GuildTestProxy>().And.NotBe(member.GetGuild());
            sut.IsGuildLeader.Should().BeFalse().And.Be(member.IsGuildLeader);
            sut.Guild.Members.Should().Contain(member);
            guild.Members.Should().Contain(member);
            member.GuildId.Should().NotBeNull();

            monitor.AssertCollectionChanged(member.Memberships);
            monitor.AssertPropertyChanged(
                nameof(Guild),
                nameof(Member.GuildId));

            monitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.Name),
                nameof(Member.IsGuildLeader));
        }
Example #4
0
        public void BePromoted_Should_Change_IsGuildLeader()
        {
            // arrange
            var member  = (MemberTestProxy)MemberFake.GuildMember().Generate();
            var monitor = member.Monitor();
            var sut     = member.GetState();

            // act
            sut.BePromoted();

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

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

            monitor.AssertCollectionNotChanged(member.Memberships);
        }
Example #5
0
        public void Leave_Should_Change_Guild()
        {
            // arrange
            var member            = (MemberTestProxy)MemberFake.GuildMember().Generate();
            var monitor           = member.Monitor();
            var membership        = (MembershipTestProxy)member.GetActiveMembership();
            var membershipMonitor = membership.Monitor();
            var sut = member.GetState();

            // act
            sut.Leave();

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

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

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

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

            // act
            var sut = new GuildMemberState(member, member.GetGuild());

            // assert
            sut.Guild.Should().BeOfType <GuildTestProxy>().And.Be(member.GetGuild());
            sut.IsGuildLeader.Should().BeFalse().And.Be(member.IsGuildLeader);
            sut.Guild.Members.Should().Contain(member);
        }
Example #7
0
        public void Should_Fail_By_Member_NotGuildLeader()
        {
            // arrange
            var member           = MemberFake.GuildMember().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.AssertErrorsCount(1);
        }
Example #8
0
        public void Should_Succeed()
        {
            // arrange
            var member           = MemberFake.GuildMember().Generate();
            var command          = PatchMemberCommandFake.LeaveGuildValid(member.Id).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetByIdSuccess(member.Id, member).Build();
            var sut = new LeaveGuildValidator(memberRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

            // assert
            result.Should().NotBeNull().And.BeOfType <ValidationResult>();
            result.IsValid.Should().BeTrue();
        }