public void RuleForEach_NoErrorShouldOccurWhenDCFValuesIsLowerThanNonObligatedOfSameCategoryType()
        {
            var model = new NonObligatedValuesViewModel(calculator);
            List <NonObligatedData> nonObligatedList = new List <NonObligatedData>();

            for (var count = 0; count < model.CategoryValues.Count; count++)
            {
                model.CategoryValues.ElementAt(count).Tonnage = (count + 2).ToString();
                var @decimal         = decimal.Parse(model.CategoryValues.ElementAt(count).Tonnage);
                var nonObligatedData = new NonObligatedData(model.CategoryValues.ElementAt(count).CategoryId, @decimal, model.CategoryValues.ElementAt(count).Dcf, Guid.NewGuid());
                nonObligatedList.Add(nonObligatedData);
            }
            var returnData = new ReturnData
            {
                NonObligatedData = nonObligatedList
            };

            for (var count = 0; count < model.CategoryValues.Count; count++)
            {
                model.CategoryValues.ElementAt(count).Tonnage = (count + 1).ToString();
                model.CategoryValues.ElementAt(count).Dcf     = true;
            }

            validator = new NonObligatedValuesViewModelValidator(returnData);
            ValidationResult validationResult = validator.Validate(model);

            validationResult.IsValid.Should().BeTrue();
        }
Пример #2
0
        public void NonObligatedData_PropertiesShouldBeSet(int categoryId, decimal?value, bool dcf)
        {
            var result = new NonObligatedData(categoryId, value, dcf, Guid.NewGuid());

            result.Tonnage.Should().Be(value);
            result.CategoryId.Should().Be(categoryId);
            result.Dcf.Should().Be(dcf);
        }
        public void RuleForEach_ErrorShouldOccurWhenNonObligatedValueIsLowerThanDcfValueOfSameCategoryType()
        {
            var model = new NonObligatedValuesViewModel(calculator)
            {
                Dcf = true
            };
            List <NonObligatedData> nonObligatedList = new List <NonObligatedData>();

            for (var count = 0; count < model.CategoryValues.Count; count++)
            {
                model.CategoryValues.ElementAt(count).Tonnage = (count + 2).ToString();
                var @decimal         = decimal.Parse(model.CategoryValues.ElementAt(count).Tonnage);
                var nonObligatedData = new NonObligatedData(model.CategoryValues.ElementAt(count).CategoryId, @decimal, true, Guid.NewGuid());
                nonObligatedList.Add(nonObligatedData);
            }
            var returnData = new ReturnData
            {
                NonObligatedData = nonObligatedList
            };

            for (var count = 0; count < model.CategoryValues.Count; count++)
            {
                model.CategoryValues.ElementAt(count).Tonnage = (count + 1).ToString();
                model.CategoryValues.ElementAt(count).Dcf     = false;
            }
            model.Dcf = false;

            validator = new NonObligatedValuesViewModelValidator(returnData);
            ValidationResult validationResult = validator.Validate(model);

            validationResult.IsValid.Should().BeFalse();
            validationResult.Errors.Count.Should().Be(14);
            for (var i = 0; i < validationResult.Errors.Count; i++)
            {
                var categoryId = i + 1;
                validationResult.Errors[i].ErrorMessage.Should().Be("Category " + categoryId + " tonnage must be greater than or equal to " + returnData.NonObligatedData[i].Tonnage);
                validationResult.Errors[i].PropertyName.Should().Be("CategoryValues[" + i + "].Tonnage");
            }
        }