Exemplo n.º 1
0
        public async Task Validate_WithCorrectOrderByClause_ShouldNotReturnValidationResult(string orderBy)
        {
            // Arrange
            RequestHandlerDelegate <OperationResult <List <WebsiteOutputModel> > > requestHandlerDelegate = () => Task.FromResult(OperationResult <List <WebsiteOutputModel> > .Success(null));

            // Act
            var query = new Application.Websites.Queries.GetWebsites.GetWebsites {
                PageNumber = 1, PageSize = 10, OrderBy = orderBy
            };
            var validationResult = await _validator.Handle(query, CancellationToken.None, requestHandlerDelegate);

            // Assert
            validationResult.IsSuccessful.Should().BeTrue();
        }
Exemplo n.º 2
0
        public async Task Validate_WithIncorrectOrderByClause_ShouldReturnValidationResult(string orderBy)
        {
            // Arrange
            RequestHandlerDelegate <OperationResult <List <WebsiteOutputModel> > > requestHandlerDelegate = () => Task.FromResult(OperationResult <List <WebsiteOutputModel> > .Success(null));

            // Act
            var query = new Application.Websites.Queries.GetWebsites.GetWebsites {
                PageNumber = 1, PageSize = 10, OrderBy = orderBy
            };
            var validationResult = await _validator.Handle(query, CancellationToken.None, requestHandlerDelegate);

            // Assert
            validationResult.IsSuccessful.Should().BeFalse();
            validationResult.Errors.Count.Should().Be(1);
            validationResult.Errors.First().Key.Should().Be("OrderBy");
            validationResult.Errors.First().Value.Should().Be("Invalid OrderBy clause");
        }
Exemplo n.º 3
0
        public async Task GetAsync_WithCorrectQuery_ShouldReturnSuccessResult()
        {
            // Arrange
            _repositoryMock.Setup(x => x.GetAll(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync(new List <Website>());

            var handler = new GetWebsitesHandler(_repositoryMock.Object, _cypherMock.Object);

            // Act
            var query = new Application.Websites.Queries.GetWebsites.GetWebsites {
                PageNumber = 1, PageSize = 10, OrderBy = "name desc"
            };

            OperationResult <List <WebsiteOutputModel> > operationResult = await handler.Handle(query, CancellationToken.None);

            // Assert
            operationResult.Should().BeOfType(typeof(OperationResult <List <WebsiteOutputModel> >));
            operationResult.IsSuccessful.Should().BeTrue();
            operationResult.Result.Should().NotBeNull();

            _repositoryMock.Verify(x => x.GetAll(It.Is <int>(x => x == 1),
                                                 It.Is <int>(x => x == 10),
                                                 It.Is <string>(x => x == "name desc")));
        }