public void TestBindCommandUnauthorized() { var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var bindRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.BindAccountAsync(async studentId => { bindRequested = true; return(new ServiceResult { Status = ServiceResultStatus.Unauthorized }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.BindCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsFalse(dialogShown); Assert.IsTrue(bindRequested); }
private void PopulateSelectListsToModel(BindingViewModel viewModel, IBinding binding) { if (viewModel != null) { if (viewModel.SelectedWebsiteId > 0) { binding.Website = WebsiteService.GetById(viewModel.SelectedWebsiteId); } if (viewModel.SelectedServerIds.Any()) { if (binding.Servers == null) { binding.Servers = new HashSet <IServer>(); } foreach (long selectedServerId in viewModel.SelectedServerIds) { binding.Servers.Add(ServerService.GetById(selectedServerId)); } } if (viewModel.SelectedEnvironmentIds.Any()) { if (binding.Environments == null) { binding.Environments = new HashSet <IEnvironment>(); } foreach (long selectedEnvironmentId in viewModel.SelectedEnvironmentIds) { binding.Environments.Add(EnvironmentService.GetById(selectedEnvironmentId)); } } } }
public ActionResult Create() { var viewModel = new BindingViewModel(); viewModel.Websites = WebsiteService.GetAll().ToList(); viewModel.SelectableServers = ServerService.GetAll().ToList(); viewModel.SelectableEnvironments = EnvironmentService.GetAll().ToList(); return(View(viewModel)); }
public ActionResult Edit(BindingViewModel viewModel, int?page) { if (ModelState.IsValid) { var binding = AutoMapper.Mapper.Map <BindingViewModel, IBinding>(viewModel); PopulateSelectListsToModel(viewModel, binding); BindingService.CreateOrUpdate(binding); return(RedirectToAction("Index", new { page })); } return(View(viewModel)); }
public List <BindingViewModel> ListBySite(Guid SiteId, ApiCall call) { List <BindingViewModel> result = new List <BindingViewModel>(); var list = GlobalDb.Bindings.GetByWebSite(SiteId); foreach (var item in list) { BindingViewModel model = new BindingViewModel(item); model.EnableSsl = HasSsl(model.FullName); result.Add(model); } return(result); }
public void TestCheckCommandSucceeded() { var studentIdToRequest = "Student ID"; var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var studentIdRequested = ""; var getRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.GetStudentByStudentIdAsync(async studentId => { getRequested = true; studentIdRequested = studentId; return(new ServiceResult <Student> { Status = ServiceResultStatus.OK, Result = new Student { StudentId = studentIdToRequest } }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.StudentId = studentIdToRequest; bindingViewModel.CheckCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsFalse(dialogShown); Assert.IsTrue(getRequested); Assert.AreEqual(studentIdToRequest, studentIdRequested); Assert.AreEqual(studentIdToRequest, bindingViewModel.Student.StudentId); }
public void TestBindCommandSucceeded() { var studentIdToRequest = "Student ID"; var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = sourcePageType == typeof(MyUvpPage) && parameter == null && navigationTransition == NavigationTransition .EntranceNavigationTransition); var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var studentIdRequested = ""; var bindRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.BindAccountAsync(async studentId => { bindRequested = true; studentIdRequested = studentId; return(new ServiceResult { Status = ServiceResultStatus.NoContent }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.StudentId = studentIdToRequest; bindingViewModel.BindCommand.Execute(null); Assert.IsTrue(rootFrameNavigated); Assert.IsFalse(dialogShown); Assert.IsTrue(bindRequested); Assert.AreEqual(studentIdToRequest, studentIdRequested); }
public void TestBindCommandOther() { var messageToShow = "Error Message"; var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var messageShown = ""; var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); var bindRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.BindAccountAsync(async studentId => { bindRequested = true; return(new ServiceResult { Status = ServiceResultStatus.Exception, Message = messageToShow }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.BindCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsTrue(dialogShown); Assert.AreEqual( UvpClient.App.HttpClientErrorMessage + messageToShow, messageShown); Assert.IsTrue(bindRequested); }
public void TestCheckCommandError() { var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var messageShown = ""; var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); var bindRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.GetStudentByStudentIdAsync(async studentId => { bindRequested = true; return(new ServiceResult <Student> { Status = ServiceResultStatus.NotFound }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.CheckCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsTrue(dialogShown); Assert.AreEqual(BindingViewModel.CheckNotFoundErrorMessage, messageShown); Assert.IsTrue(bindRequested); }