SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void StartStorageEmulator()
  2. {
  3.     //var count = Process.GetProcessesByName("DSServiceLDB").Length;
  4.     //if (count == 0)
  5.     //  ExecuteCSRun("/devstore:start");
  6.     var count = Process.GetProcessesByName("WAStorageEmulator").Length;
  7.     if (count == 0)
  8.         ExecuteWAStorageEmulator("start");
  9. }
  10.  
  11. /*
  12. private static void ExecuteCSRun(string argument)
  13. {
  14.     var start = new ProcessStartInfo
  15.     {
  16.         Arguments = argument,
  17.         FileName = @"c:Program FilesMicrosoft SDKsWindows AzureEmulatorcsrun.exe"
  18.     };
  19. var exitCode = ExecuteProcess(start);
  20. Assert.AreEqual(exitCode, 0, "Error {0} executing {1} {2}", exitCode, start.FileName, start.Arguments);
  21. }
  22. */
  23.  
  24. private static void ExecuteWAStorageEmulator(string argument)
  25. {
  26.     var start = new ProcessStartInfo
  27.     {
  28.         Arguments = argument,
  29.         FileName = @"c:Program Files (x86)Microsoft SDKsWindows AzureStorage EmulatorWAStorageEmulator.exe"
  30.     };
  31.     var exitCode = ExecuteProcess(start);
  32.     Assert.AreEqual(exitCode, 0, "Error {0} executing {1} {2}", exitCode, start.FileName, start.Arguments);
  33. }
  34.  
  35. private static int ExecuteProcess(ProcessStartInfo start)
  36. {
  37.     int exitCode;
  38.     using (var proc = new Process { StartInfo = start })
  39.     {
  40.         proc.Start();
  41.         proc.WaitForExit();
  42.         exitCode = proc.ExitCode;
  43.     }
  44.     return exitCode;
  45. }
  46.      
  47. using System;
  48. using System.Diagnostics;
  49. using System.Linq;
  50. using System.Threading;
  51. using Xunit;
  52.  
  53. namespace UnitTests.Persistence
  54. {
  55.     public class AzureStorageEmulatorManagerV3
  56.     {
  57.         private const string ProcessName = "WAStorageEmulator";
  58.  
  59.         public static void StartStorageEmulator()
  60.         {
  61.             var count = Process.GetProcessesByName(ProcessName).Length;
  62.             if (count == 0)
  63.                 ExecuteWAStorageEmulator("start");
  64.         }
  65.  
  66.         public static void StopStorageEmulator()
  67.         {
  68.             Process process = GetWAstorageEmulatorProcess();
  69.             if (process != null)
  70.             {
  71.                 process.Kill();
  72.             }
  73.         }
  74.  
  75.         private static void ExecuteWAStorageEmulator(string argument)
  76.         {
  77.             var start = new ProcessStartInfo
  78.             {
  79.                 Arguments = argument,
  80.                 FileName = @"c:Program Files (x86)Microsoft SDKsWindows AzureStorage EmulatorWAStorageEmulator.exe"
  81.             };
  82.             var exitCode = ExecuteProcess(start);
  83.             if (exitCode != 0)
  84.             {
  85.                 string message = string.Format(
  86.                     "Error {0} executing {1} {2}",
  87.                     exitCode,
  88.                     start.FileName,
  89.                     start.Arguments);
  90.                 throw new InvalidOperationException(message);
  91.             }
  92.         }
  93.  
  94.         private static int ExecuteProcess(ProcessStartInfo start)
  95.         {
  96.             int exitCode;
  97.             using (var proc = new Process { StartInfo = start })
  98.             {
  99.                 proc.Start();
  100.                 proc.WaitForExit();
  101.                 exitCode = proc.ExitCode;
  102.             }
  103.             return exitCode;
  104.         }
  105.  
  106.         public static Process GetWAstorageEmulatorProcess()
  107.         {
  108.             return Process.GetProcessesByName(ProcessName).FirstOrDefault();
  109.         }
  110.  
  111.         [Fact]
  112.         public void StartingAndThenStoppingWAStorageEmulatorGoesOk()
  113.         {
  114.             // Arrange Start
  115.             AzureStorageEmulatorManagerV3.StartStorageEmulator();
  116.  
  117.             // Act
  118.             Thread.Sleep(2000);
  119.             Process WAStorageEmulatorProcess = GetWAstorageEmulatorProcess();
  120.  
  121.             // Assert
  122.             Assert.NotNull(WAStorageEmulatorProcess);
  123.             Assert.True(WAStorageEmulatorProcess.Responding);
  124.  
  125.             // Arrange Stop
  126.             AzureStorageEmulatorManagerV3.StopStorageEmulator();
  127.             Thread.Sleep(2000);
  128.             // Act
  129.             WAStorageEmulatorProcess = GetWAstorageEmulatorProcess();
  130.  
  131.             // Assert
  132.             Assert.Null(WAStorageEmulatorProcess);
  133.         }
  134.     }
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top