public void SimpleListVM_Update() { var vmController = new MockVMController <SimpleListVM>(_simpleListVM); var vmEmployees = vmController.RequestVM(); vmController.UpdateVM(new Dictionary <string, object>() { { "Update", "{ Id: 1, FirstName: 'Teddy' }" } }); vmController.UpdateVM(new Dictionary <string, object>() { { "Update", "{ Id: 1, LastName: 'Lee' }" } }); vmController.UpdateVM(new Dictionary <string, object>() { { "Update", "{ Id: 3, FirstName: 'Beth' }" } }); vmController.UpdateVM(new Dictionary <string, object>() { { "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_ShowNotification() { var vmController = new MockVMController <SimpleListVM>(_simpleListVM); var vmEmployees = vmController.RequestVM(); var employees = _employeeService.GetAll(); Assert.AreEqual(3, employees.Count); var response = vmController.UpdateVM(new Dictionary <string, object>() { { "Remove", "2" } }); Assert.AreEqual(true, response["ShowNotification"]); var response2 = vmController.UpdateVM(new Dictionary <string, object>() { { "Update", "{ Id: 1, LastName: 'Lee' }" } }); Assert.AreEqual(null, response2); var response3 = vmController.UpdateVM(new Dictionary <string, object>() { { "Remove", "1" } }); Assert.AreEqual(true, response3["ShowNotification"]); }
public void MasterDetailsVM_Request() { var vmController = new MockVMController <MasterVM>(_masterVM); var response = vmController.RequestVM(_detailsVMId); Assert.AreEqual(int.MaxValue, response.GetVMProperty <int>("Value")); }
public async Task HelloWorldReactiveVM_UpdateAsync() { var vmController = new MockVMController <HelloWorldReactiveVMAsync>(); vmController.RequestVM(); dynamic data1 = null; vmController.OnResponse += (sender, e) => { dynamic data = JObject.Parse(e); if (data.NameLengthAsync != null) { if (data1 == null) { data1 = data; } } }; var update = new Dictionary <string, object>() { { "FirstName", "John" } }; var response1 = vmController.UpdateVM(update); Assert.AreEqual("John World", response1["FullName"]); await Task.Delay(2000); Assert.AreEqual(10, data1.NameLengthAsync.Value); }
public void HelloWorldReactiveNoBaseVM_Request() { var vmController = new MockVMController <HelloWorldReactiveNoBaseVM>(); var response = vmController.RequestVM(); Assert.AreEqual("Hello", response.GetVMProperty <string>("FirstName")); Assert.AreEqual("World", response.GetVMProperty <string>("LastName")); Assert.AreEqual("Hello World", response.GetVMProperty <string>("FullName")); }
public void HelloWorldReactiveVM_Internal() { var vmController = new MockVMController <HelloWorldReactiveVM>(); var response = vmController.RequestVM(); // Internal properties should not be sent to the client. Assert.IsNull(response.VMData["Internal1"]); Assert.IsNull(response.VMData["Internal2"]); }
public void SerializerVM_Serialize() { var vmController = new MockVMController <SerializerVM>(); var response = vmController.RequestVM(); Assert.AreEqual("Hello", response.GetVMProperty <string>("FirstName")); Assert.AreEqual("World", response.GetVMProperty <string>("LastName")); Assert.AreEqual("Hello World", response.GetVMProperty <string>("FullName")); }
public void RuntimeVM_RequestWithNamespace() { var vmController = new MockVMController <BaseVM>(); var response = vmController.RequestVM("HelloWorldRuntimeVM", JObject.Parse("{ namespace: 'MyNamespace' }")); Assert.AreEqual("John", response.GetVMProperty <string>("FirstName")); Assert.AreEqual("Hancock", response.GetVMProperty <string>("LastName")); Assert.AreEqual("John Hancock", response.GetVMProperty <string>("FullName")); }
public void HelloWorldReactiveNoBaseVM_PushUpdates() { int updateCounter = 0; var vmController = new MockVMController <HelloWorldReactiveNoBaseVM>(new HelloWorldReactiveNoBaseVM(true)); vmController.OnResponse += (sender, e) => updateCounter++; vmController.RequestVM(); System.Threading.Thread.Sleep(1000); Assert.IsTrue(updateCounter >= 4); }
public void HelloWorldReactiveVM_Dispose() { bool dispose = false; var vm = new HelloWorldReactiveVM(); vm.Disposed += (sender, e) => dispose = true; var vmController = new MockVMController <HelloWorldReactiveVM>(vm); vmController.RequestVM(); vmController.DisposeVM(); Assert.IsTrue(dispose); }
public void MasterDetailsVM_SubVMCreated() { object subVM = null; bool subVMCreated = false; _masterVM.SubVMCreated += (sender, e) => { subVM = sender; subVMCreated = true; }; var vmController = new MockVMController <MasterVM>(_masterVM); vmController.RequestVM(_detailsVMId); Assert.IsTrue(subVMCreated); Assert.IsTrue(subVM is DetailsVM); }
public void MasterDetailsNoBaseVM_SubVMDisposing() { object subVM = null; bool subVMDisposing = false; _masterVM.SubVMDisposing += (sender, e) => { subVM = sender; subVMDisposing = true; }; var vmController = new MockVMController <MasterNoBaseVM>(_masterVM); vmController.RequestVM(_detailsVMId); vmController.DisposeVM(_detailsVMId); Assert.IsTrue(subVMDisposing); Assert.IsTrue(subVM is DetailsNoBaseVM); }
public void MasterDetailsVM_Update() { var vmController = new MockVMController <MasterVM>(_masterVM); vmController.RequestVM(_detailsVMId); var update = new Dictionary <string, object>() { { "Value", "99" } }; vmController.UpdateVM(update, _detailsVMId); Assert.AreEqual(99, (_masterVM.GetSubVM(nameof(DetailsVM)) as DetailsVM).Value); }
public void SimpleListVM_Read() { var vmController = new MockVMController <SimpleListVM>(_simpleListVM); var vmEmployees = vmController .RequestVM() .GetVMProperty <List <EmployeeRecord> >("Employees"); Assert.IsNotNull(vmEmployees); Assert.AreEqual(3, vmEmployees.Count); Assert.AreEqual("John", vmEmployees[0].FirstName); Assert.AreEqual("Doe", vmEmployees[0].LastName); Assert.AreEqual("Mary", vmEmployees[1].FirstName); Assert.AreEqual("Sue", vmEmployees[1].LastName); Assert.AreEqual("Bob", vmEmployees[2].FirstName); Assert.AreEqual("Smith", vmEmployees[2].LastName); }
public void SimpleListVM_Create() { var vmController = new MockVMController <SimpleListVM>(_simpleListVM); vmController.RequestVM(); vmController.UpdateVM(new Dictionary <string, object>() { { "Add", "Peter Chen" } }); var employee = _employeeService.GetAll().Last(); Assert.AreEqual("Peter", employee.FirstName); Assert.AreEqual("Chen", employee.LastName); }
public void HelloWorldReactiveVM_UpdateAsync() { var vmController = new MockVMController <HelloWorldReactiveVM>(); vmController.RequestVM(); var autoResetEvent = new AutoResetEvent(false); dynamic data1 = null; dynamic data2 = null; vmController.OnResponse += (sender, e) => { dynamic data = JObject.Parse(e); if (data.NameLengthAsync != null) { if (data1 == null) { data1 = data; } else { data2 = data; autoResetEvent.Set(); } } }; var update = new Dictionary <string, object>() { { "FirstName", "John" } }; var response1 = vmController.UpdateVM(update); update = new Dictionary <string, object>() { { "LastName", "Doe" } }; var response2 = vmController.UpdateVM(update); Assert.AreEqual("John World", response1["FullName"]); Assert.AreEqual("John Doe", response2["FullName"]); autoResetEvent.WaitOne(5000); Assert.AreEqual(10, data1.NameLengthAsync.Value); Assert.AreEqual(8, data2.NameLengthAsync.Value); }
public void SerializerVM_Deserialize() { var vmController = new MockVMController <SerializerVM>(); vmController.RequestVM(); var response = vmController.UpdateVM(new Dictionary <string, object>() { { "FirstName", "John" } }); Assert.AreEqual("John World", response["FullName"]); response = vmController.UpdateVM(new Dictionary <string, object>() { { "LastName", "Hancock" } }); Assert.AreEqual("John Hancock", response["FullName"]); }
public void SimpleListVM_Delete() { var vmController = new MockVMController <SimpleListVM>(_simpleListVM); var vmEmployees = vmController.RequestVM(); var employees = _employeeService.GetAll(); Assert.AreEqual(3, employees.Count); Assert.IsTrue(employees.Exists(i => i.Id == 2)); vmController.UpdateVM(new Dictionary <string, object>() { { "Remove", "2" } }); employees = _employeeService.GetAll(); Assert.AreEqual(2, employees.Count); Assert.IsFalse(employees.Exists(i => i.Id == 2)); }
public void HelloWorldReactiveNoBaseVM_Update() { var vmController = new MockVMController <HelloWorldReactiveNoBaseVM>(); vmController.RequestVM(); var update = new Dictionary <string, object>() { { "FirstName", "John" } }; var response1 = vmController.UpdateVM(update); update = new Dictionary <string, object>() { { "LastName", "Doe" } }; var response2 = vmController.UpdateVM(update); Assert.AreEqual("John World", response1["FullName"]); Assert.AreEqual("John Doe", response2["FullName"]); }