public void HelloWorldVM() { VMController.RegisterAssembly <BaseVM>(typeof(HelloWorldVM).Assembly); var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(HelloWorldVM).Name); Assert.AreEqual(typeof(HelloWorldVM).Name, _vmId); var vm = GetVM <HelloWorldVM>(); Assert.IsNotNull(vm); Assert.AreEqual("Hello", vm.FirstName); Assert.AreEqual("World", vm.LastName); Assert.AreEqual("Hello World", vm.FullName); var update = new Dictionary <string, object>() { { "FirstName", "John" } }; vmController.OnUpdateVM("conn1", typeof(HelloWorldVM).Name, update); Assert.IsNotNull(VMData); Assert.AreEqual("John World", VMData["FullName"]); update = new Dictionary <string, object>() { { "LastName", "Doe" } }; vmController.OnUpdateVM("conn1", typeof(HelloWorldVM).Name, update); Assert.IsNotNull(VMData); Assert.AreEqual("John Doe", VMData["FullName"]); }
public void ControlTypesVM_SearchBox() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.IsTrue(String.IsNullOrEmpty(vm.SearchBox)); Assert.IsNotNull(vm.SearchResults); Assert.AreEqual(0, vm.SearchResults.Count()); Assert.IsFalse(string.IsNullOrEmpty(vm.SearchBoxPlaceHolder)); var update = new Dictionary <string, object>() { { "SearchBox", "m" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.AreEqual(2, VMData["SearchResults"].ToList().Count); update = new Dictionary <string, object>() { { "SearchBox", "ma" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.AreEqual("Mars", VMData["SearchResults"].ToList().First()); }
public void ControlTypesVM_CheckBox() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.IsTrue(vm.CheckBoxResult.Contains("enabled")); Assert.IsTrue(vm.EnableMeCheckBox); Assert.IsTrue(vm.ShowMeCheckBox); var update = new Dictionary <string, object>() { { "EnableMeCheckBox", "false" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsTrue(VMData["CheckBoxResult"].ToString().Contains("disabled")); update = new Dictionary <string, object>() { { "ShowMeCheckBox", "false" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsFalse(String.IsNullOrEmpty(VMData["CheckBoxResult"].ToString())); }
public void VMController_OnUpdateVM() { var vmController = new VMController(TestResponse, _vmFactory); vmController.OnRequestVM("conn1", typeof(UnitTestVM).Name); vmController.OnUpdateVM("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"]); vmController.OnRequestVM("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 void MasterDetailsVM_Update() { var vmController = new VMController(_response.Handler); vmController.OnRequestVM("conn1", $"{nameof(MasterVM)}.{nameof(DetailsVM)}"); vmController.OnUpdateVM("conn1", $"{nameof(MasterVM)}.{nameof(DetailsVM)}", _response.MockAction("Value", "99")); Assert.AreEqual(99, (_masterVM.GetSubVM(nameof(DetailsVM)) as DetailsVM).Value); }
public void SimpleListVM_Update() { var vmController = new VMController(_response.Handler); vmController.OnRequestVM("conn1", typeof(SimpleListVM).Name); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Update", "{ Id: 1, FirstName: 'Teddy' }")); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Update", "{ Id: 1, LastName: 'Lee' }")); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Update", "{ Id: 3, FirstName: 'Beth' }")); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Update", "{ Id: 3, LastName: 'Larson' }")); var employee = _employeeService.GetById(1); Assert.AreEqual("Teddy", employee.FirstName); Assert.AreEqual("Lee", employee.LastName); employee = _employeeService.GetById(3); Assert.AreEqual("Beth", employee.FirstName); Assert.AreEqual("Larson", employee.LastName); }
public void SimpleListVM_Create() { var vmController = new VMController(_response.Handler); vmController.OnRequestVM("conn1", typeof(SimpleListVM).Name); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Add", "Peter Chen")); var employee = _employeeService.GetAll().Last(); Assert.AreEqual("Peter", employee.FirstName); Assert.AreEqual("Chen", employee.LastName); }
public void BetterListVM_Update() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(BetterListVM).Name); var update = new Dictionary <string, object>() { { "Employees.$1.FirstName", "Teddy" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); update = new Dictionary <string, object>() { { "Employees.$1.LastName", "Lee" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); update = new Dictionary <string, object>() { { "Employees.$3.FirstName", "Beth" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); update = new Dictionary <string, object>() { { "Employees.$3.LastName", "Larson" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); var employee = _model.GetAllRecords().First(); Assert.AreEqual("Teddy", employee.FirstName); Assert.AreEqual("Lee", employee.LastName); employee = _model.GetAllRecords().Last(); Assert.AreEqual("Beth", employee.FirstName); Assert.AreEqual("Larson", employee.LastName); }
public void ControlTypesVM_Button() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.IsFalse(vm.ButtonClicked); Assert.AreEqual(0, vm.ClickCount); var update = new Dictionary <string, object>() { { "ButtonClicked", "true" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.AreEqual(1, VMData["ClickCount"]); vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.AreEqual(2, VMData["ClickCount"]); }
public void SimpleListVM_Delete() { var vmController = new VMController(_response.Handler); vmController.OnRequestVM("conn1", typeof(SimpleListVM).Name); var employees = _employeeService.GetAll(); Assert.AreEqual(3, employees.Count); Assert.IsTrue(employees.Exists(i => i.Id == 2)); vmController.OnUpdateVM("conn1", typeof(SimpleListVM).Name, _response.MockAction("Remove", "2")); employees = _employeeService.GetAll(); Assert.AreEqual(2, employees.Count); Assert.IsFalse(employees.Exists(i => i.Id == 2)); }
public void BetterListVM_Create() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(BetterListVM).Name); var update = new Dictionary <string, object>() { { "Add", "{ \"FirstName\": \"Peter\", \"LastName\": \"Chen\"}" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); var employee = _model.GetAllRecords().Last(); Assert.AreEqual("Peter", employee.FirstName); Assert.AreEqual("Chen", employee.LastName); }
public void ControlTypesVM_RadioButton() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.AreEqual("label-success", vm.RadioButtonStyle); Assert.AreEqual("green", vm.RadioButtonValue); var update = new Dictionary <string, object>() { { "RadioButtonValue", "yellow" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsTrue(VMData["RadioButtonStyle"].ToString().Contains("label-warning")); }
public void ControlTypesVM_TextBox() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.IsTrue(String.IsNullOrEmpty(vm.TextBoxValue)); Assert.IsTrue(String.IsNullOrEmpty(vm.TextBoxResult)); Assert.IsFalse(string.IsNullOrEmpty(vm.TextBoxPlaceHolder)); var update = new Dictionary <string, object>() { { "TextBoxValue", "text box test" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsTrue(VMData["TextBoxResult"].ToString().Contains("text box test")); }
public void BetterListVM_Delete() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(BetterListVM).Name); var employees = _model.GetAllRecords(); Assert.AreEqual(3, employees.Count); Assert.IsTrue(employees.Exists(i => i.Id == 2)); var update = new Dictionary <string, object>() { { "Remove", "2" } }; vmController.OnUpdateVM("conn1", typeof(BetterListVM).Name, update); Assert.AreEqual(2, employees.Count); Assert.IsFalse(employees.Exists(i => i.Id == 2)); }
public void ControlTypesVM_DropDownList() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.AreEqual(4, vm.DropDownOptions.Count); Assert.AreEqual(1, vm.DropDownOptions[0].Id); Assert.AreEqual(2, vm.DropDownOptions[1].Id); Assert.AreEqual(3, vm.DropDownOptions[2].Id); Assert.AreEqual(4, vm.DropDownOptions[3].Id); var update = new Dictionary <string, object>() { { "DropDownValue", 2 } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsTrue(VMData["DropDownResult"].ToString().Contains("Object Two")); }
public void ControlTypesVM_SimpleDropDownList() { var vmController = new VMController(TestResponse); vmController.OnRequestVM("conn1", typeof(ControlTypesVM).Name); var vm = GetVM <ControlTypesVM>(); Assert.AreEqual(4, vm.SimpleDropDownOptions.Count); Assert.AreEqual("One", vm.SimpleDropDownOptions[0]); Assert.AreEqual("Two", vm.SimpleDropDownOptions[1]); Assert.AreEqual("Three", vm.SimpleDropDownOptions[2]); Assert.AreEqual("Four", vm.SimpleDropDownOptions[3]); var update = new Dictionary <string, object>() { { "SimpleDropDownValue", "Two" } }; vmController.OnUpdateVM("conn1", typeof(ControlTypesVM).Name, update); Assert.IsTrue(VMData["SimpleDropDownResult"].ToString().Contains("Two")); }
public JObject UpdateVM(Dictionary <string, object> update, string vmId = null) { _response.Reset(); _vmController.OnUpdateVM("conn1", vmId ?? _vmId, update); return(_response.VMData); }
public async Task <string> Update_VM( string vmId, [FromQuery] string vmArg, [FromBody] Dictionary <string, object> vmData, [FromServices] IVMFactory vmFactory, [FromServices] IHubServiceProvider hubServiceProvider, [FromServices] IVMServiceScopeFactory serviceScopeFactory, [FromServices] IHubPipeline hubPipeline, [FromServices] IPrincipalAccessor principalAccessor) { var taskCompletionSource1 = new TaskCompletionSource <string>(); var taskCompletionSource2 = new TaskCompletionSource <string>(); var vmController = new VMController((arg1, arg2, arg3) => { if (!taskCompletionSource1.TrySetResult(arg3)) { taskCompletionSource2.TrySetResult(arg3); } }, vmFactory, serviceScopeFactory.CreateScope()) { ResponseVMFilter = CreateRespondingVMFilter(hubPipeline, vmId, vmData) }; 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); hubPipeline.RunMiddlewares(hubContext, ctx => { vmController.OnRequestVM(connectionId, ctx.VMId, ctx.Data); return(Task.CompletedTask); }); } catch (Exception ex) { var finalEx = hubPipeline.RunExceptionMiddleware(httpCallerContext, ex); if (finalEx is OperationCanceledException == false) { taskCompletionSource1.TrySetResult(DotNetifyHub.SerializeException(finalEx)); } } await taskCompletionSource1.Task; try { var hubContext = new DotNetifyHubContext(httpCallerContext, nameof(Update_VM), vmId, vmData, BuildHeaders(), httpCallerContext.User); vmController.UpdateVMFilter = CreateVMFilter(hubContext, hubPipeline); hubPipeline.RunMiddlewares(hubContext, ctx => { vmController.OnUpdateVM(connectionId, ctx.VMId, ctx.Data as Dictionary <string, object>); vmController.Dispose(); return(Task.CompletedTask); }); } catch (Exception ex) { var finalEx = hubPipeline.RunExceptionMiddleware(httpCallerContext, ex); if (finalEx is OperationCanceledException == false) { taskCompletionSource2.TrySetResult(DotNetifyHub.SerializeException(finalEx)); } } return(await taskCompletionSource2.Task); }