public async void BulkInsert_No_Errors() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResponse = new CreateResponse <ApiStudioResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiStudioResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStudioRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStudioResponseModel> >(mockResponse)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiStudioRequestModel>(); records.Add(new ApiStudioRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var result = (response as OkObjectResult).Value as List <ApiStudioResponseModel>; result.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioRequestModel>())); }
// TODO: Refactor with respect of Item.Action generalization void InvokeAdditionalActionOnItem(Item item) { if (item.Entity.IsTable) { StudioController.DesignTable(SelectedServer, item.Entity); } }
public async void Patch_No_Errors() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiStudioResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(true); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiStudioRequestModel>())) .Callback <int, ApiStudioRequestModel>( (id, model) => model.Address1.Should().Be("A") ) .Returns(Task.FromResult <UpdateResponse <ApiStudioResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioResponseModel>(new ApiStudioResponseModel())); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiStudioModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiStudioRequestModel>(); patch.Replace(x => x.Address1, "A"); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiStudioRequestModel>())); }
// Reload database list private void Async_ReloadDatabaseList(Object arg) { if (arg is IServer) { StudioController.RefreshServer(arg as IServer); InvokeInUI(() => { ReloadDatabaseList(true); }); } }
// TODO: Refactor with respect of Item.Action generalization void InvokeActionOnItem(Item item) { if (item.Entity.IsTable) { StudioController.EditTableData(SelectedServer, item.Entity); } else if (item.Entity.IsProcedure) { StudioController.ExecuteProcedure(SelectedServer, item.Entity); } else if (item.Entity.IsFunction) { StudioController.ExecuteFunction(SelectedServer, item.Entity); } }
// Reload objects in database private void Async_ReloadObjectsFromDatabase(Object arg) { var cmd = (ServerDatabaseCommand)arg; SetStatus("Reloading " + cmd.DatabaseName + "...", true); StudioController.RefreshDatabase(cmd.Server, cmd.DatabaseName); InvokeInUI(() => { DoSearch(true); }); SetStatus("Completed reloading " + cmd.DatabaseName); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WelcomeForm welcomeForm = new WelcomeForm(); Application.Run(welcomeForm); SearchForm searchForm = new SearchForm(); PersonController personController = new PersonController(searchForm); StudioController studioController = new StudioController(searchForm); MovieController movieController = new MovieController(searchForm, personController.People, studioController.Studios); MovieActorsController moviesActorsController = new MovieActorsController(searchForm, movieController.Movies, personController.People); MovieProducerController movieProducerController = new MovieProducerController(searchForm, movieController.Movies, personController.People); Application.Run(searchForm); }
public async void Get_Not_Exists() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioResponseModel>(null)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Delete_Errors() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async void Get_Exists() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiStudioServerResponseModel())); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var record = (response as OkObjectResult).Value as ApiStudioServerResponseModel; record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Update_NotFound() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiStudioResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiStudioRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiStudioResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioResponseModel>(null)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiStudioModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Update(default(int), new ApiStudioRequestModel()); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
// TODO: Refactor with respect of Item.Action generalization void InvokeDefaultOnItem(Item item) { if (item.Entity.IsTable) { StudioController.SelectFromTable(SelectedServer, item.Entity); } else if (item.Entity.IsProcedure) { StudioController.ModifyProcedure(SelectedServer, item.Entity); } else if (item.Entity.IsFunction) { StudioController.ModifyFunction(SelectedServer, item.Entity); } else if (item.Entity.IsView) { StudioController.SelectFromView(SelectedServer, item.Entity); } }
public async void All_Not_Exists() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiStudioResponseModel> >(new List <ApiStudioResponseModel>())); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiStudioResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public void ReloadServers() { log.Info("Reloading Servers - initiated by user"); var servers = StudioController.ListServers(); _serverList.Clear(); foreach (var item in ItemFactory.BuildServer(servers)) { _serverList.Add(item); } log.Info("Reloading Servers - loaded:" + _serverList.Count + " servers."); cbServer.ItemsSource = _serverList; if (_serverList.Count == 1) { cbServer.SelectedIndex = 0; } }
public async void Patch_Record_Not_Found() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioResponseModel>(null)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiStudioRequestModel>(); patch.Replace(x => x.Address1, "A"); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public void Logout_Click(object sender, EventArgs e) { loginId = Convert.ToInt32(HttpContext.Current.Request.Cookies["Press3Cookie"]["LoginId"]); agentId = Convert.ToInt32(HttpContext.Current.Request.Cookies["Press3Cookie"]["AgentId"]); roleId = Convert.ToByte(Session["RoleId"].ToString()); accountId = Convert.ToInt32(Session["AccountId"].ToString()); Session.Clear(); Session.Abandon(); LogoutSession(loginId, agentId); if (roleId == 1) { StudioController studioControllerObj = new StudioController(); studioControllerObj.ManagerDashBoardCounts(MyConfig.MyConnectionString, accountId, "AgentLogout"); } if (HttpContext.Current.Request.Cookies["Press3Cookie"] != null) { HttpCookie authCookie = new HttpCookie("Press3Cookie", ""); authCookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(authCookie); } Response.Redirect("/Login.aspx"); }
public async void Create_No_Errors() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiStudioServerResponseModel> .CreateResponse(null as ApiStudioServerResponseModel); mockResponse.SetRecord(new ApiStudioServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStudioServerResponseModel> >(mockResponse)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiStudioServerRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiStudioServerResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())); }
private void UserControl_Loaded(Object sender, RoutedEventArgs e) { try { log.Info("XAML Loaded..."); var scroll = itemsControl.FindChild <ScrollContentPresenter>(); _userPref = UserPreferencesStorage.Load(); _cfg = _persistor.Restore <Config.DogConfig>(_userPref); UpdateDetector = new UpdateDetector(_userPref); UpdateDetector.NewVersionFound += UpdateDetector_NewVersionFound; _processor.RequestFailed += new Action <Request, Exception>(_processor_RequestFailed); StudioController.Initialise(); StudioController.SetConfiguration(_cfg); StudioController.OnServersAdded += StudioController_OnServersAdded; StudioController.OnServersRemoved += StudioController_OnServersRemoved; StudioController.OnDatabaseChanged += StudioController_OnDatabaseChanged; StudioController.ShowYourself += new System.Action(StudioController_ShowYourself); ReloadServers(); ResultsFontSize = _cfg.FontSize; var lastSrvName = _userPref.GetByName(UserPref_LastSelectedServer); RestoreLastSearchTextFromUserProfile(); // select first server if ((cbServer.SelectedIndex == -1) && (cbServer.Items.Count > 1)) { cbServer.SelectedIndex = 0; } } catch (Exception ex) { log.Error("Fatal error loading main control:" + ex.Message, ex); } }
public async void BulkInsert_Errors() { StudioControllerMockFacade mock = new StudioControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiStudioServerResponseModel> >(null as ApiStudioServerResponseModel); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStudioServerResponseModel> >(mockResponse.Object)); StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiStudioServerRequestModel>(); records.Add(new ApiStudioServerRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())); }
void ReloadDatabaseList(bool keepSameDatabase, bool setFocus = true) { string databaseName = string.Empty; try { var sel = SelectedServer; if (keepSameDatabase) { databaseName = SelectedDatabase; } if (sel != null) { cbDatabase.ItemsSource = ItemFactory.BuildDatabase(StudioController.ListDatabase(sel)); _databaseChangedByUser = false; // changed server - try to restore database user worked with last time if (string.IsNullOrEmpty(databaseName)) { databaseName = _userPref.GetByName(UserPref_ServerDatabase + sel.ServerName); } var previousDatabaseWasFound = false; if ((databaseName != null) && (cbDatabase.Items != null)) { foreach (Item item in cbDatabase.ItemsSource) { if (item.Name == databaseName) { cbDatabase.SelectedValue = item; previousDatabaseWasFound = true; break; } } } // select the first database if a database previously chosen by user does not exist on a server any more if (!previousDatabaseWasFound && (cbDatabase.Items != null) && (cbDatabase.Items.Count > 0)) { cbDatabase.SelectedIndex = 0; } _databaseChangedByUser = true; _userPref.StoreByName(UserPref_LastSelectedServer, sel.ServerName); _userPref.Save(); if (previousDatabaseWasFound) { // we managed to find our database - restore search text RestoreLastSearchTextFromUserProfile(); if (setFocus) { txtSearch.Focus(); } } else { ClearSearchText(); if (setFocus) { cbDatabase.Focus(); } } } else { ClearSearchText(); } } catch (Exception ex) { log.Error("Server Selection:" + ex.Message, ex); } }
private void Async_PerformSearch(Object arg) { if (arg == null) { return; } var par = (SearchAsyncParam)arg; // new request was added - this one is outdated if (par.SequenceNumber < _requestSequenceNumber) { return; } if (SameAsPreviousSearch(par)) { return; } SetStatus("Searching '" + par.Text + "' in " + par.Database, true); var result = StudioController.Find(par.Srv, par.Database, par.Text, _cfg.LimitSearch); // new request was added - this one is outdated if (par.SequenceNumber < _requestSequenceNumber) { log.Info("Cancelled search request because new request was added. " + par.Text); return; } SetStatus("Found " + result.Count + " objects"); InvokeInUI(() => { log.Info("Updating UI items"); var analyzer = new PerformanceAnalyzer(); var items = ItemFactory.BuildFromEntries(result); itemsControl.ItemsSource = items; itemsControl.SelectedIndex = -1; itemsControl.ScrollIntoView(itemsControl.SelectedItem); if (items.Count == 0) { gridEmptyResult.Visibility = System.Windows.Visibility.Visible; itemsControl.Visibility = System.Windows.Visibility.Collapsed; } else { gridEmptyResult.Visibility = System.Windows.Visibility.Collapsed; itemsControl.Visibility = System.Windows.Visibility.Visible; } log.Performance("UI items updated", analyzer.Result); analyzer.Stop(); }); if (result.Count == 0) { SetStatus("Found nothing. Try to refresh"); } else if (result.Count == 1) { SetStatus("Found exactly one object"); } else { SetStatus("Found " + result.Count + " objects "); } }
// TODO: Refactor with respect of Item.Action generalization void InvokeNavigationOnItem(Item item) { StudioController.NavigateObject(SelectedServer, item.Entity); }