public void SaveTestCollectionInfo(TestCollection testCollection)
        {
            var activeManifest = _configurationService.ActiveManifestInfo;

            if (activeManifest == null)
            {
                throw new InvalidOperationException("Could not load the active manifest.");
            }

            var testCollectionInfo = new TestCollectionInfo
            {
                Name = testCollection.File,
                IsEnabled = testCollection.Enabled,
                DisabledTests = testCollection.Tests
                    .Where(test => !test.Enabled)
                    .Select(test => test.Name)
                    .ToList(),
            };

            if (activeManifest.TestCollections == null)
            {
                activeManifest.TestCollections = new List<TestCollectionInfo> { testCollectionInfo };
            }

            // Update the existing test collection to the current values if it's already in the list.
            var tci = activeManifest.TestCollections.FirstOrDefault(tc => tc.Name == testCollectionInfo.Name);
            if (tci != null)
            {
                activeManifest.TestCollections.Remove(tci);
            }

            activeManifest.TestCollections.Add(testCollectionInfo);

            _configurationService.ActiveManifestInfo = activeManifest;
        }
        private SeleniteTest CreateTest(TestCollection testCollection, dynamic test, string domain, bool isEnabled = true)
        {
            var url = test.Url.ToString();

            var baseUri = domain.EndsWith("/")
                ? new Uri(domain)
                : new Uri(domain + "/");

            var relativeUri = new Uri(baseUri, url);

            var testInstance = new SeleniteTest
            {
                TestCollection = testCollection,
                Enabled = isEnabled,
                Name = test.Name,
                Description = test.Description,
                Url = url,
                TestUrl = relativeUri.ToString(),
                Macros = GetDictionaryFromJObject(test.Macros)
            };

            var commands = new List<ICommand>();

            foreach (var command in test.Commands)
                commands.Add(_commandService.CreateCommand(command, testInstance));

            testInstance.Commands = commands;

            return testInstance;
        }
        // TODO: See if the UI can go through the same flow as the test runner and use GetTestCollections instead of this method.
        private TestCollection CreateTestCollection(string resolvedPath, string name, dynamic testCollection, string overrideDomain)
        {
            var manifestInfo = _configurationService == null
                ? null
                : _configurationService.ActiveManifestInfo;

            var testCollectionInfo = manifestInfo != null && manifestInfo.TestCollections != null
                ? manifestInfo.TestCollections.FirstOrDefault(tc => tc.Name == name)
                : null;

            var isEnabled = testCollectionInfo != null
                ? testCollectionInfo.IsEnabled
                : testCollection.Enabled ?? true;

            var collection = new TestCollection
            {
                DefaultDomain = String.IsNullOrWhiteSpace(overrideDomain)
                    ? testCollection.DefaultDomain
                    : overrideDomain,
                Enabled = isEnabled,
                File = name,
                ResolvedFile = resolvedPath,
                SetupStepsFile = testCollection.SetupStepsFile,
                Description = testCollection.Description,
                Macros = GetDictionaryFromJObject(testCollection.Macros),
            };

            if (!String.IsNullOrWhiteSpace(collection.SetupStepsFile))
                collection.SetupStepsFile = ResolvePath(resolvedPath, collection.SetupStepsFile);

            var tests = new List<SeleniteTest>();

            foreach (var test in testCollection.Tests)
            {
                var enabled = (bool?) test.Enabled;

                var testEnabled = (testCollectionInfo == null 
                        || testCollectionInfo.DisabledTests == null 
                        || !testCollectionInfo.DisabledTests.Any(testName => testName == test.Name.ToString()))
                    && enabled.GetValueOrDefault(true);

                tests.Add(CreateTest(collection, test, collection.DefaultDomain, testEnabled));
            }

            if (!String.IsNullOrWhiteSpace(collection.SetupStepsFile))
            {
                if (testCollection.SetupSteps != null)
                    throw new InvalidOperationException("Must only specify SetupSteps or SetupStepsFile");

                var setupStepsJson = _fileService.ReadAllText(collection.SetupStepsFile);
                testCollection.SetupSteps = JArray.Parse(setupStepsJson);
            }
            
            if (testCollection.SetupSteps != null)
            {
                var setupSteps = new List<SeleniteTest>();
                foreach (var step in testCollection.SetupSteps)
                {
                    var setupStep = CreateTest(collection, step, collection.DefaultDomain, true);
                    setupSteps.Add(setupStep);
                }
                collection.SetupSteps = setupSteps;
            }

            collection.Tests = tests;

            return collection;
        }