Exemplo n.º 1
0
        public void ValidationRulesUtilities_behave_as_expected()
        {
            //arrange
            ValidationRules validationRules = ValidationRulesUtility.GetRules();
            var             presidentialNameValidationRule  = new Regex(validationRules.PresidentialNameValidationRule);
            var             presidentialPartyValidationRule = new Regex(validationRules.PresidentialPartyValidationRule);
            var             deadMouse           = "deadmau5";
            var             joelThomasZimmerman = "Joel Thomas Zimmerman";
            var             misterZimmerman     = "Mr. Zimmerman";

            //act
            Match deadMouseNameMatch            = presidentialNameValidationRule.Match(deadMouse);
            Match deadMousePartyMatch           = presidentialPartyValidationRule.Match(deadMouse);
            Match joelThomasZimmermanNameMatch  = presidentialNameValidationRule.Match(joelThomasZimmerman);
            Match joelThomasZimmermanPartyMatch = presidentialPartyValidationRule.Match(joelThomasZimmerman);
            Match misterZimmermanNameMatch      = presidentialNameValidationRule.Match(misterZimmerman);
            Match misterZimmermanPartyMatch     = presidentialPartyValidationRule.Match(misterZimmerman);

            //assert
            Assert.Equal(deadMouseNameMatch.Success, false);
            Assert.Equal(deadMousePartyMatch.Success, false);
            Assert.Equal(joelThomasZimmermanNameMatch.Success, true);
            Assert.Equal(joelThomasZimmermanPartyMatch.Success, true);
            Assert.Equal(misterZimmermanNameMatch.Success, true);
            Assert.Equal(misterZimmermanPartyMatch.Success, false);
        }
Exemplo n.º 2
0
        public President Post([FromBody] President president)
        {
            List <President> presidents = _flatFileMechanics.GetPresidents();

            ValidationRulesUtility.ValidateName(presidents, president.Name);
            ValidationRulesUtility.ValidateParty(president.Party);
            presidents.Add(president);
            _flatFileMechanics.SetPresidents(presidents);
            return(president);
        }
Exemplo n.º 3
0
        public void ValidationRulesUtilities_disallows_empty_strings_when_applicable()
        {
            //arrange
            ValidationRules validationRules = ValidationRulesUtility.GetRules();
            var             presidentialNameValidationRule  = new Regex(validationRules.PresidentialNameValidationRule);
            var             presidentialPartyValidationRule = new Regex(validationRules.PresidentialPartyValidationRule);
            var             deadAir = "";

            //act
            Match deadAirNameMatch  = presidentialNameValidationRule.Match(deadAir);
            Match deadAirPartyMatch = presidentialPartyValidationRule.Match(deadAir);

            //assert
            Assert.Equal(deadAirNameMatch.Success, false);
            Assert.Equal(deadAirPartyMatch.Success, true);
        }
Exemplo n.º 4
0
        public void Put(string id, [FromBody] President president)
        {
            List <President> presidents = _flatFileMechanics.GetPresidents();

            ValidationRulesUtility.ValidateName(presidents, president.Name, id);
            ValidationRulesUtility.ValidateParty(president.Party);
            presidents.ForEach(p =>
            {
                if (id == p.Name)
                {
                    p.Name  = president.Name;
                    p.Party = president.Party;
                    p.HasNonconsecutiveTerms = president.HasNonconsecutiveTerms;
                }
            });
            _flatFileMechanics.SetPresidents(presidents);
        }
Exemplo n.º 5
0
 public ValidationRules Get()
 {
     return(ValidationRulesUtility.GetRules());
 }
Exemplo n.º 6
0
 public void Put([FromBody] List <President> presidents)
 {
     ValidationRulesUtility.ValidatePresidents(presidents);
     _flatFileMechanics.SetPresidents(presidents);
 }