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

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

            var damageCodeReadRepositoryMock = new Mock <IDamageCodeReadRepository>();

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

            var damageCodeOdataProviderMock = new Mock <IDamageCodeOdataProvider>();

            damageCodeOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <DamageCode, bool> >)null);
            var damageCodeOdataProvider = damageCodeOdataProviderMock.Object;

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

            var handler = new ListDamageCodeQueryHandler(mapper, damageCodeReadRepository, damageCodeOdataProvider);

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

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

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

            var damageCodeReadRepositoryMock = new Mock <IDamageCodeReadRepository>();

            damageCodeReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <DamageCode, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var damageCodeReadRepository = damageCodeReadRepositoryMock.Object;

            var damageCodeOdataProviderMock = new Mock <IDamageCodeOdataProvider>();

            damageCodeOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <DamageCode, bool> >)null);
            var damageCodeOdataProvider = damageCodeOdataProviderMock.Object;

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

            var handler = new ListDamageCodeQueryHandler(mapper, damageCodeReadRepository, damageCodeOdataProvider);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListDamageCodeFailure);
        }
Пример #3
0
        public ListDamageCodeQuery Map(ListDamageCodeRequest request)
        {
            var filter = request.Filter;
            var top    = request.Top;
            var skip   = request.Skip;

            var result = new ListDamageCodeQuery(filter, top, skip);

            return(result);
        }
Пример #4
0
        public void ShouldContainNoTopErrorWhenTopIsNotSet(string top)
        {
            // Arrange
            string filter = null;
            string skip   = null;

            var query = new ListDamageCodeQuery(filter, top, skip);

            // Act
            var validationResult = _validator.Validate(query);
            var exists           = validationResult.Errors.Any(a => a.PropertyName.Equals("$top"));

            // Assert
            exists.Should().BeFalse();
        }
Пример #5
0
        public void ShouldContainNoErrors()
        {
            // Arrange
            string filter = null;
            string top    = null;
            string skip   = null;
            var    query  = new ListDamageCodeQuery(filter, top, skip);

            // Act
            var validationResult = _validator.Validate(query);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
Пример #6
0
        public void ShouldHaveTopInvalidCustomFailureWhenTopInvalid(string top)
        {
            // Arrange
            string filter = null;
            string skip   = null;

            var query = new ListDamageCodeQuery(filter, top, skip);

            // Act
            var validationResult = _validator.Validate(query);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("$top") && a.ErrorMessage.Contains(CustomFailures.TopInvalid));

            // Assert
            exists.Should().BeTrue();
        }
Пример #7
0
        public void ShouldHaveSkipRangeCustomFailure(string skip)
        {
            // Arrange
            string filter = null;
            string top    = null;

            var query = new ListDamageCodeQuery(filter, top, skip);

            // Act
            var validationResult = _validator.Validate(query);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("$skip") && a.ErrorMessage.Contains(string.Format(CustomFailures.SkipRange, Consts.CqsValidation.SkipMaxValue)));

            // Assert
            exists.Should().BeTrue();
        }