public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <SourceModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <SourceModel>());
            var mapper = mapperMock.Object;

            var sourceReadRepositoryMock = new Mock <ISourceReadRepository>();

            sourceReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Source, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var sourceReadRepository = sourceReadRepositoryMock.Object;

            var sourceOdataProviderMock = new Mock <ISourceOdataProvider>();

            sourceOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Source, bool> >)null);
            var sourceOdataProvider = sourceOdataProviderMock.Object;


            var query = new ListSourceQuery(null, null, null);

            var handler = new ListSourceQueryHandler(mapper, sourceReadRepository, sourceOdataProvider);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListSourceFailure);
        }
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <SourceModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <SourceModel>());
            var mapper = mapperMock.Object;

            var sourceReadRepositoryMock = new Mock <ISourceReadRepository>();

            sourceReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Source, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Source>()));
            var sourceReadRepository = sourceReadRepositoryMock.Object;

            var sourceOdataProviderMock = new Mock <ISourceOdataProvider>();

            sourceOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Source, bool> >)null);
            var sourceOdataProvider = sourceOdataProviderMock.Object;

            var query = new ListSourceQuery(null, null, null);

            var handler = new ListSourceQueryHandler(mapper, sourceReadRepository, sourceOdataProvider);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <SourcesModel>));
        }
        public async Task HandleShouldReturnFailWhenFilterOdataErrorOccurs()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <FlowModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <FlowModel>());
            var mapper = mapperMock.Object;

            var sourceReadRepositoryMock = new Mock <ISourceReadRepository>();

            sourceReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Source, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Source>()));
            var sourceReadRepository = sourceReadRepositoryMock.Object;

            var sourceOdataProviderMock = new Mock <ISourceOdataProvider>();

            sourceOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Throws <FilterODataException>();
            var sourceOdataProvider = sourceOdataProviderMock.Object;

            var query = new ListSourceQuery(null, null, null);

            var handler = new ListSourceQueryHandler(mapper, sourceReadRepository, sourceOdataProvider);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.InvalidQueryFilter.Name &&
                                                 x.Message == HandlerFailures.InvalidQueryFilter &&
                                                 x.Target == "$filter");
        }