Пример #1
0
        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();
        }
Пример #2
0
        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()));
        }
Пример #3
0
        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());
        }
Пример #4
0
        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"]);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        public void MasterDetailsVM_Request()
        {
            var vmController = new VMController(_response.Handler);

            vmController.OnRequestVM("conn1", $"{nameof(MasterVM)}.{nameof(DetailsVM)}");

            Assert.AreEqual($"{nameof(MasterVM)}.{nameof(DetailsVM)}", _response.VMId);

            var vm = _response.GetVM <DetailsVM>();

            Assert.IsNotNull(vm);
            Assert.AreEqual(int.MaxValue, vm.Value);
        }
Пример #8
0
        public void MasterDetailsVM_SubVMCreated()
        {
            object subVM        = null;
            bool   subVMCreated = false;

            _masterVM.SubVMCreated += (sender, e) => { subVM = sender; subVMCreated = true; };

            var vmController = new VMController(_response.Handler);

            vmController.OnRequestVM("conn1", $"{nameof(MasterVM)}.{nameof(DetailsVM)}");

            Assert.IsTrue(subVMCreated);
            Assert.IsTrue(subVM is DetailsVM);
        }
Пример #9
0
        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));
        }
Пример #10
0
        public void BetterListVM_Read()
        {
            var vmController = new VMController(TestResponse);

            vmController.OnRequestVM("conn1", typeof(BetterListVM).Name);

            var vmEmployees = 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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        public void VMController_OnRequestVM()
        {
            var vmController = new VMController(TestResponse, _vmFactory);

            vmController.OnRequestVM("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();
        }
Пример #13
0
        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);
        }
Пример #14
0
        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"));
        }
Пример #15
0
        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>();
            var vmController         = new VMController((arg1, arg2, arg3) => taskCompletionSource.TrySetResult(arg3), 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);

                hubPipeline.RunMiddlewares(hubContext, ctx =>
                {
                    vmController.OnRequestVM(connectionId, ctx.VMId, ctx.Data);
                    vmController.Dispose();
                    return(Task.CompletedTask);
                });
            }
            catch (Exception ex)
            {
                var finalEx = hubPipeline.RunExceptionMiddleware(httpCallerContext, ex);
                if (finalEx is OperationCanceledException == false)
                {
                    taskCompletionSource.TrySetResult(DotNetifyHub.SerializeException(finalEx));
                }
            }

            return(await taskCompletionSource.Task);
        }
Пример #16
0
        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);
        }
Пример #17
0
        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"));
        }
Пример #18
0
        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));
        }
Пример #19
0
        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);
        }
Пример #20
0
        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"]);
        }
Пример #21
0
        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"));
        }
Пример #22
0
        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"));
        }
Пример #23
0
 public Response RequestVM()
 {
     _response.Reset();
     _vmController.OnRequestVM("conn1", _vmId);
     return(_response);
 }
Пример #24
0
 public Response RequestVM()
 {
     _response.Reset();
     _vmController.OnRequestVM(_connectionId, _vmId);
     return(_response);
 }