Beispiel #1
0
 public void ValidHotDressSequences(InputDressCodeSequence input)
 {
     foreach (var validation in _hotDressValidations)
     {
         validation.Validate(input);
     }
 }
 public void Validate(InputDressCodeSequence input)
 {
     if (input?.Commands[0].CommandKey != _removePyjamaCommand)
     {
         foreach (var command in input?.Commands)
         {
             command.IsInvalid = true;
             return;
         }
     }
 }
        public void Validate(InputDressCodeSequence input)
        {
            foreach (var command in input.Commands)
            {
                if (_invalidCommands.Contains(command.CommandKey))
                {
                    command.IsInvalid = true;
                    return;
                }
            }

            return;
        }
Beispiel #4
0
        public void Validate(InputDressCodeSequence input)
        {
            var checkList = new List <int>();

            foreach (var command in input.Commands)
            {
                checkList.Add(command.CommandKey);
                if (checkList.GroupBy(x => x).Any(g => g.Count() > 1))
                {
                    command.IsInvalid = true;
                }
            }
        }
 private void GetResponseListForColdTemp(InputDressCodeSequence input, DressCodeResponse response)
 {
     response.ResponseList = new List <string>();
     foreach (var command in input.Commands)
     {
         if (!command.IsInvalid)
         {
             response.ResponseList.Add(_weatherDrivenDressCodeData.InstructionsData
                                       .Find(v => v.Command == command.CommandKey).ColdResponse);
         }
         else
         {
             response.ResponseList.Add("fail");
             return;
         }
     }
 }
Beispiel #6
0
        public void Validate(InputDressCodeSequence input)
        {
            var checkList = new List <int>();

            foreach (var command in input.Commands)
            {
                if (command.CommandKey == _putOnHeadWear)
                {
                    if (!checkList.Exists(x => x == _putOnShirtCommand))
                    {
                        command.IsInvalid = true;
                        return;
                    }
                }

                checkList.Add(command.CommandKey);
            }
        }
 public void Validate(InputDressCodeSequence input)
 {
     if (input.Commands.Find(x => x.CommandKey == _leavingHouseCommandKey) != null)
     {
         var checkList = new List <int>();
         foreach (var command in input.Commands)
         {
             if (command.CommandKey == _leavingHouseCommandKey)
             {
                 command.IsInvalid = !_commandsBeforeLeavingHouse.All(itm2 => checkList.Contains(itm2));
             }
             else
             {
                 checkList.Add(command.CommandKey);
             }
         }
     }
 }
        public DressCodeResponse GetValidDressCode(InputDressCodeSequence input)
        {
            var response = new DressCodeResponse();

            switch (input.Code)
            {
            case Enums.TempCode.Hot:
                _ruleBook.ValidHotDressSequences(input);
                GetResponseListForHotTemp(input, response);
                return(response);

            case Enums.TempCode.Cold:
                _ruleBook.ValidColdDressSequences(input);
                GetResponseListForColdTemp(input, response);
                return(response);

            default:
                response.ResponseList = new List <string>();
                response.ResponseList.Add("fail");
                return(response);
            }
        }
Beispiel #9
0
        private static void Input(WeatherDressCodeSequencingService serviceProvider)
        {
            var userInput       = Console.ReadLine();
            var codeAndCommands = userInput?.Split(' ');

            if (codeAndCommands != null)
            {
                var input = new InputDressCodeSequence {
                    Commands = new List <Command>()
                };
                foreach (var instruction in codeAndCommands)
                {
                    switch (instruction.ToLower())
                    {
                    case "cold":
                        input.Code = Enums.TempCode.Cold;
                        continue;

                    case "hot":
                        input.Code = Enums.TempCode.Hot;
                        continue;
                    }

                    input.Commands.Add(new Command {
                        CommandKey = Int32.Parse(instruction)
                    });
                }

                var dressCodeResponse = serviceProvider.GetValidDressCode(input);
                foreach (var response in dressCodeResponse.ResponseList)
                {
                    Console.WriteLine(response);
                }
            }
            Input(serviceProvider);
        }