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