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

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

            var iconReadRepositoryMock = new Mock <IIconReadRepository>();

            iconReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Icon, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var iconReadRepository = iconReadRepositoryMock.Object;

            var iconOdataProviderMock = new Mock <IIconOdataProvider>();

            iconOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Icon, bool> >)null);
            var iconOdataProvider = iconOdataProviderMock.Object;

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

            var handler = new ListIconQueryHandler(mapper, iconReadRepository, iconOdataProvider);

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

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

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

            var iconReadRepositoryMock = new Mock <IIconReadRepository>();

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

            var iconOdataProviderMock = new Mock <IIconOdataProvider>();

            iconOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Icon, bool> >)null);
            var iconOdataProvider = iconOdataProviderMock.Object;

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

            var handler = new ListIconQueryHandler(mapper, iconReadRepository, iconOdataProvider);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <IconsModel>));
        }
        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 iconReadRepositoryMock = new Mock <IIconReadRepository>();

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

            var iconOdataProviderMock = new Mock <IIconOdataProvider>();

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

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

            var handler = new ListIconQueryHandler(mapper, iconReadRepository, iconOdataProvider);

            // 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");
        }