public void TestThatInvalidDayOfWeekFailsValidation(Site.PickupDays day)
        {
            testSite.sitePickupDays = day;
            var results = HelperTestModel.Validate(testSite);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("Specified Pickup Days are invalid", results[0].ErrorMessage);
        }
        // This method will take in a String value of an Excel cell
        // and tries to parse to a valid PickupDay. If it fails, it will return an invalid PickupDay
        public static Site.PickupDays ParsePickupDays(string[] pickupDays)
        {
            //Order the pickupDays string array in descending order for each collection that has data (is not null or empty)
            pickupDays = pickupDays.Where(s => !string.IsNullOrEmpty(s)).OrderByDescending(s => s).ToArray();

            Site.PickupDays parsedPickupDays = (Site.PickupDays) 0;

            int largestNumber = 0;

            //If there are no collection days to parse, immediately set the PickupDays to invalid and return
            if (pickupDays.Length == 0)
            {
                return(Site.PickupDays.Invalid);
            }

            //Find and parse the largest number (also most recent) of the given collection days
            Int32.TryParse(pickupDays[0], out largestNumber);

            //If the largest number falls outside of the valid ranges, immediately set the PickupDays to invalid and return
            if (largestNumber > 9999 || largestNumber < 1000 || largestNumber == 0)
            {
                return(Site.PickupDays.Invalid);
            }

            //Create a string array to hold the largest collection day value
            string collectionDay = pickupDays[0];

            //Create a char array to store individual digits of each collection day
            char largestDigit = collectionDay[0];

            //For each digit in the current collection day
            foreach (string day in pickupDays)
            {
                //If the first digit in the day is the largest digit and the entire number is 4 digits (valid)
                if (day[0] == largestDigit && day.Length == 4)
                {
                    //Get the last digit of the collection (numeric day of the week)
                    int lastDigit = Convert.ToInt32(day[3].ToString());

                    //Get the last pick up day of the collection (convert to value our enum can use)
                    int lastPickupDay = Convert.ToInt32(Math.Pow(2, (lastDigit - 1)));

                    //Append the parsed pickup day to the existing variable of pickup days
                    parsedPickupDays = parsedPickupDays | ((Site.PickupDays)lastPickupDay);
                }
                else
                {
                    break;
                }
            }

            return(parsedPickupDays);
        }
        public void TestThatParseSitePickupDaysValidPickupDays()
        {
            string[] collectionDays = new string[4];

            collectionDays[0] = "1005";
            collectionDays[1] = "2005";
            collectionDays[2] = "";
            collectionDays[3] = "";

            Site.PickupDays pickupDays = SiteParser.ParsePickupDays(collectionDays);

            Assert.IsTrue(pickupDays == Site.PickupDays.Friday);
        }
        public void TestThatParseSitePickupDaysWithMultipleDaysIsValid()
        {
            string[] collectionDays = new string[]
            {
                "1002",
                "1005",
                "2002",
                "2005",
            };

            Site.PickupDays pickupDays = SiteParser.ParsePickupDays(collectionDays);

            Assert.IsTrue(pickupDays == (Site.PickupDays.Tuesday | Site.PickupDays.Friday));
        }
        public void TestThatParseSitePickupDaysWithInvalidDaysReturnsInvalid()
        {
            string[] collectionDays = new string[]
            {
                "SomeRandomString",
                "String",
                "1092",
                "12321"
            };

            Site.PickupDays pickupDays = SiteParser.ParsePickupDays(collectionDays);

            Assert.IsTrue(pickupDays == Site.PickupDays.Invalid);
        }