public static ProvisionerModel ToProvisionerModel(this DepartmentEmulateUser src)
        {
            var dest = new ProvisionerModel();

            dest.JobNumber = src.JobNumber;
            dest.Reason    = src.Reason;
            dest.UserId    = src.UserId;
            return(dest);
        }
        public void DepartmentEmulateUser_ReturnsSuccessViewResult()
        {
            var emulateUser = new DepartmentEmulateUser {
                JobNumber = "123", Reason = "Test", UserId = "XX001122"
            };
            var controller = SystemUnderTest();

            mockProvisionerService.Setup(e => e.EmulateAtNextLogon(It.IsAny <ProvisionerModel>())).Returns(true);

            var result = controller.DepartmentEmulateUser(emulateUser);

            Assert.IsNotNull(result);
            Assert.IsNotNull(((System.Web.Mvc.ViewResultBase)(result)).Model);
            Assert.IsNotNull(((DepartmentEmulateUser)((System.Web.Mvc.ViewResultBase)(result)).Model));

            Assert.AreEqual("123", ((DepartmentEmulateUser)((System.Web.Mvc.ViewResultBase)(result)).Model).JobNumber);
        }
        public void DepartmentEmulateUser_ReturnsErrorViewResult()
        {
            var emulateUser = new DepartmentEmulateUser {
                JobNumber = "123", Reason = "Test", UserId = "XX001122"
            };
            var controller = SystemUnderTest();

            mockProvisionerService.Setup(e => e.EmulateAtNextLogon(It.IsAny <ProvisionerModel>())).Returns(false);

            var result = controller.DepartmentEmulateUser(emulateUser);

            Assert.IsNotNull(result);
            Assert.IsTrue(((ViewResult)result).ViewData.ModelState.Values.Count == 1);
            var modelState = ((ViewResult)result).ViewData.ModelState.Values.GetEnumerator();

            modelState.MoveNext();
            Assert.AreEqual("User Emulate Failed.", modelState.Current.Errors[0].ErrorMessage);
        }
        public ActionResult DepartmentEmulateUser(DepartmentEmulateUser emulateUser)
        {
            if (ModelState.IsValid)
            {
                ProvisionerModel emulate = emulateUser.ToProvisionerModel();    //   MappingEngine.Map<ProvisionerModel>(emulateUser);
                try
                {
                    var result = ProvisionerService.EmulateAtNextLogon(emulate);
                    if (result)
                    {
                        AddInformationMessage("User will be emulated at next logon. Restart your browser");
                        return(View(emulateUser));
                    }
                }
                catch (ServiceValidationException)
                {
                    AddErrorMessage("User Emulate Failed.");
                    return(View(emulateUser));
                }
            }

            AddErrorMessage("User Emulate Failed.");
            return(View(emulateUser));
        }
        public ActionResult DepartmentEmulateUser()
        {
            var model = new DepartmentEmulateUser();

            return(View(model));
        }