public void GetEnumeratorTest()
        {
            FilePathCollection target = new FilePathCollection();

            AssertExtras.Raises <ArgumentException>(delegate()
            {
                foreach (var choice in target)
                {
                }
            });

            // Test path
            target.Path = testFolderPath;
            var expected = new List <string> {
                testFolderPath + "item1.txt",
                testFolderPath + "item2.txt",
                testFolderPath + "item3.log",
                testFolderPath + "item5.png",
            };
            var actual = new List <string>();

            foreach (var choice in target)
            {
                actual.Add(choice.Value.ToString());
            }
            AssertExtras.ListIsEqual(expected, actual);

            // Test pattern
            target.SearchPattern = "*.txt";
            expected             = new List <string> {
                testFolderPath + "item1.txt",
                testFolderPath + "item2.txt"
            };
            actual = new List <string>();
            foreach (var choice in target)
            {
                actual.Add(choice.Value.ToString());
            }
            AssertExtras.ListIsEqual(expected, actual);

            // Test recursive
            target.Recursive = true;
            expected         = new List <string> {
                testFolderPath + "item1.txt",
                testFolderPath + "item2.txt",
                testFolderPath + "SubFolder\\item4.txt"
            };
            actual = new List <string>();
            foreach (var choice in target)
            {
                actual.Add(choice.Value.ToString());
            }
            AssertExtras.ListIsEqual(expected, actual);
        }
        public void SplitStringTest()
        {
            List <object> empty  = new List <object>();
            List <object> single = new List <object>()
            {
                "test1"
            };
            List <object> multiple = new List <object>()
            {
                "test1", "test2", "test3"
            };

            AssertExtras.ListIsEqual(empty, ConversionHelper.SplitString(null));
            AssertExtras.ListIsEqual(empty, ConversionHelper.SplitString(string.Empty));
            AssertExtras.ListIsEqual(single, ConversionHelper.SplitString("test1"));
            AssertExtras.ListIsEqual(multiple, ConversionHelper.SplitString("test1,test2,test3"));
        }
        public void ObjectListTest()
        {
            Collection <object> empty = new Collection <object>();

            string[]      stringArray = new string[] { "a", "b", "c" };
            List <object> stringList  = new List <object>()
            {
                "a", "b", "c"
            };
            List <object> single = new List <object>()
            {
                "test1"
            };

            Assert.IsNull(ConversionHelper.ObjectList(null));
            Assert.AreSame(empty, ConversionHelper.ObjectList(empty));
            AssertExtras.ListIsEqual(stringList, ConversionHelper.ObjectList(stringArray));
            AssertExtras.ListIsEqual(single, ConversionHelper.ObjectList("test1"));
        }
        public void CleanTest()
        {
            var target = new MultipleChoiceField()
            {
                Choices = Widgets.Choices.AustralianStates.Abbreviated
            };

            AssertExtras.Raises <ValidationException>(delegate() {
                target.Clean(null);
            }).WithMessage("This field is required.");

            target.Required = false;

            var result = target.Clean(null) as Collection <object>;

            Assert.IsInstanceOfType(result, typeof(Collection <object>));
            Assert.AreEqual(0, result.Count);

            var validCollection = new Collection <object> {
                "QLD", "SA"
            };
            var invalidCollection = new Collection <object> {
                "QLD", "SA", "CA"
            };

            AssertExtras.Raises <ValidationException>(delegate()
            {
                target.Clean("123");
            }).WithMessage("Select a valid choice. \"123\" is not one of the available choices.");

            AssertExtras.ListIsEqual(validCollection, target.Clean(validCollection) as IList);
            AssertExtras.Raises <ValidationException>(delegate()
            {
                target.Clean(invalidCollection);
            }).WithMessage("Select a valid choice. \"CA\" is not one of the available choices.");
        }