Пример #1
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedMember = MemberFake.WithoutGuild().Generate();
            var command        = PatchMemberCommandFake.ChangeMemberNameValid(
                id: expectedMember.Id,
                name: expectedMember.Name).Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .GetByIdSuccess(command.Id, expectedMember)
                                   .Update(expectedMember, expectedMember)
                                   .Build();
            var sut = new ChangeMemberNameHandler(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>().Name.Should().Be(expectedMember.Name);
            result.Data.As <Member>().Id.Should().Be(expectedMember.Id);
        }
Пример #2
0
        public void Should_Fail_By_Member_NotFound()
        {
            // arrange
            var command          = PatchMemberCommandFake.ChangeMemberNameValid().Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithId(false, command.Id)
                                   .CanChangeName(true, command.Id, command.Name).Build();

            var sut = new ChangeMemberNameValidator(memberRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

            // assert
            result.AssertErrorsCount(1);
        }
Пример #3
0
        public void Should_Succeed()
        {
            // arrange
            var command          = PatchMemberCommandFake.ChangeMemberNameValid().Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithId(true, command.Id)
                                   .CanChangeName(true, command.Id, command.Name).Build();

            var sut = new ChangeMemberNameValidator(memberRepository)
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

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