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); }
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 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); }
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); }