private void ValidateActiveEntity(BaseEntity expectedEntity) { if (expectedEntity == null) { Assert.IsNull(WorkspaceSessionPersistanceManager.GetActiveEntity(), "There shouldn't be any active entity"); return; } var activeEntity = WorkspaceSessionPersistanceManager.GetActiveEntity(); Assert.AreEqual(expectedEntity.Id, activeEntity.Id, "Mismatched entity ids"); Assert.AreEqual(VisualStudio.Common.Utility.GetConcreteEntityType(expectedEntity), VisualStudio.Common.Utility.GetConcreteEntityType(activeEntity), "Mismatched entity types"); Assert.IsTrue(WorkspaceSessionPersistanceManager.IsActiveEntity(expectedEntity), "Entity isn't the active entity"); }
/// <summary> /// Retrieve all the entities related to the current user /// </summary> internal async System.Threading.Tasks.Task LoadMyItemsAsync() { if (string.IsNullOrEmpty(OctaneConfiguration.Url)) { // No URL which means it's the first time use. Mode = MainWindowMode.FirstTime; return; } // If we already loading wait for the runnung load to complete. if (Mode == MainWindowMode.LoadingItems) { return; } Mode = MainWindowMode.LoadingItems; try { OctaneServices octaneService; try { octaneService = OctaneServices.GetInstance(); } catch (Exception e) { if (e.GetBaseException().Message.Equals("Object not created")) { OctaneServices.Create(OctaneConfiguration.Url, OctaneConfiguration.SharedSpaceId, OctaneConfiguration.WorkSpaceId); } octaneService = OctaneServices.GetInstance(); await octaneService.Connect(); } _myItems.Clear(); _totalItems = 0; bool foundActiveItem = false; IEnumerable <BaseEntity> items = await octaneService.GetMyItems(); // when a user story is converted to feature it might still be in the list of my work items, // the plugins do not support features in my work, so we just remove those entities items = items.Where(entity => !WorkItem.SUBTYPE_FEATURE.Equals(entity.GetStringValue(CommonFields.SubType))); if (sublistsMap == null) { sublistsMap = createMyWorkItemsSublistsMap(); } else { cleanSubListsMap(sublistsMap); } foreach (BaseEntity entity in items) { var octaneItem = new OctaneItemViewModel(entity); _totalItems++; if (WorkspaceSessionPersistanceManager.IsActiveEntity(entity)) { foundActiveItem = true; OctaneItemViewModel.SetActiveItem(octaneItem); } MyWorkItemsSublist itemSublist; string concreteEntityType = Utility.GetConcreteEntityType(entity); if (sublistsMap.TryGetValue(concreteEntityType, out itemSublist)) { itemSublist.Items.Add(octaneItem); } } myWorkItemSublists = sublistsMap.Values.ToList(); if (!foundActiveItem) { OctaneItemViewModel.ClearActiveItem(); MainWindowCommand.Instance?.DisableActiveItemToolbar(); } IList <BaseEntity> comments = await octaneService.GetMyCommentItems(); foreach (BaseEntity comment in comments) { _totalItems++; MyWorkItemsSublist itemSublist; if (sublistsMap.TryGetValue("comment", out itemSublist)) { itemSublist.Items.Add(new CommentViewModel(comment)); } } myWorkItemSublists.ForEach(ms => { if (ms.IsSelected) { foreach (var myWorkItem in ms.Items) { _myItems.Add(myWorkItem); } } }); Mode = MainWindowMode.ItemsLoaded; SearchFilter = ""; MainWindowCommand.Instance?.UpdateActiveItemInToolbar(); NotifyPropertyChanged(); } catch (Exception ex) { MainWindowCommand.Instance?.DisableActiveItemToolbar(); Mode = MainWindowMode.FailToLoad; if (ex is NotConnectedException) { LastExceptionMessage = "Failed to load \"My Work\""; } else { LastExceptionMessage = ex.Message; } } }
public void WorkspaceSessionPersistanceManagerTests_IsActiveEntity_Null_Success() { Assert.IsFalse(WorkspaceSessionPersistanceManager.IsActiveEntity(null)); }