PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/VisualStudio/ABB.SrcML.VisualStudio.SrcMLService.IntegrationTests/TestHelpers.cs

https://github.com/nkcsgexi/SrcML.NET
C# | 49 lines | 43 code | 6 blank | 0 comment | 3 complexity | 5c5d33d45e8490c02e81a1a838fd5c19 MD5 | raw file
  1. using EnvDTE;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace ABB.SrcML.VisualStudio.SrcMLService.IntegrationTests {
  11. [TestClass]
  12. public class TestHelpers {
  13. internal static Scaffold<ISrcMLGlobalService> TestScaffold;
  14. [AssemblyInitialize]
  15. public static void AssemblySetup(TestContext testContext) {
  16. TestScaffold = Scaffold<ISrcMLGlobalService>.Setup(new SrcMLServicePackage(), typeof(SSrcMLGlobalService));
  17. }
  18. [AssemblyCleanup]
  19. public static void AssemblyCleanup() {
  20. TestScaffold.Cleanup();
  21. }
  22. internal static bool WaitForServiceToFinish(ISrcMLGlobalService service, int millisecondsTimeout) {
  23. if(!service.IsReady) {
  24. ManualResetEvent mre = new ManualResetEvent(false);
  25. EventHandler<IsReadyChangedEventArgs> action = (o, e) => { mre.Set(); };
  26. service.IsReadyChanged += action;
  27. mre.WaitOne(millisecondsTimeout);
  28. service.IsReadyChanged -= action;
  29. }
  30. return service.IsReady;
  31. }
  32. internal static IEnumerable<Project> GetProjects(Solution solution) {
  33. var projects = solution.Projects;
  34. var enumerator = projects.GetEnumerator();
  35. while(enumerator.MoveNext()) {
  36. Project currentProject = enumerator.Current as Project;
  37. if(null != currentProject) {
  38. yield return currentProject;
  39. }
  40. }
  41. }
  42. }
  43. }