public void Initialize() { VMController.Register("HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "Hello"); var lastName = vm.AddProperty("LastName", "World"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); VMController.Register("MyNamespace.HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "John"); var lastName = vm.AddProperty("LastName", "Hancock"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); var hubEmulatorBuilder = new HubEmulatorBuilder(); foreach (var typeHelper in VMController.VMTypes) { hubEmulatorBuilder.Register(typeHelper.FullName, typeHelper.CreateInstance()); } _hubEmulator = hubEmulatorBuilder.Build(); }
public void Initialize() { VMController.Register <SimpleListVM>(); var baseDelegate = VMController.CreateInstance; VMController.CreateInstance = (type, args) => type == typeof(SimpleListVM) ? new SimpleListVM(_employeeService) : baseDelegate(type, args); }
public void Initialize() { VMController.Register <MasterVM>(); VMController.Register <DetailsVM>(); var baseDelegate = VMController.CreateInstance; VMController.CreateInstance = (type, args) => type == typeof(MasterVM) ? _masterVM : baseDelegate(type, args); }
public void Initialize() { VMController.Register <BetterListVM>(); var baseDelegate = VMController.CreateInstance; VMController.CreateInstance = (type, args) => { if (type == typeof(BetterListVM)) { return(new BetterListVM(_model)); } return(baseDelegate(type, args)); }; }
public void DisconnectionMiddleware_DisconnectionIntercepted() { VMController.Register <TestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <CustomMiddleware>() .Create(); bool middlewareInvoked = false; _middleware.Invoked += (sender, e) => middlewareInvoked = true; hub.RequestVM(nameof(TestVM)); hub.OnDisconnected(); Assert.IsTrue(middlewareInvoked); }
public void Filter_PushUpdateIntercepted() { VMController.Register <FilterTestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <ExtractHeadersMiddleware>() .UseMiddleware <JwtBearerAuthenticationMiddleware>() .UseFilter <AuthorizeFilter>() .UseFilter <CustomFilter1>() .UseFilter <CustomFilter2>() .Create(); Action filter1Assertions = null; _filter1.Invoked += (sender, tuple) => { if (tuple.Item2.HubContext.CallType != "Response_VM") { return; } var attr = tuple.Item1; var vmContext = tuple.Item2; var context = vmContext.HubContext; var connectionId = context.CallerContext.ConnectionId; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); filter1Assertions = () => { Assert.AreEqual(hub.ConnectionId, connectionId); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(0, pipelineData.Count); Assert.AreEqual(_vm, vmContext.Instance); Assert.AreEqual("Welcome", attr.Property); }; }; hub.RequestVM(nameof(FilterTestVM), _vmArg); _vm.TriggerProperty = true; _vm.PushUpdates(); filter1Assertions(); }
public void LiveChartNoBaseVM_PushUpdates() { int updateCounter = 0; VMController.Register <LiveChartNoBaseVM>(); VMController.VMResponseDelegate handler = (string connectionId, string vmId, string vmData) => { updateCounter++; }; var vmController = new VMController(handler); vmController.OnRequestVM("conn1", typeof(LiveChartNoBaseVM ).Name); System.Threading.Thread.Sleep(1000); Assert.IsTrue(updateCounter >= 5); }
public MockVMController(TViewModel vmInstance = default(TViewModel)) { if (vmInstance?.Equals(default(TViewModel)) == false) { VMController.CreateInstance = (type, args) => type == typeof(TViewModel) ? vmInstance : throw new InvalidOperationException(); } else { VMController.CreateInstance = (type, args) => Activator.CreateInstance(type, args); } VMController.Register <TViewModel>(); _vmId = typeof(TViewModel).Name; _vmController = new VMController((connectionId, vmId, vmData) => { _response.Handler(connectionId, vmId, vmData); OnResponse?.Invoke(this, vmData); }); }
public void Initialize() { VMController.Register("HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "Hello"); var lastName = vm.AddProperty("LastName", "World"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); VMController.Register("MyNamespace.HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "John"); var lastName = vm.AddProperty("LastName", "Hancock"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); }
public void Middleware_ResponseIntercepted() { VMController.Register <MiddlewareTestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <ExtractHeadersMiddleware>() .UseMiddleware <JwtBearerAuthenticationMiddleware>() .UseMiddleware <CustomMiddleware3>() .Create(); hub.RequestVM(nameof(MiddlewareTestVM), _vmArg); string responsePropertyValue = null; hub.Response += (sender, e) => { dynamic data = JsonConvert.DeserializeObject <dynamic>(e.Item2); responsePropertyValue = data.ResponseProperty; }; hub.UpdateVM(nameof(MiddlewareTestVM), new Dictionary <string, object> { { "TriggerProperty", true } }); Assert.AreEqual("TRIGGERED", responsePropertyValue); }
public void Initialize() { VMController.Register <MasterVM>(); VMController.Register <DetailsVM>(); }
public void Filter_RequestIntercepted() { VMController.Register <FilterTestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <ExtractHeadersMiddleware>() .UseMiddleware <JwtBearerAuthenticationMiddleware>() .UseFilter <AuthorizeFilter>() .UseFilter <CustomFilter1>() .UseFilter <CustomFilter2>() .Create(); string vmName = null; dynamic vmData = null; hub.Response += (sender, e) => { vmName = e.Item1; vmData = JsonConvert.DeserializeObject <dynamic>(e.Item2); }; Action filter1Assertions = null; _filter1.Invoked += (sender, tuple) => { var attr = tuple.Item1; var vmContext = tuple.Item2; var context = vmContext.HubContext; var callType = context.CallType; var connectionId = context.CallerContext.ConnectionId; var testVMPropValue = (context.Data as JObject)[nameof(FilterTestVM.Property)]; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); filter1Assertions = () => { Assert.AreEqual("Request_VM", callType); Assert.AreEqual(hub.ConnectionId, connectionId); Assert.AreEqual("World", testVMPropValue); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(0, pipelineData.Count); Assert.AreEqual(_vm, vmContext.Instance); Assert.AreEqual("Welcome", attr.Property); }; }; Action filter2Assertions = null; _filter2.Invoked += (sender, tuple) => { var attr = tuple.Item1; var vmContext = tuple.Item2; var context = vmContext.HubContext; var callType = context.CallType; var connectionId = context.CallerContext.ConnectionId; var testVMPropValue = (context.Data as JObject)[nameof(FilterTestVM.Property)]; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); filter2Assertions = () => { Assert.AreEqual("Request_VM", callType); Assert.AreEqual(hub.ConnectionId, connectionId); Assert.AreEqual("World", testVMPropValue); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(0, pipelineData.Count); Assert.AreEqual(_vm, vmContext.Instance); Assert.AreEqual("Bienvenu", attr.Property); }; }; hub.RequestVM(nameof(FilterTestVM), _vmArg); Assert.AreEqual(nameof(FilterTestVM), vmName); Assert.AreEqual("World", vmData.Property.ToString()); filter1Assertions(); filter2Assertions(); }
public void Middleware_DisposeIntercepted() { VMController.Register <MiddlewareTestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <ExtractHeadersMiddleware>() .UseMiddleware <JwtBearerAuthenticationMiddleware>() .UseMiddleware <CustomMiddleware1>() .UseMiddleware <CustomMiddleware2>() .Create(); Action middleware1Assertions = null; _middleware1.Invoked += (sender, context) => { if (context.CallType != "Dispose_VM") { return; } var connectionId = context.CallerContext.ConnectionId; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); middleware1Assertions = () => { Assert.AreEqual(hub.ConnectionId, connectionId); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(0, pipelineData.Count); }; }; Action middleware2Assertions = null; _middleware2.Invoked += (sender, context) => { if (context.CallType != "Dispose_VM") { return; } var connectionId = context.CallerContext.ConnectionId; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); middleware2Assertions = () => { Assert.AreEqual(hub.ConnectionId, connectionId); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(1, pipelineData.Count); }; }; hub.RequestVM(nameof(MiddlewareTestVM), _vmArg); hub.DisposeVM(nameof(MiddlewareTestVM)); middleware1Assertions(); middleware2Assertions(); }
public void Middleware_RequestIntercepted() { VMController.Register <MiddlewareTestVM>(); var hub = new MockDotNetifyHub() .UseMiddleware <ExtractHeadersMiddleware>() .UseMiddleware <JwtBearerAuthenticationMiddleware>() .UseMiddleware <CustomMiddleware1>() .UseMiddleware <CustomMiddleware2>() .Create(); string vmName = null; dynamic vmData = null; hub.Response += (sender, e) => { vmName = e.Item1; vmData = JsonConvert.DeserializeObject <dynamic>(e.Item2); }; Action middleware1Assertions = null; _middleware1.Invoked += (sender, context) => { if (middleware1Assertions != null) { return; } var callType = context.CallType; var connectionId = context.CallerContext.ConnectionId; var testVMPropValue = (context.Data as JObject)[nameof(MiddlewareTestVM.Property)]; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); middleware1Assertions = () => { Assert.AreEqual("Request_VM", callType); Assert.AreEqual(hub.ConnectionId, connectionId); Assert.AreEqual("World", testVMPropValue); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(0, pipelineData.Count); }; }; Action middleware2Assertions = null; _middleware2.Invoked += (sender, context) => { if (middleware2Assertions != null) { return; } var callType = context.CallType; var connectionId = context.CallerContext.ConnectionId; var testVMPropValue = (context.Data as JObject)[nameof(MiddlewareTestVM.Property)]; var authToken = (context.Headers as JObject)["Authorization"].ToString(); var principalName = context.Principal.Identity.Name; var pipelineData = new Dictionary <string, object>(context.PipelineData); middleware2Assertions = () => { Assert.AreEqual("Request_VM", callType); Assert.AreEqual(hub.ConnectionId, connectionId); Assert.AreEqual("World", testVMPropValue); Assert.IsTrue(authToken.StartsWith("Bearer ")); Assert.AreEqual("admin", principalName); Assert.AreEqual(1, pipelineData.Count); }; }; hub.RequestVM(nameof(MiddlewareTestVM), _vmArg); Assert.AreEqual(nameof(MiddlewareTestVM), vmName); Assert.AreEqual("World", vmData.Property.ToString()); middleware1Assertions(); middleware2Assertions(); }