Example #1
0
        public void TestOrg2Code_NotOtherOrgCode_NotRequiredCodeLength()
        {
            string amount1    = null;
            string org1       = null;
            string otherName1 = null;
            string amount2    = null;
            string org2       = null;
            string otherName2 = null;
            Func <USGovernmentFunding> createEntity = () =>
            {
                return(new USGovernmentFunding(
                           org1: org1,
                           otherName1: otherName1,
                           amount1: amount1,
                           org2: org2,
                           otherName2: otherName2,
                           amount2: amount2
                           ));
            };
            var validator = new USGovernmentFundingValidator();

            org1    = new string('a', USGovernmentFundingValidator.ORG_CODE_MAX_LENGTH);
            amount1 = "1";
            org2    = new string('a', USGovernmentFundingValidator.ORG_CODE_MAX_LENGTH);
            amount2 = "1";
            var instance = createEntity();
            var result   = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            org2     = String.Empty;
            instance = createEntity();
            result   = validator.Validate(instance);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(USGovernmentFundingValidator.ORG_2_CODE_NOT_SPECIFIED_ERROR_MESSAGE, result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(FundingErrorPath));

            org2     = new string('a', USGovernmentFundingValidator.ORG_CODE_MAX_LENGTH + 1);
            instance = createEntity();
            result   = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(USGovernmentFundingValidator.ORG_2_CODE_NOT_SPECIFIED_ERROR_MESSAGE, result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(FundingErrorPath));
        }
Example #2
0
        public void TestOrg2Code_IsOtherOrgCode_OtherNameNull()
        {
            string amount1    = null;
            string org1       = null;
            string otherName1 = null;
            string amount2    = null;
            string org2       = null;
            string otherName2 = null;
            Func <USGovernmentFunding> createEntity = () =>
            {
                return(new USGovernmentFunding(
                           org1: org1,
                           otherName1: otherName1,
                           amount1: amount1,
                           org2: org2,
                           otherName2: otherName2,
                           amount2: amount2
                           ));
            };
            var validator = new USGovernmentFundingValidator();


            org1       = USGovernmentFundingValidator.OTHER_ORG_CODE;
            amount1    = "1";
            otherName1 = new string('a', USGovernmentFundingValidator.OTHER_ORG_NAME_MAX_LENGTH);


            org2       = USGovernmentFundingValidator.OTHER_ORG_CODE;
            amount2    = "1";
            otherName2 = new string('a', USGovernmentFundingValidator.OTHER_ORG_NAME_MAX_LENGTH);

            var instance = createEntity();
            var result   = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            otherName2 = null;
            instance   = createEntity();
            result     = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(USGovernmentFundingValidator.OTHER_ORG_2_NAME_REQUIRED, result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(FundingErrorPath));
        }
Example #3
0
        public void TestAmount2NotNull_Org2IsNull()
        {
            string amount1    = null;
            string org1       = null;
            string otherName1 = null;
            string amount2    = null;
            string org2       = null;
            string otherName2 = null;
            Func <USGovernmentFunding> createEntity = () =>
            {
                return(new USGovernmentFunding(
                           org1: org1,
                           otherName1: otherName1,
                           amount1: amount1,
                           org2: org2,
                           otherName2: otherName2,
                           amount2: amount2
                           ));
            };
            var validator = new USGovernmentFundingValidator();

            org1    = "abc";
            amount1 = "1";

            org2    = "xyz";
            amount2 = "2";
            var instance = createEntity();
            var result   = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            org2     = null;
            instance = createEntity();
            result   = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(USGovernmentFundingValidator.ORG_2_CODE_NOT_SPECIFIED_ERROR_MESSAGE, result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(FundingErrorPath));
        }
Example #4
0
        public void TestAmount2_OtherName2IsNotNull()
        {
            string amount1    = null;
            string org1       = null;
            string otherName1 = null;
            string amount2    = null;
            string org2       = null;
            string otherName2 = null;
            Func <USGovernmentFunding> createEntity = () =>
            {
                return(new USGovernmentFunding(
                           org1: org1,
                           otherName1: otherName1,
                           amount1: amount1,
                           org2: org2,
                           otherName2: otherName2,
                           amount2: amount2
                           ));
            };
            var validator = new USGovernmentFundingValidator();

            org1    = "abc";
            amount1 = "1";
            org2    = null;
            amount2 = null;
            var instance = createEntity();
            var result   = validator.Validate(instance);

            Assert.IsTrue(result.IsValid);

            org2       = USGovernmentFundingValidator.OTHER_ORG_CODE;
            otherName2 = "a";
            instance   = createEntity();
            result     = validator.Validate(instance);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(String.Format(USGovernmentFundingValidator.AMOUNT_ERROR_MESSAGE, "2", USGovernmentFundingValidator.AMOUNT_MAX_LENGTH), result.Errors.First().ErrorMessage);
            Assert.IsInstanceOfType(result.Errors.First().CustomState, typeof(FundingErrorPath));
        }