public async Task VMController_OnUpdateVM() { var vmController = new VMController(TestResponse, _vmFactory); await vmController.OnRequestVMAsync("conn1", typeof(UnitTestVM).Name); await vmController.OnUpdateVMAsync("conn1", typeof(UnitTestVM).Name, new Dictionary <string, object>() { { "LastName", "Doe" }, { "Age", 42 } }); Assert.AreEqual("conn1", _connectionId); Assert.AreEqual(typeof(UnitTestVM).Name, _vmId); var vmData = (JObject)JsonConvert.DeserializeObject(_vmData); Assert.AreEqual("John Doe", vmData["FullName"]); await vmController.OnRequestVMAsync("conn1", typeof(UnitTestVM).Name); Assert.AreEqual("conn1", _connectionId); Assert.AreEqual(typeof(UnitTestVM).Name, _vmId); vmData = (JObject)JsonConvert.DeserializeObject(_vmData); Assert.AreEqual("Doe", vmData["LastName"]); Assert.AreEqual(42, vmData["Age"]); vmController.Dispose(); }
public async Task <string> Request_VM( string vmId, [FromQuery] string vmArg, [FromServices] IVMFactory vmFactory, [FromServices] IHubServiceProvider hubServiceProvider, [FromServices] IVMServiceScopeFactory serviceScopeFactory, [FromServices] IHubPipeline hubPipeline, [FromServices] IPrincipalAccessor principalAccessor ) { var taskCompletionSource = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously); Task responseVM(string arg1, string arg2, string arg3) { taskCompletionSource.TrySetResult(arg3); return(Task.CompletedTask); } var vmController = new VMController(responseVM, vmFactory, serviceScopeFactory.CreateScope()) { ResponseVMFilter = CreateRespondingVMFilter(hubPipeline, vmId, vmArg) }; var httpCallerContext = InitializeContext(vmController, hubServiceProvider, principalAccessor); var connectionId = httpCallerContext.ConnectionId; try { var hubContext = new DotNetifyHubContext(httpCallerContext, nameof(Request_VM), vmId, vmArg, BuildHeaders(), httpCallerContext.User); vmController.RequestVMFilter = CreateVMFilter(hubContext, hubPipeline); await hubPipeline.RunMiddlewaresAsync(hubContext, async ctx => { await vmController.OnRequestVMAsync(connectionId, ctx.VMId, ctx.Data); vmController.Dispose(); }); } catch (Exception ex) { var finalEx = await hubPipeline.RunExceptionMiddlewareAsync(httpCallerContext, ex); if (finalEx is OperationCanceledException == false) { taskCompletionSource.TrySetResult(DotNetifyHub.SerializeException(finalEx)); } } return(await taskCompletionSource.Task); }
public async Task VMController_OnRequestVM() { var vmController = new VMController(TestResponse, _vmFactory); await vmController.OnRequestVMAsync("conn1", typeof(UnitTestVM).Name); Assert.AreEqual("conn1", _connectionId); Assert.AreEqual(typeof(UnitTestVM).Name, _vmId); var vmData = JsonConvert.DeserializeObject <UnitTestVM>(_vmData); Assert.IsNotNull(vmData); Assert.AreEqual("John", vmData.FirstName); Assert.AreEqual("Smith", vmData.LastName); Assert.AreEqual("John Smith", vmData.FullName); Assert.AreEqual(25, vmData.Age); vmController.Dispose(); }