コード例 #1
0
        public void CheckFormatShouldReturnFalse(string dateTimeIso8601)
        {
            // Arrange
            IDateTimeProvider dateTimeProvider = new DateTimeProvider();

            // Act
            var result = dateTimeProvider.CheckFormat(dateTimeIso8601);

            // Assert
            result.Should().BeFalse();
        }
コード例 #2
0
        public void CheckFormatShouldFail(string dateTimeIso8601)
        {
            // Arrange
            IDateTimeProvider dateTimeProvider = new DateTimeProvider();


            // Act
            Action action = () => { dateTimeProvider.CheckFormat(dateTimeIso8601); };

            // Assert
            action.Should().Throw <Exception>();
        }
コード例 #3
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            var result   = true;
            var pictures = (Optional <IEnumerable <PictureDto> >)context.PropertyValue;

            if (pictures.HasValue && pictures.Value != null && pictures.Value.Any())
            {
                var index = 0;
                foreach (var picture in pictures.Value)
                {
                    if (picture != null)
                    {
                        var dateTimeProvider = new DateTimeProvider();
                        var resultDateTime   = dateTimeProvider.Parse(picture.CreatedOn);
                        if (resultDateTime.HasValue)
                        {
                            var validIso = dateTimeProvider.CheckFormat(picture.CreatedOn);
                            if (validIso)
                            {
                                try
                                {
                                    new CreatedOn(resultDateTime.Value);
                                }
                                catch
                                {
                                    result = false;
                                    context.MessageFormatter.AppendArgument("Key", nameof(picture.CreatedOn));
                                    context.MessageFormatter.AppendArgument("Index", index);
                                }
                            }
                            else
                            {
                                result = false;
                                context.MessageFormatter.AppendArgument("Index", index);
                                context.MessageFormatter.AppendArgument("Key", nameof(picture.CreatedOn));
                            }
                        }
                        else
                        {
                            result = false;
                            context.MessageFormatter.AppendArgument("Key", nameof(picture.CreatedOn));
                            context.MessageFormatter.AppendArgument("Index", index);
                        }
                    }

                    index++;
                }
            }

            return(result);
        }
コード例 #4
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            var result       = true;
            var handledUnits = (Optional <IEnumerable <HandledUnitDto> >)context.PropertyValue;

            if (handledUnits.HasValue && handledUnits.Value != null && handledUnits.Value.Any())
            {
                var index = 0;
                foreach (var handledUnit in handledUnits.Value)
                {
                    if (handledUnit != null && handledUnit.Products != null && handledUnit.Products.Any())
                    {
                        var indexProduct = 0;
                        foreach (var product in handledUnit.Products)
                        {
                            if (product != null)
                            {
                                var dateTimeProvider = new DateTimeProvider();
                                var resultDateTime   = dateTimeProvider.Parse(product.DateFifo);

                                if (resultDateTime.HasValue)
                                {
                                    var validIso = dateTimeProvider.CheckFormat(product.DateFifo);
                                    if (validIso)
                                    {
                                        try
                                        {
                                            new DateOn(resultDateTime.Value);
                                        }
                                        catch
                                        {
                                            result = false;
                                            context.MessageFormatter.AppendArgument("Index", index);
                                            context.MessageFormatter.AppendArgument("IndexProduct", indexProduct);
                                            context.MessageFormatter.AppendArgument("Key", nameof(product.DateFifo));
                                        }
                                    }
                                    else
                                    {
                                        result = false;
                                        context.MessageFormatter.AppendArgument("Index", index);
                                        context.MessageFormatter.AppendArgument("IndexProduct", indexProduct);
                                        context.MessageFormatter.AppendArgument("Key", nameof(product.DateFifo));
                                    }
                                }
                                else
                                {
                                    if (product.DateFifo != null)
                                    {
                                        result = false;
                                        context.MessageFormatter.AppendArgument("Index", index);
                                        context.MessageFormatter.AppendArgument("IndexProduct", indexProduct);
                                        context.MessageFormatter.AppendArgument("Key", nameof(product.DateFifo));
                                    }
                                }
                            }

                            indexProduct++;
                        }
                    }

                    index++;
                }
            }

            return(result);
        }