Example #1
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedMember = MemberFake.WithoutGuild().Generate();
            var command        = PatchMemberCommandFake.ChangeMemberNameValid(
                id: expectedMember.Id,
                name: expectedMember.Name).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetByIdSuccess(command.Id, expectedMember)
                                   .Update(expectedMember, expectedMember)
                                   .Build();
            var sut = new ChangeMemberNameHandler(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>().Name.Should().Be(expectedMember.Name);
            result.Data.As <Member>().Id.Should().Be(expectedMember.Id);
        }
Example #2
0
        public MemberRepositoryMockBuilder Insert(string name, Member output = null)
        {
            var result = output ?? MemberFake.WithoutGuild().Generate();

            _mock.Setup(x => x.InsertAsync(It.Is <Member>(x => x.Name == name), default)).ReturnsAsync(result);
            return(this);
        }
Example #3
0
        public void Join_Should_Change_Guild_And_Memberships()
        {
            // arrange
            var member  = (MemberTestProxy)MemberFake.WithoutGuild().Generate();
            var monitor = member.Monitor();
            var guild   = (GuildTestProxy)GuildFake.Complete().Generate();
            var sut     = member.GetState();
            var factory = TestModelFactoryHelper.Factory;

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

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

            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 Promote_NotMember_Should_Change_Nothing()
        {
            // arrange
            var sut             = (GuildTestProxy)GuildFake.Complete().Generate();
            var monitor         = sut.Monitor();
            var notMember       = (MemberTestProxy)MemberFake.WithoutGuild().Generate();
            var unchangedLeader = sut.GetLeader();

            // act
            sut.Promote(notMember);

            // assert
            sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>();
            sut.Members.Should().Contain(unchangedLeader).And.NotContain(notMember);
            sut.GetLeader().Should().NotBeNull()
            .And.BeOfType <MemberTestProxy>()
            .And.Be(unchangedLeader)
            .And.NotBe(notMember);
            sut.GetVice().Should().NotBeNull()
            .And.BeOfType <MemberTestProxy>();
            notMember.IsGuildLeader.Should().BeFalse().And.Be(!unchangedLeader.IsGuildLeader);

            monitor.AssertCollectionNotChanged(sut.Members, sut.Invites);
            monitor.AssertPropertyNotChanged(
                nameof(Guild.Id),
                nameof(Guild.Name));
            monitor.AssertCollectionNotChanged(sut.Members, sut.Invites);
        }
Example #5
0
        public void InviteMember_NotInGuild_Should_Change_Invites()
        {
            // arrange
            var sut = (GuildTestProxy)GuildFake.Complete().Generate();
            var expectedMembersCount = sut.Members.Count;
            var expectedInvitesCount = sut.Invites.Count + 1;
            var monitor = sut.Monitor();
            var member  = (MemberTestProxy)MemberFake.WithoutGuild().Generate();

            // act
            sut.InviteMember(member, TestModelFactoryHelper.Factory);

            // assert
            sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>();
            sut.GetLatestInvite().Should().NotBeNull().And.BeOfType <InviteTestProxy>();
            sut.Members.Should().NotBeEmpty().And.HaveCount(expectedMembersCount);
            sut.Invites.Should().NotBeEmpty()
            .And.Match(x => x.Any(y => y.GetMember().Equals(member)))
            .And.HaveCount(expectedInvitesCount);

            monitor.AssertPropertyNotChanged(
                nameof(Guild.Id),
                nameof(Guild.Name));
            monitor.AssertCollectionChanged(sut.Invites);
            monitor.AssertCollectionNotChanged(sut.Members);
        }
Example #6
0
        public async Task Handle_Should_Succeed_With_ValidCommandAsync()
        {
            // arrange
            var guild          = GuildFake.Complete().Generate();
            var member         = MemberFake.WithoutGuild().Generate();
            var command        = InviteMemberCommandFake.Valid(guild.Id, member.Id).Generate();
            var expectedInvite = InviteFake.ValidWithStatus(InviteStatuses.Pending, guild, member).Generate();

            var unit = UnitOfWorkMockBuilder.Create()
                       .SetupMembers(x => x.GetByIdSuccess(command.MemberId, member).Build())
                       .SetupGuilds(x => x.GetByIdSuccess(command.GuildId, guild).Build())
                       .SetupInvites(x => x.Insert(output: expectedInvite).Build())
                       .Build();
            var factory = ModelFactoryMockBuilder.Create().CreateInvite(guild, member, expectedInvite).Build();
            var sut     = new InviteMemberHandler(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 <InviteTestProxy>();
            result.Data.As <Invite>().Should().Be(expectedInvite);
        }
Example #7
0
        public void Constructor_Should_CreateWith_GivenStatus()
        {
            // arrange
            var member = (MemberTestProxy)MemberFake.WithoutGuild().Generate();

            // act
            var sut = new NoGuildMemberState(member);

            // assert
            sut.Guild.Should().BeOfType <NullGuild>().And.Be(member.GetGuild());
            sut.IsGuildLeader.Should().BeFalse().And.Be(member.IsGuildLeader);
            sut.Guild.Members.Should().NotContain(member);
        }
Example #8
0
        public void CreateGuild_WithNameAndMember_Should_Create_With_AllProperties()
        {
            // arrange
            const string expectedName = "name";
            var          member       = MemberFake.WithoutGuild().Generate();

            // act
            var model = _sut.CreateGuild(expectedName, member);

            // assert
            model.Should().NotBeNull().And.BeOfType <GuildTestProxy>();
            model.Id.Should().NotBeEmpty();
            model.Name.Should().NotBeEmpty().And.Be(expectedName);
            model.Members.Should().Contain(member);
            model.Invites.Should().Contain(x => x.MemberId == member.Id && x.GuildId == model.Id);
        }
Example #9
0
        public void Should_Fail_By_Member_Without_Guild()
        {
            // arrange
            var member           = MemberFake.WithoutGuild().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 #10
0
        public void CreateMembership_WithGuildAndMember_Should_CreateWith_AllProperties_Except_ModifiedDate()
        {
            // arrange
            var guild  = GuildFake.Complete().Generate();
            var member = MemberFake.WithoutGuild().Generate();

            // act
            var model = _sut.CreateMembership(guild, member);

            // assert
            model.Should().NotBeNull().And.BeOfType <MembershipTestProxy>();
            model.Id.Should().NotBeEmpty();
            model.ModifiedDate.Should().BeNull();
            model.GuildName.Should().Be(guild.Name);
            model.GuildId.Should().NotBeEmpty().And.Be(guild.Id);
            model.MemberName.Should().Be(member.Name);
            model.MemberId.Should().NotBeEmpty().And.Be(member.Id);
        }
Example #11
0
        public void CreateInvite_WithGuildAndMember_Should_Create_Pending_With_AllProperties()
        {
            // arrange
            var guild  = GuildFake.Complete().Generate();
            var member = MemberFake.WithoutGuild().Generate();
            const InviteStatuses expectedStatus = InviteStatuses.Pending;

            // act
            var model = _sut.CreateInvite(guild, member);

            // assert
            model.Should().NotBeNull().And.BeOfType <InviteTestProxy>();
            model.Id.Should().NotBeEmpty();
            model.GetGuild().Should().NotBeNull().And.Be(guild);
            model.GuildId.Should().NotBeEmpty().And.Be(guild.Id);
            model.GetMember().Should().NotBeNull().And.Be(member);
            model.MemberId.Should().NotBeEmpty().And.Be(member.Id);
            model.Status.Should().Be(expectedStatus);
        }
Example #12
0
        public async Task Handle_Should_Succeed_With_ValidCommandAsync()
        {
            // arrange
            var command        = CreateMemberCommandFake.Valid().Generate();
            var expectedMember = MemberFake.WithoutGuild(command.Name).Generate();
            var repository     = MemberRepositoryMockBuilder.Create().Insert(command.Name, expectedMember).Build();
            var factory        = ModelFactoryMockBuilder.Create().CreateMember(command.Name, expectedMember).Build();
            var sut            = new CreateMemberHandler(repository, factory);

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

            // assert
            response.Should().NotBeNull().And.BeOfType <SuccessCreatedResult>();
            response.Success.Should().BeTrue();
            response.Errors.Should().BeEmpty();
            response.As <SuccessCreatedResult>().StatusCode.Should().Be(StatusCodes.Status201Created);
            response.Data.Should().NotBeNull().And.BeOfType <MemberTestProxy>();
            response.Data.As <Member>().Should().Be(expectedMember);
        }
Example #13
0
        public void RemoveMember_WithoutGuild_Should_Change_Nothing()
        {
            var sut = (GuildTestProxy)GuildFake.Complete().Generate();
            var expectedMembersCount = sut.Members.Count;
            var expectedInvitesCount = sut.Invites.Count;
            var monitor       = sut.Monitor();
            var member        = (MemberTestProxy)MemberFake.WithoutGuild().Generate();
            var memberMonitor = member.Monitor();

            // act
            sut.RemoveMember(member);

            // assert
            sut.Should().NotBeNull()
            .And.BeOfType <GuildTestProxy>();
            sut.Members.Should().NotBeEmpty()
            .And.HaveCount(expectedMembersCount)
            .And.NotContain(member);
            sut.Invites.Should().NotBeEmpty()
            .And.HaveCount(expectedInvitesCount);

            monitor.AssertPropertyNotChanged(
                nameof(Guild.Id),
                nameof(Guild.Name),
                nameof(Guild.Members),
                nameof(Guild.Invites));

            member.Should().NotBeNull()
            .And.BeOfType <MemberTestProxy>();
            member.IsGuildLeader.Should().BeFalse();
            member.GuildId.Should().BeNull();
            member.GetGuild().Should().BeOfType <NullGuild>();

            memberMonitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.Name),
                nameof(Member.GuildId),
                nameof(Guild),
                nameof(Member.IsGuildLeader),
                nameof(Member.Memberships));
        }
Example #14
0
        public void ChangeName_WithName_Should_Change_NameOnly()
        {
            // arrange
            var expectedName = new Person().UserName;
            var sut          = (MemberTestProxy)MemberFake.WithoutGuild().Generate();
            var monitor      = sut.Monitor();

            // act
            sut.ChangeName(expectedName);

            // assert
            sut.Should().NotBeNull().And.BeOfType <MemberTestProxy>();
            sut.Name.Should().NotBeEmpty().And.Be(expectedName);

            monitor.AssertPropertyChanged(nameof(Member.Name));
            monitor.AssertCollectionNotChanged(sut.Memberships);
            monitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.IsGuildLeader),
                nameof(Member.GuildId),
                nameof(Guild));
        }
Example #15
0
        public void BeDemoted_Should_Change_Nothing()
        {
            // arrange
            var member  = (MemberTestProxy)MemberFake.WithoutGuild().Generate();
            var monitor = member.Monitor();
            var sut     = member.GetState();

            // act
            sut.BeDemoted();

            // assert
            sut.Guild.Should().NotBeNull().And.BeOfType <NullGuild>().And.Be(member.GetGuild());
            sut.IsGuildLeader.Should().BeFalse().And.Be(member.IsGuildLeader);
            sut.Guild.Members.Should().NotContain(member);
            member.GuildId.Should().BeNull();

            monitor.AssertCollectionNotChanged(member.Memberships);
            monitor.AssertPropertyNotChanged(
                nameof(Member.Id),
                nameof(Member.Name),
                nameof(Guild),
                nameof(Member.GuildId),
                nameof(Member.IsGuildLeader));
        }
Example #16
0
        public void AddMember_NotInGuild_Should_Change_Members()
        {
            // arrange
            var sut = (GuildTestProxy)GuildFake.Complete().Generate();
            var expectedMembersCount = sut.Members.Count + 1;
            var expectedInvitesCount = sut.Invites.Count;
            var monitor = sut.Monitor();
            var member  = (MemberTestProxy)MemberFake.WithoutGuild().Generate();

            // act
            sut.AddMember(member);

            // assert
            sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>();
            sut.Members.Should().NotBeEmpty().And.HaveCount(expectedMembersCount);
            sut.Invites.Should().NotBeEmpty().And.HaveCount(expectedInvitesCount);

            monitor.AssertCollectionChanged(sut.Members);

            monitor.AssertPropertyNotChanged(
                nameof(Guild.Id),
                nameof(Guild.Name));
            monitor.AssertCollectionNotChanged(sut.Invites);
        }