예제 #1
0
        public void Should_Fail_By_Empty_Name()
        {
            // arrange
            var command          = CreateMemberCommandFake.InvalidByEmptyName().Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create().Build();

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

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

            // assert
            result.AssertErrorsCount(1);
        }
예제 #2
0
        public void Should_Fail_By_Member_ExistsWithName_True()
        {
            // arrange
            var command          = CreateMemberCommandFake.Valid().Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithName(true, command.Name).Build();

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

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

            // assert
            result.AssertErrorsCount(1);
        }
예제 #3
0
        public void Should_Succeed()
        {
            // arrange
            var command          = CreateMemberCommandFake.Valid().Generate();
            var memberRepository = MemberRepositoryMockBuilder.Create()
                                   .ExistsWithName(false, command.Name).Build();

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

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

            // assert
            result.Should().NotBeNull().And.BeOfType <ValidationResult>();
            result.IsValid.Should().BeTrue();
        }
예제 #4
0
        public async Task Handle_Should_Succeed_With_ValidCommandAsync()
        {
            // arrange
            var command        = CreateMemberCommandFake.Valid().Generate();
            var expectedMember = MemberFake.WithoutGuild(command.Name).Generate();
            var repository     = MemberRepositoryMockBuilder.Create().Insert(command.Name, expectedMember).Build();
            var factory        = ModelFactoryMockBuilder.Create().CreateMember(command.Name, expectedMember).Build();
            var sut            = new CreateMemberHandler(repository, factory);

            // act
            var response = await sut.Handle(command, default);

            // assert
            response.Should().NotBeNull().And.BeOfType <SuccessCreatedResult>();
            response.Success.Should().BeTrue();
            response.Errors.Should().BeEmpty();
            response.As <SuccessCreatedResult>().StatusCode.Should().Be(StatusCodes.Status201Created);
            response.Data.Should().NotBeNull().And.BeOfType <MemberTestProxy>();
            response.Data.As <Member>().Should().Be(expectedMember);
        }