Beispiel #1
0
        public async Task Handle_Should_Succeed_With_ValidCommand()
        {
            // arrange
            var expectedPage     = new Random().Next(1, 5);
            var expectedPages    = new Random().Next(expectedPage, expectedPage + 1);
            var expectedPageSize = new Random().Next(5, 10);
            var command          = ListGuildCommandFake.Valid(pageSize: expectedPageSize, page: expectedPage).Generate();
            var repository       = GuildRepositoryMockBuilder.Create().Paginate(
                pageSize: command.PageSize,
                page: command.Page,
                totalItems: command.PageSize * expectedPages).Build();
            var sut = new ListGuildHandler(repository);

            // 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 <PagedResponse <Guild> >();
            result.Data.As <PagedResponse <Guild> >().Items.Should().NotBeEmpty()
            .And.AllBeAssignableTo <Guild>()
            .And.HaveCount(expectedPageSize)
            .And.HaveCount(command.PageSize);
            result.Data.As <PagedResponse <Guild> >().PageSize.Should().Be(expectedPageSize)
            .And.Be(command.PageSize);
            result.Data.As <PagedResponse <Guild> >().Page.Should().Be(expectedPage)
            .And.Be(command.Page);
            result.Data.As <PagedResponse <Guild> >().Pages.Should().Be(expectedPages);
        }
Beispiel #2
0
        public void Should_Succeed()
        {
            // arrange
            var command = ListGuildCommandFake.Valid().Generate();
            var sut     = new ListGuildValidator
            {
                CascadeMode = FluentValidation.CascadeMode.Stop
            };

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

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