예제 #1
0
            private async Task UpdateTestCasesAsync(IEnumerable <string> paths, bool notify)
            {
                var analyzer = await _project.GetAnalyzerAsync();

                if (analyzer == null)
                {
                    return;
                }

                var testCaseData = await analyzer.SendExtensionCommandAsync(
                    TestAnalyzer.Name,
                    TestAnalyzer.GetTestCasesCommand,
                    string.Join(";", paths)
                    );

                if (testCaseData == null)
                {
                    return;
                }

                var testCaseGroups = TestAnalyzer.GetTestCases(testCaseData).GroupBy(tc => tc.Filename);

                bool anythingToNotify = false;

                foreach (var testCases in testCaseGroups)
                {
                    var path = testCases.Key;
                    if (testCases.Any())
                    {
                        if (!TryGetContainer(path, out TestContainer existing) || !existing.TestCases.SequenceEqual(testCases))
                        {
                            // we have a new entry or some of the tests changed
                            int version = (existing?.Version ?? 0) + 1;
                            lock (_containersLock) {
                                _containers[path] = new TestContainer(
                                    _discoverer,
                                    path,
                                    _project,
                                    version,
                                    Architecture,
                                    testCases.ToArray()
                                    );
                            }

                            anythingToNotify = true;
                        }
                    }
                    else if (RemoveContainer(path))
                    {
                        // Raise containers changed event...
                        anythingToNotify = true;
                    }
                }

                if (notify && anythingToNotify)
                {
                    ContainersChanged();
                }
            }
예제 #2
0
            public async void AnalysisComplete(object sender, AnalysisCompleteEventArgs e)
            {
                var testCaseData = await _project.Analyzer.SendExtensionCommandAsync(
                    TestAnalyzer.Name,
                    TestAnalyzer.GetTestCasesCommand,
                    e.Path
                    );

                if (testCaseData == null)
                {
                    return;
                }
                var testCases = TestAnalyzer.GetTestCases(testCaseData);

                if (testCases.Length != 0)
                {
                    TestContainer existing;
                    bool          changed = true;
                    if (_containers.TryGetValue(e.Path, out existing))
                    {
                        // we have an existing entry, let's see if any of the tests actually changed.
                        if (existing.TestCases.Length == testCases.Length)
                        {
                            changed = false;

                            for (int i = 0; i < existing.TestCases.Length; i++)
                            {
                                if (!existing.TestCases[i].Equals(testCases[i]))
                                {
                                    changed = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (changed)
                    {
                        // we have a new entry or some of the tests changed
                        int version = (existing?.Version ?? 0) + 1;
                        _containers[e.Path] = new TestContainer(
                            _discoverer,
                            e.Path,
                            _project,
                            version,
                            Architecture,
                            testCases
                            );

                        ContainersChanged();
                    }
                }
                else if (_containers.Remove(e.Path))
                {
                    // Raise containers changed event...
                    ContainersChanged();
                }
            }
예제 #3
0
            private async Task <bool> UpdateTestCasesAsync(string path, bool notify)
            {
                var testCaseData = await _project.Analyzer.SendExtensionCommandAsync(
                    TestAnalyzer.Name,
                    TestAnalyzer.GetTestCasesCommand,
                    path
                    );

                if (testCaseData == null)
                {
                    return(false);
                }

                var testCases = TestAnalyzer.GetTestCases(testCaseData);

                if (testCases.Length != 0)
                {
                    TestContainer existing;
                    bool          changed = true;
                    if (_containers.TryGetValue(path, out existing))
                    {
                        // we have an existing entry, let's see if any of the tests actually changed.
                        if (existing.TestCases.Length == testCases.Length)
                        {
                            changed = false;

                            for (int i = 0; i < existing.TestCases.Length; i++)
                            {
                                if (!existing.TestCases[i].Equals(testCases[i]))
                                {
                                    changed = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (changed)
                    {
                        // we have a new entry or some of the tests changed
                        int version = (existing?.Version ?? 0) + 1;
                        _containers[path] = new TestContainer(
                            _discoverer,
                            path,
                            _project,
                            version,
                            Architecture,
                            testCases
                            );

                        if (notify)
                        {
                            ContainersChanged();
                        }
                        return(true);
                    }
                }
                else if (_containers.Remove(path))
                {
                    // Raise containers changed event...
                    if (notify)
                    {
                        ContainersChanged();
                    }
                    return(true);
                }

                return(false);
            }