public void DemoteLeader_GuildWithLeaderAndMembers_Should_Change_GuildLeader() { // arrange var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var monitor = sut.Monitor(); var expectedLeader = sut.GetVice(); var expectedVice = sut.GetLeader(); // act sut.DemoteLeader(); var actualLeader = sut.GetLeader(); var actualVice = sut.GetVice(); // assert sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>(); sut.Members.Should().Contain(new[] { expectedLeader, expectedVice }); actualLeader.Should().NotBeNull() .And.BeOfType <MemberTestProxy>() .And.Be(expectedLeader); actualVice.Should().NotBeNull() .And.BeOfType <MemberTestProxy>() .And.Be(expectedVice); actualLeader.Should().NotBe(actualVice); actualLeader.IsGuildLeader.Should().BeTrue(); actualVice.IsGuildLeader.Should().BeFalse(); monitor.AssertPropertyNotChanged( nameof(Guild.Id), nameof(Guild.Name)); monitor.AssertCollectionNotChanged(sut.Members, sut.Invites); }
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)); }
public void Promote_GuildLeader_Should_Change_Nothing() { // arrange var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var monitor = sut.Monitor(); var leader = sut.GetLeader(); var vice = sut.GetVice(); // act sut.Promote(leader); // assert sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>(); sut.Members.Should().Contain(new[] { leader, vice }); sut.GetLeader().Should().NotBeNull() .And.NotBeOfType <NullMember>() .And.Be(leader) .And.NotBe(vice); sut.GetVice().Should().NotBeNull() .And.NotBeOfType <NullMember>() .And.Be(vice) .And.NotBe(leader); leader.IsGuildLeader.Should().BeTrue(); vice.IsGuildLeader.Should().BeFalse(); monitor.AssertPropertyNotChanged( nameof(Guild.Id), nameof(Guild.Name)); monitor.AssertCollectionNotChanged(sut.Members, sut.Invites); }
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); }
public void RemoveMember_NullMember_Should_Change_Nothing() { // arrange var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var expectedMembersCount = sut.Members.Count; var expectedInvitesCount = sut.Invites.Count; var monitor = sut.Monitor(); var member = Member.Null; // 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)); }
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); }
public async Task Handle_Should_Succeed_With_ValidCommand() { // arrange var guild = GuildFake.Complete().Generate(); var demotedLeader = guild.GetLeader(); var expectedNewLeader = guild.GetVice(); var command = PatchMemberCommandFake.DemoteMemberValid(demotedLeader.Id).Generate(); var memberRepository = MemberRepositoryMockBuilder.Create() .GetForGuildOperationsSuccess(command.Id, demotedLeader) .Update(demotedLeader, demotedLeader) .Update(expectedNewLeader, expectedNewLeader) .Build(); var sut = new DemoteMemberHandler(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(demotedLeader.Id); result.Data.As <Member>().IsGuildLeader.Should().BeFalse() .And.Be(!expectedNewLeader.IsGuildLeader); result.Data.As <Member>().GetGuild().Should().NotBeNull(); result.Data.As <Member>().GetGuild().Id.Should().Be(guild.Id); }
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); }
public GuildRepositoryMockBuilder GetByIdSuccess(Guid input, Guild output = null) { var result = output ?? GuildFake.Complete(membersCount: 3).Generate(); _mock.Setup(x => x.GetByIdAsync(input, It.IsAny <bool>(), default)).ReturnsAsync(result); return(this); }
public GuildRepositoryMockBuilder Insert(Guild input = null, Guild output = null) { var result = output ?? GuildFake.Complete().Generate(); if (input == null) { _mock.Setup(x => x.InsertAsync(It.IsAny <Guild>(), default)).ReturnsAsync(result); } else { _mock.Setup(x => x.InsertAsync(input, default)).ReturnsAsync(result); } return(this); }
public GuildRepositoryMockBuilder Update(Guild input = null, Guild output = null) { var result = output ?? GuildFake.Complete().Generate(); if (input == null) { _mock.Setup(x => x.Update(It.IsAny <Guild>())).Returns(result); } else { _mock.Setup(x => x.Update(input)).Returns(result); } return(this); }
public GuildRepositoryMockBuilder GetForMemberHandlingSuccess(Guid?input = null, Guild output = null) { var result = output ?? GuildFake.Complete(membersCount: 3).Generate(); if (input == null) { _mock.Setup(x => x.GetForMemberHandlingAsync(It.IsAny <Guid>(), default)).ReturnsAsync(result); } else { _mock.Setup(x => x.GetForMemberHandlingAsync(input.Value, default)).ReturnsAsync(result); } return(this); }
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); }
public void RemoveMember_GuildLeader_Should_Change_Guild_Members() { // arrange var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var expectedMembersCount = sut.Members.Count - 1; var expectedInvitesCount = sut.Invites.Count; var monitor = sut.Monitor(); var leader = (MemberTestProxy)sut.GetLeader(); var memberMonitor = leader.Monitor(); // act sut.RemoveMember(leader); // assert sut.Should().NotBeNull() .And.BeOfType <GuildTestProxy>(); sut.Members.Should().NotBeEmpty() .And.HaveCount(expectedMembersCount) .And.NotContain(leader); sut.Invites.Should().NotBeEmpty() .And.HaveCount(expectedInvitesCount); monitor.AssertCollectionChanged(sut.Members); monitor.AssertPropertyNotChanged( nameof(Guild.Id), nameof(Guild.Name)); monitor.AssertCollectionNotChanged(sut.Invites); leader.Should().NotBeNull() .And.BeOfType <MemberTestProxy>(); leader.IsGuildLeader.Should().BeFalse(); leader.GuildId.Should().BeNull(); leader.GetGuild().Should().BeOfType <NullGuild>(); memberMonitor.AssertPropertyChanged( nameof(Member.IsGuildLeader), nameof(Member.GuildId), nameof(Guild)); memberMonitor.AssertPropertyNotChanged( nameof(Member.Id), nameof(Member.Name)); memberMonitor.AssertCollectionNotChanged(leader.Memberships); }
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); }
public void ChangeName_WithName_Should_Change_NameOnly() { // arrange const string expectedNane = "new name"; var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var monitor = sut.Monitor(); // act sut.ChangeName(expectedNane); // assert sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>(); sut.Name.Should().NotBeEmpty().And.Be(expectedNane); monitor.AssertPropertyChanged(nameof(Guild.Name)); monitor.AssertPropertyNotChanged( nameof(Guild.Id), nameof(Guild.Members), nameof(Guild.Invites)); }
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)); }
public void InviteMember_AlreadyInGuild_Should_Change_Nothing() { // arrange var sut = (GuildTestProxy)GuildFake.Complete().Generate(); var expectedMembersCount = sut.Members.Count; var expectedInvitesCount = sut.Invites.Count; var monitor = sut.Monitor(); var member = sut.Members.First(); // act sut.InviteMember(member, TestModelFactoryHelper.Factory); // assert sut.Should().NotBeNull().And.BeOfType <GuildTestProxy>(); sut.Members.Should().NotBeEmpty().And.HaveCount(expectedMembersCount); sut.Invites.Should().NotBeEmpty().And.HaveCount(expectedMembersCount); monitor.AssertPropertyNotChanged( nameof(Guild.Id), nameof(Guild.Name)); monitor.AssertCollectionNotChanged(sut.Invites, sut.Members); }
public async Task Handle_Should_Succeed_With_ValidCommand() { // arrange const int expectedMembersCount = 3; var expectedGuild = GuildFake.Complete(membersCount: expectedMembersCount).Generate(); var command = GetGuildCommandFake.Valid(expectedGuild.Id).Generate(); var repository = GuildRepositoryMockBuilder.Create() .GetByIdSuccess(input: command.Id, output: expectedGuild).Build(); var sut = new GetGuildHandler(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 <GuildTestProxy>(); result.Data.As <Guild>().Id.Should().Be(expectedGuild.Id); result.Data.As <Guild>().GetLeader().Id.Should().Be(expectedGuild.GetLeader().Id); result.Data.As <Guild>().Members.Should().NotBeEmpty().And.HaveCount(expectedMembersCount); }
public async Task Handle_Should_Succeed_With_ValidCommand() { // arrange var expectedGuild = GuildFake.Complete().Generate(); var expectedMembersCount = expectedGuild.Members.Count; var expectedLeader = expectedGuild.GetVice(); var expectedVice = expectedGuild.GetLeader(); var command = UpdateGuildCommandFake.Valid( id: expectedGuild.Id, leaderId: expectedLeader.Id, name: expectedGuild.Name).Generate(); var guildRepository = GuildRepositoryMockBuilder.Create() .GetByIdSuccess(command.Id, expectedGuild) .Update(expectedGuild, expectedGuild).Build(); var memberRepository = MemberRepositoryMockBuilder.Create() .Update(expectedLeader, expectedLeader) .Update(expectedVice, expectedVice) .Build(); var sut = new UpdateGuildHandler(guildRepository, 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 <GuildTestProxy>(); result.Data.As <Guild>().Name.Should().Be(expectedGuild.Name); result.Data.As <Guild>().Id.Should().Be(expectedGuild.Id); result.Data.As <Guild>().GetLeader().Id.Should().Be(expectedLeader.Id); result.Data.As <Guild>().Members.Should().NotBeEmpty() .And.HaveCount(expectedMembersCount) .And.Contain(x => x.Id == expectedLeader.Id) .And.Contain(x => x.Id == expectedVice.Id); }
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); }
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); }