예제 #1
0
        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);
        }
예제 #2
0
        public void Should_Fail_By_Empty_MemberId()
        {
            // arrange
            var command          = InviteMemberCommandFake.InvalidByEmptyMemberId().Generate();
            var guildRepository  = GuildRepositoryMockBuilder.Create().Build();
            var memberRepository = MemberRepositoryMockBuilder.Create().Build();

            var sut = new InviteMemberValidator(memberRepository, guildRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
예제 #3
0
        public void Should_Fail_By_Guild_ExistsWithId_False()
        {
            // arrange
            var command         = InviteMemberCommandFake.Valid().Generate();
            var guildRepository = GuildRepositoryMockBuilder.Create()
                                  .ExistsWithId(false, command.GuildId).Build();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithId(true, command.MemberId)
                                   .IsGuildMember(false, command.MemberId, command.GuildId)
                                   .Build();

            var sut = new InviteMemberValidator(memberRepository, guildRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.AssertErrorsCount(1);
        }
예제 #4
0
        public void Should_Succeed()
        {
            // arrange
            var command         = InviteMemberCommandFake.Valid().Generate();
            var guildRepository = GuildRepositoryMockBuilder.Create()
                                  .ExistsWithId(true, command.GuildId).Build();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithId(true, command.MemberId)
                                   .IsGuildMember(false, command.MemberId, command.GuildId)
                                   .Build();

            var sut = new InviteMemberValidator(memberRepository, guildRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

            // act
            var result = sut.Validate(command);

            // assert
            result.Should().NotBeNull().And.BeOfType <ValidationResult>();
            result.IsValid.Should().BeTrue();
        }