Пример #1
0
        public void TrackTestExecution(string projectTrackInfo)
        {
            bool isDebug = IsDebugRun();

            try
            {
                if (!isDebug)
                {
                    projectTrackInfo = $"{projectTrackInfo}  Framework";

                    var assemblyFacade      = new AssemblyFacade();
                    var callingAssemblies   = assemblyFacade.GetAssembliesCallChain();
                    var testProjectAssembly = callingAssemblies[3];

                    if (callingAssemblies.Any(x => x.FullName.Contains("SpecFlow")))
                    {
                        projectTrackInfo = $"{projectTrackInfo} SpecFlow";
                    }

                    if (testProjectAssembly.FullName.Contains("GettingStarted"))
                    {
                        projectTrackInfo = $"{projectTrackInfo} GettingStarted";
                    }

                    var            testInfoProvider = new TestInfoProvider();
                    EventTelemetry eventTelemetry   = default;
                    int            mstestTestsCount = testInfoProvider.CountBellatrixTests(testProjectAssembly, _msTestClassAttributeName, _msTestTestAttributeName);
                    int            nunitTestsCount  = testInfoProvider.CountBellatrixTests(testProjectAssembly, _nunitTestFixtureAttributeName, _nunitTestAttributeName);
                    if (mstestTestsCount > 0)
                    {
                        eventTelemetry      = new EventTelemetry();
                        eventTelemetry.Name = "MSTest Test Run";
                        eventTelemetry.Metrics.Add(projectTrackInfo, mstestTestsCount);
                    }

                    if (nunitTestsCount > 0)
                    {
                        eventTelemetry      = new EventTelemetry();
                        eventTelemetry.Name = "NUnit Test Run";
                        eventTelemetry.Metrics.Add(projectTrackInfo, nunitTestsCount);
                    }

                    TelemetryService.TrackEvent(eventTelemetry, isDebug);
                }
            }
            catch (Exception ex)
            {
                TelemetryService.TrackException(ex, isDebug);
            }
        }
Пример #2
0
        public string FromFile(string name)
        {
            _currentExecutingAssembly = _currentExecutingAssembly ?? _assemblyFacade.GetAssembliesCallChain()[2];
            string currentFileTempPath;

            using (var resourceStream = _currentExecutingAssembly.GetManifestResourceStream(name))
            {
                var tempFolder = Path.GetTempPath();
                currentFileTempPath = Path.Combine(tempFolder, name).Replace("\\", "/");

                using Stream file = File.Create(currentFileTempPath);
                CopyStream(resourceStream, file);
            }

            if (!File.Exists(currentFileTempPath))
            {
                throw new ArgumentException($"Image {name} was not found. Please add the base line image as embedded resource.");
            }

            return(currentFileTempPath);
        }