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