public void ShouldContainNoTopErrorWhenTopIsNotSet(string top)
        {
            // Arrange
            string filter = null;
            string skip   = null;

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

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

            // Assert
            exists.Should().BeFalse();
        }
        public void ShouldContainNoErrors()
        {
            // Arrange
            string filter = null;
            string top    = null;
            string skip   = null;
            var    query  = new ListChecklistQuery(filter, top, skip);

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

            // Assert
            exists.Should().BeFalse();
        }
        public void ShouldHaveTopInvalidCustomFailureWhenTopInvalid(string top)
        {
            // Arrange
            string filter = null;
            string skip   = null;

            var query = new ListChecklistQuery(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();
        }
        public void ShouldHaveSkipRangeCustomFailure(string skip)
        {
            // Arrange
            string filter = null;
            string top    = null;

            var query = new ListChecklistQuery(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();
        }
Beispiel #5
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var checklistReadRepositoryMock = new Mock <IChecklistReadRepository>();

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

            var mapperMock = new Mock <IMapper>();

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

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

            var handler = new ListChecklistQueryHandler(mapper, checklistReadRepository);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <ChecklistsModel>));
        }
Beispiel #6
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var checklistReadRepositoryMock = new Mock <IChecklistReadRepository>();

            checklistReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Checklist, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var checklistReadRepository = checklistReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

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

            var handler = new ListChecklistQueryHandler(mapper, checklistReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListChecklistFailure);
        }