Beispiel #1
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());
        }
Beispiel #2
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());
        }
Beispiel #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());
        }
Beispiel #4
0
        public void Should_Not_Be_Valid_When_ColorId_Is_Empty()
        {
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Domain.Entities.Feedstock.New(_feedstockId, _feedstockName, _status, _creationDate, _updateDate, _measureId, _stock, ColorId.Empty, _tenantId));
            var domainError = domainException.Errors.First();
            var fieldName   = ResourcesReader.Field(nameof(_feedstock.ColorId));

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
Beispiel #5
0
        public void Should_Not_Be_Valid_When_TenantId_Is_Empty()
        {
            var domainException = Assert.Throws <DomainException>(() =>
                                                                  Color.New(_colorId, _colorName, _status, _creationDate, _updateDate, TenantId.Empty));

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

            Assert.Equal(fieldName, domainError.Property);
            Assert.Equal(ValidationMessage.Required(fieldName), domainError.Messages.First());
        }
Beispiel #6
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            var isInvalid = false;
            var message   = ValidationMessage.Required(fieldName);

            if (fieldValue is null)
            {
                isInvalid = true;
            }
            else
            {
                switch (fieldValue.GetType())
                {
                case Type x when x == typeof(string):
                    if (string.IsNullOrWhiteSpace(fieldValue))
                    {
                        isInvalid = true;
                    }
                    break;

                case Type a when a == typeof(int?):
                case Type b when b == typeof(uint?):
                case Type c when c == typeof(long?):
                case Type d when d == typeof(ulong?):
                case Type e when e == typeof(short?):
                case Type f when f == typeof(ushort?):
                case Type g when g == typeof(double?):
                case Type h when h == typeof(decimal?):
                case Type i when i == typeof(byte?):
                case Type j when j == typeof(sbyte?):
                case Type k when k == typeof(char?):
                case Type l when l == typeof(bool?):
                    if (fieldValue == null)
                    {
                        isInvalid = true;
                    }
                    break;

                case Type x when(x == typeof(Guid) || x == typeof(Guid?)):
                    if (fieldValue == Guid.Empty || fieldValue == null)
                    {
                        isInvalid = true;
                    }

                    break;

                case Type x when x == typeof(int):
                    isInvalid = (int)fieldValue == default;
                    break;

                case Type x when x == typeof(uint):
                    isInvalid = (uint)fieldValue == default;
                    break;

                case Type x when x == typeof(long):
                    isInvalid = (long)fieldValue == default;
                    break;

                case Type x when x == typeof(ulong):
                    isInvalid = (ulong)fieldValue == default;
                    break;

                case Type x when x == typeof(short):
                    isInvalid = (short)fieldValue == default;
                    break;

                case Type x when x == typeof(ushort):
                    isInvalid = (ushort)fieldValue == default;
                    break;

                case Type x when x == typeof(double):
                    isInvalid = (double)fieldValue == default;
                    break;

                case Type x when x == typeof(decimal):
                    isInvalid = (decimal)fieldValue == default;
                    break;

                case Type x when x == typeof(byte):
                    isInvalid = (byte)fieldValue == default;
                    break;

                case Type x when x == typeof(sbyte):
                    isInvalid = (sbyte)fieldValue == default;
                    break;

                case Type x when x == typeof(char):
                    isInvalid = (char)fieldValue == default;
                    break;

                case Type x when x == typeof(bool):
                    isInvalid = (bool)fieldValue == default;
                    break;
                }
            }

            if (isInvalid)
            {
                _roleBuilder.AddErrorMessage(fieldName, message);
            }
        }