示例#1
0
        public void Shoul_Not_Create_New_Measure_With_Name_Is_Null()
        {
            var domainException = Assert.Throws <DomainException>(() => Measure.New(null, _status, _tenantId));
            var domainError     = domainException.Errors.First();

            var fieldName = ResourcesReader.Field(nameof(_measure.Name));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
示例#2
0
        public void Shoul_Not_Create_New_Color_With_Name_Is_EmptySpace()
        {
            var domainException = Assert.Throws <DomainException>(() => Color.New(" ", _status, _tenantId));

            var domainError = domainException.Errors.First();
            var fieldName   = ResourcesReader.Field(nameof(_color.Name));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
示例#3
0
        public void Shoul_Not_Create_New_Feedstock_With_Name_Is_Empty()
        {
            var domainException = Assert.Throws <DomainException>(() => Domain.Entities.Feedstock.New("", _status, _measureId, _stock, _colorId, _tenantId));
            var domainError     = domainException.Errors.First();

            var fieldName = ResourcesReader.Field(nameof(_feedstock.Name));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
示例#4
0
        public void Should_Not_Be_Valid_When_ColorId_Is_Null()
        {
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Domain.Entities.Feedstock.New(_feedstockId, _feedstockName, _status, _creationDate, _updateDate, _measureId, _stock, null, _tenantId));
            var domainError = domainException.Errors.First();
            var fieldName   = ResourcesReader.Field(nameof(_feedstock.ColorId));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.NotNull(fieldName), domainError.Messages.First());
        }
示例#5
0
        public void Should_Not_Be_Valid_When_ColorId_Is_Empty()
        {
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Color.New(ColorId.Empty, _colorName, _status, _creationDate, _updateDate, _tenantId));

            var domainError = domainException.Errors.First();
            var fieldName   = ResourcesReader.Field(nameof(_color.ColorId));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
示例#6
0
        public void Should_Not_Be_Valid_When_TenantId_Is_Nully()
        {
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Measure.New(_measureId, _measureName, _status, _creationDate, _updateDate, null));
            var domainError = domainException.Errors.First();

            var fieldName = ResourcesReader.Field(nameof(_measure.TenantId));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.NotNull(fieldName), domainError.Messages.First());
        }
示例#7
0
        public void Should_Not_Be_Valid_When_Name_Has_More_Than_200_Chars()
        {
            var name            = @"01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        0123456789";
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Domain.Entities.Feedstock.New(name, _status, _measureId, _stock, _colorId, _tenantId));
            var domainError = domainException.Errors.First();
            var fieldName   = ResourcesReader.Field(nameof(_feedstock.Name));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.MaxLength(fieldName, 200), domainError.Messages.First());
        }
示例#8
0
        public void Should_Not_Be_Valid_When_Name_Has_More_Than_200_Chars()
        {
            var name = @"01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        01234567890123456789012345678901234567890123456789
                        0123456789";

            var color = Color.New(_colorName, _status, _tenantId);

            color.ChangeName(name);

            Assert.NotNull(color);

            var fieldName   = ResourcesReader.Field(nameof(color.Name));
            var domainError = GetDomainExceptionError(color);

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.MaxLength(fieldName, 200), domainError.Messages.First());
        }
示例#9
0
        /// <summary>
        /// Checks if the object is valid.
        /// </summary>
        /// <returns>Returns boolean value to express the status.</returns>
        public bool Isvalid()
        {
            var validator = Validator <Feedstock> .New();

            validator.RuleFor(x => x.Name, ResourcesReader.Field(nameof(Name)))
            .Required()
            .MaxLength(200);

            validator.RuleFor(x => x.MeasureId, ResourcesReader.Field(nameof(MeasureId)))
            .NotNull();

            validator.RuleFor(x => x.MeasureId.Value, ResourcesReader.Field(nameof(MeasureId)))
            .Required()
            .When(x => x.MeasureId != null);

            validator.RuleFor(x => x.TenantId, ResourcesReader.Field(nameof(TenantId)))
            .NotNull();

            validator.RuleFor(x => x.TenantId.Value, ResourcesReader.Field(nameof(TenantId)))
            .Required()
            .When(x => x.TenantId != null);

            validator.RuleFor(x => x.FeedstockId, ResourcesReader.Field(nameof(FeedstockId)))
            .NotNull();

            validator.RuleFor(x => x.FeedstockId.Value, ResourcesReader.Field(nameof(FeedstockId)))
            .Required()
            .When(x => x.FeedstockId != null);

            validator.RuleFor(x => x.ColorId, ResourcesReader.Field(nameof(ColorId)))
            .NotNull();

            validator.RuleFor(x => x.ColorId.Value, ResourcesReader.Field(nameof(ColorId)))
            .Required()
            .When(x => x.ColorId != null);

            return(validator.Validate(this).IsValid);
        }