public void Should_Succeed() { // arrange var command = UpdateGuildCommandFake.Valid().Generate(); var guildRepository = GuildRepositoryMockBuilder.Create() .ExistsWithId(true, command.Id) .CanChangeName(true, command.Id, command.Name) .Build(); var memberRepository = MemberRepositoryMockBuilder.Create() .ExistsWithId(true, command.LeaderId) .IsGuildMember(true, command.LeaderId, command.Id) .Build(); var sut = new UpdateGuildValidator(guildRepository, memberRepository) { CascadeMode = FluentValidation.CascadeMode.Stop }; // act var result = sut.Validate(command); // assert result.Should().NotBeNull().And.BeOfType <ValidationResult>(); result.IsValid.Should().BeTrue(); }
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 Should_Fail_By_IsGuildMember_False() { // arrange var command = UpdateGuildCommandFake.Valid().Generate(); var guildRepository = GuildRepositoryMockBuilder.Create() .ExistsWithId(true, command.Id) .CanChangeName(true, command.Id, command.Name) .Build(); var memberRepository = MemberRepositoryMockBuilder.Create() .ExistsWithId(true, command.LeaderId) .IsGuildMember(false, command.LeaderId, command.Id) .Build(); var sut = new UpdateGuildValidator(guildRepository, memberRepository) { CascadeMode = FluentValidation.CascadeMode.Stop }; // act var result = sut.Validate(command); // assert result.AssertErrorsCount(1); }