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

/tests/Microsoft.AspNet.SignalR.FunctionalTests/Server/Hubs/HubProgressFacts.cs

https://gitlab.com/scgitlab/SignalR
C# | 204 lines | 177 code | 27 blank | 0 comment | 0 complexity | 847def47e9c8a1c03e15f744d9624085 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNet.SignalR.Client;
  7. using Microsoft.AspNet.SignalR.Tests.Common.Infrastructure;
  8. using Xunit;
  9. using Xunit.Extensions;
  10. namespace Microsoft.AspNet.SignalR.FunctionalTests.Server.Hubs
  11. {
  12. public class HubProgressFacts : HostedTest
  13. {
  14. [Theory]
  15. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  16. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  17. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  18. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  19. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  20. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  21. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  22. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  23. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  24. public async Task HubProgressIsReportedSuccessfully(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  25. {
  26. using (var host = CreateHost(hostType, transportType))
  27. {
  28. host.Initialize(messageBusType: messageBusType);
  29. HubConnection hubConnection = CreateHubConnection(host);
  30. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  31. var progressUpdates = new List<int>();
  32. var jobName = "test";
  33. using (hubConnection)
  34. {
  35. await hubConnection.Start(host.Transport);
  36. var result = await proxy.Invoke<string, int>("DoLongRunningJob", progress => progressUpdates.Add(progress), jobName);
  37. Assert.Equal(new[] { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, progressUpdates);
  38. Assert.Equal(String.Format("{0} done!", jobName), result);
  39. }
  40. }
  41. }
  42. [Theory]
  43. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  44. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  45. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  46. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  47. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  48. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  49. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  50. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  51. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  52. public async Task HubProgressThrowsInvalidOperationExceptionIfAttemptToReportProgressAfterMethodReturn(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  53. {
  54. using (var host = CreateHost(hostType, transportType))
  55. {
  56. host.Initialize(messageBusType: messageBusType);
  57. HubConnection hubConnection = CreateHubConnection(host);
  58. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  59. proxy.On<bool>("sendProgressAfterMethodReturnResult", result => Assert.True(result));
  60. using (hubConnection)
  61. {
  62. await hubConnection.Start(host.Transport);
  63. await proxy.Invoke<int>("SendProgressAfterMethodReturn", _ => { });
  64. }
  65. }
  66. }
  67. [Theory]
  68. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  69. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  70. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  71. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  72. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  73. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  74. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  75. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  76. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  77. public async Task HubProgressReportsProgressForInt(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  78. {
  79. using (var host = CreateHost(hostType, transportType))
  80. {
  81. host.Initialize(messageBusType: messageBusType);
  82. HubConnection hubConnection = CreateHubConnection(host);
  83. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  84. using (hubConnection)
  85. {
  86. await hubConnection.Start(host.Transport);
  87. await proxy.Invoke<int>("ReportProgressInt", progress => Assert.Equal(100, progress));
  88. }
  89. }
  90. }
  91. [Theory]
  92. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  93. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  94. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  95. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  96. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  97. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  98. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  99. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  100. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  101. public async Task HubProgressReportsProgressForString(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  102. {
  103. using (var host = CreateHost(hostType, transportType))
  104. {
  105. host.Initialize(messageBusType: messageBusType);
  106. HubConnection hubConnection = CreateHubConnection(host);
  107. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  108. using (hubConnection)
  109. {
  110. await hubConnection.Start(host.Transport);
  111. await proxy.Invoke<string>("ReportProgressString", progress => Assert.Equal("Progress is 100%", progress));
  112. }
  113. }
  114. }
  115. [Theory]
  116. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  117. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  118. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  119. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  120. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  121. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  122. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  123. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  124. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  125. public async Task HubProgressReportsProgressForCustomType(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  126. {
  127. using (var host = CreateHost(hostType, transportType))
  128. {
  129. host.Initialize(messageBusType: messageBusType);
  130. HubConnection hubConnection = CreateHubConnection(host);
  131. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  132. using (hubConnection)
  133. {
  134. await hubConnection.Start(host.Transport);
  135. await proxy.Invoke<ProgressUpdate>("ReportProgressTyped", progress =>
  136. {
  137. Assert.Equal(100, progress.Percent);
  138. Assert.Equal("Progress is 100%", progress.Message);
  139. });
  140. }
  141. }
  142. }
  143. [Theory]
  144. [InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
  145. [InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
  146. [InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
  147. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
  148. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
  149. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
  150. [InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.FakeMultiStream)]
  151. [InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
  152. [InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
  153. public async Task HubProgressReportsProgressForDynamic(HostType hostType, TransportType transportType, MessageBusType messageBusType)
  154. {
  155. using (var host = CreateHost(hostType, transportType))
  156. {
  157. host.Initialize(messageBusType: messageBusType);
  158. HubConnection hubConnection = CreateHubConnection(host);
  159. IHubProxy proxy = hubConnection.CreateHubProxy("progress");
  160. using (hubConnection)
  161. {
  162. await hubConnection.Start(host.Transport);
  163. await proxy.Invoke<dynamic>("ReportProgressDynamic", progress =>
  164. {
  165. Assert.Equal(100, (int)progress.Percent);
  166. Assert.Equal("Progress is 100%", (string)progress.Message);
  167. });
  168. }
  169. }
  170. }
  171. public class ProgressUpdate
  172. {
  173. public int Percent { get; set; }
  174. public string Message { get; set; }
  175. }
  176. }
  177. }