Beispiel #1
0
        public void SaveManifest(Manifest manifest)
        {
            var oldManifest = _manifestCollection.Value.Manifests.FirstOrDefault(m => m.Name == manifest.Name);

            if (oldManifest == null)
                _manifestCollection.Value.Manifests.Add(manifest);
            else
            {
                var i = _manifestCollection.Value.Manifests.IndexOf(oldManifest);
                _manifestCollection.Value.Manifests[i] = manifest;
            }

            SaveManifestInfo();
        }
Beispiel #2
0
        private static bool GetCompilationSymbol(Manifest manifest, out string compilationSymbol)
        {
            const string key = "CompilationSymbol";

            compilationSymbol = String.Empty;

            if (manifest.Metadata == null)
                return false;

            if (!manifest.Metadata.ContainsKey(key))
                return false;

            var value = manifest.Metadata[key];
            var hasSymbol = !String.IsNullOrEmpty(value);
            if (hasSymbol)
                compilationSymbol = value;
            return hasSymbol;
        }
Beispiel #3
0
        private string GenerateTestMethods(Uri projectDirectory, string manifestBaseDirectory, Manifest manifest, DriverType driverType)
        {
            var testCollectionService = ServiceResolver.Get<ITestCollectionService>();

            var sb = new StringBuilder();

            foreach (var testCollectionFile in manifest.Files)
            {
                var testCollectionFilePath = Path.Combine(manifestBaseDirectory, testCollectionFile);
                var testCollection = testCollectionService.GetTestCollection(testCollectionFilePath, manifest.OverrideDomain);

                if (!testCollection.DriverTypes.IsNullOrNotAny() && !testCollection.DriverTypes.Contains(driverType))
                    continue;

                var testCollectionFullPath = new Uri(testCollectionFilePath);
                var testCollectionRelativePath = "~/" + projectDirectory.MakeRelativeUri(testCollectionFullPath);

                foreach (var test in testCollection.Tests)
                {
                    if (!test.DriverTypes.IsNullOrNotAny() && !test.DriverTypes.Contains(driverType))
                        continue;

                    sb.AppendLine(GenerateTestMethod(testCollectionRelativePath, manifest, test));
                }

            }

            return sb.ToString();
        }
Beispiel #4
0
        private string GenerateTestMethod(string testCollectionRelativePath, Manifest manifest, SeleniteTest test)
        {
            var tokenReplacer = new Func<Match, string>(match =>
            {
                switch (match.Value)
                {
                    case "@{TestName}":
                        return test.Name;
                    case "@{OverrideDomain}":
                        return manifest.OverrideDomain;
                    case "@{TestCollectionName}":
                        return testCollectionRelativePath;
                    case "@{TestCollectionNameFriendly}":
                        var extension = Path.GetExtension(testCollectionRelativePath);
                        var pathWithoutExtension = testCollectionRelativePath.Substring(0, testCollectionRelativePath.Length - extension.Length);
                        var cleanName = DisallowedTestNamePattern.Replace(pathWithoutExtension, "_");
                        cleanName = cleanName.TrimStart('_');
                        return cleanName;
                    case "@{TestNameFriendly}":
                        return DisallowedTestNamePattern.Replace(test.Name, "_");
                    case "@{TestJson}":
                        return JsonConvert.SerializeObject(test, Formatting.Indented);
                    case "@{SkipParameter}":
                        if (!test.TestCollection.Enabled)
                            return "(Skip = \"Disabled in Test Collection JSON\")";
                        if (!test.Enabled)
                            return "(Skip = \"Disabled in Test JSON\")";
                        return string.Empty;
                    default:
                        throw new InvalidOperationException("Invalid token: " + match.Value);
                }
            });

            return TokenFinder.Replace(TestMethodTemplate, new MatchEvaluator(tokenReplacer));
        }
Beispiel #5
0
        private string GenerateTestClasses(string inputFileName, Manifest manifest)
        {
            var activeProject = Dte.ActiveSolutionProjects[0];
            var projectPath = new Uri((string)activeProject.FileName);

            string compilationSymbol;
            var hasCompilationSymbol = GetCompilationSymbol(manifest, out compilationSymbol);

            var driverTypes = manifest.DriverTypes.IsNullOrNotAny()
                ? Enum
                    .GetValues(typeof (DriverType))
                    .Cast<DriverType>()
                    .ToArray()
                : manifest.DriverTypes;

            var sb = new StringBuilder();

            var startIf = hasCompilationSymbol ? "#if " + compilationSymbol : String.Empty;
            var firstLine = CodeFileTemplatePrefix.Replace("@{Namespace}", FileNamespace).Replace("@{BeginCompilationSymbol}", startIf);
            sb.AppendLine(firstLine);

            for (var i = 0; i < driverTypes.Count; i++)
            {
                var driverType = driverTypes[i];
                if (driverType == DriverType.Unknown)
                    continue;

                var tokenReplacer = new Func<Match, string>(match =>
                {
                    switch (match.Value)
                    {
                        case "@{ManifestName}":
                            return DisallowedTestNamePattern.Replace(manifest.Name, "_");
                        case "@{TestMethods}":
                            return GenerateTestMethods(projectPath, Path.GetDirectoryName(inputFileName), manifest, driverType);
                        case "@{DriverType}":
                            return driverType.ToString();
                        default:
                            throw new InvalidOperationException("Invalid token: " + match.Value);
                    }
                });

                var code = TokenFinder.Replace(TestClassTemplate, new MatchEvaluator(tokenReplacer));
                sb.AppendLine(code);
            }

            var endIf = hasCompilationSymbol ? "#endif" : String.Empty;
            var lastLine = CodeFileTemplatePostfix.Replace("@{EndCompilationSymbol}", endIf);
            sb.AppendLine(lastLine);

            return sb.ToString();
        }
        public IList<TestCollection> GetTestCollections(Manifest manifest, string overrideDomain = null)
        {
            var testCollections = manifest.Files
                .Select(file => GetTestCollection(file, overrideDomain ?? manifest.OverrideDomain))
                .ToList();

            var manifestInfo = _configurationService.ActiveManifestInfo;

            // Go through the manifest info and see if we need to disable any tests.
            foreach (var testCollection in testCollections)
            {
                var tc = manifestInfo.TestCollections != null
                    ? manifestInfo.TestCollections.FirstOrDefault(testColl => testColl.Name == testCollection.File)
                    : null;

                if (tc == null)
                    continue;

                testCollection.Enabled = tc.IsEnabled;

                foreach (var test in testCollection.Tests)
                    if (tc.DisabledTests.Contains(test.Name))
                        test.Enabled = false;
            }

            return testCollections;
        }