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 = ListInviteCommandFake.Valid(expectedPageSize, expectedPage).Generate(); var repository = InviteRepositoryMockBuilder.Create().Paginate( pageSize: command.PageSize, page: command.Page, totalItems: command.PageSize * expectedPages).Build(); var sut = new ListInviteHandler(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 <Invite> >(); result.Data.As <PagedResponse <Invite> >().Items.Should().NotBeEmpty() .And.AllBeAssignableTo <Invite>() .And.HaveCount(expectedPageSize) .And.HaveCount(command.PageSize); result.Data.As <PagedResponse <Invite> >().PageSize.Should().Be(expectedPageSize) .And.Be(command.PageSize); result.Data.As <PagedResponse <Invite> >().Page.Should().Be(expectedPage) .And.Be(command.Page); result.Data.As <PagedResponse <Invite> >().Pages.Should().Be(expectedPages); }
public void Should_Fail_By_PageSize_LessThan0() { // arrange var command = ListInviteCommandFake.InvalidByPageSize().Generate(); var sut = new ListInviteValidator { CascadeMode = FluentValidation.CascadeMode.Stop }; // act var result = sut.Validate(command); // assert result.AssertErrorsCount(1); }
public void Should_Succeed() { // arrange var command = ListInviteCommandFake.Valid().Generate(); var sut = new ListInviteValidator { CascadeMode = FluentValidation.CascadeMode.Stop }; // act var result = sut.Validate(command); // assert result.Should().NotBeNull() .And.BeOfType <ValidationResult>(); result.IsValid.Should().BeTrue(); }