public void Disposing_Tasks_On_Project_Changed() { // creates a Task list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.TasksListViewModel list = new ViewModel.TasksListViewModel( null, null, null, aggregator, null, null); // create a task and adds to the task list view model List<ViewModel.TaskViewModel> tasks = new List<ViewModel.TaskViewModel>(); Mock<ViewModel.TaskViewModel> taskVM = new Mock<ViewModel.TaskViewModel>( null, null, aggregator, null, null, new Task(), null); tasks.Add(taskVM.Object); list.Tasks = tasks; // emulates a project change Project project = new Project(); aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, project); taskVM.Verify(i => i.Dispose(), "Dispose was not called"); }
public void Disposing_Items_On_Project_Changed() { // creates a backlog list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.BacklogViewModel list = new ViewModel.BacklogViewModel( null, null, null, aggregator, null, null); // create a item and adds to the backlog list view model List<ViewModel.BacklogItemViewModel> items = new List<ViewModel.BacklogItemViewModel>(); Mock<ViewModel.BacklogItemViewModel> itemVM = new Mock<ViewModel.BacklogItemViewModel>( null, null, aggregator, null, new Project() { Roles = new List<Role>() }, new BacklogItem()); items.Add(itemVM.Object); list.Items = items; // emulates a project change aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, new Project()); itemVM.Verify(i => i.Dispose(), "Dispose was not called"); }
public void Disposing_Tasks_On_Load() { // creates a fake taskservice Mock<Services.ITasksService> tasksService = new Mock<Services.ITasksService>(); tasksService.Setup(t => t.GetProjectTasks(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<bool>(), It.IsAny<string>())) .Returns(new List<Task>()); // creates a immediate bg executor Mock<IBackgroundExecutor> executor = BackgroundExecutorMock.SetupExecutorForCollectionOf<Task>(null); // creates a Task list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.TasksListViewModel list = new ViewModel.TasksListViewModel( tasksService.Object, null, executor.Object, aggregator, null, null); // assign a project to the list (no tasks yet, so no dispose by now) aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, new Project()); // create a task and adds to the task list view model List<ViewModel.TaskViewModel> tasks = new List<ViewModel.TaskViewModel>(); Mock<ViewModel.TaskViewModel> taskVM = new Mock<ViewModel.TaskViewModel>( null, null, aggregator, new Mock<IDialogService>().Object, null, new Task(), null); tasks.Add(taskVM.Object); list.Tasks = tasks; // emulates two load command list.OnLoadCommand.Execute(null); taskVM.Verify(i => i.Dispose(), "Dispose was not called"); }
public void RiskViewModel_Dispose_Ok() { // creates a Task ViewModel IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.RiskViewModel viewModel = new ViewModel.RiskViewModel(null, null, new Risk()); // creates the view FakeView view = new FakeView(); view.Model = viewModel; // clears VM reference WeakReference riskVMRef = new WeakReference(viewModel); viewModel.Dispose(); viewModel = null; view.Model = null; GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsNull(riskVMRef.Target, "ViewModel was not garbage collected. Check OnDispose method to see if all Commands and Events were unsubscribed"); }
private ViewModel.IterationPlanningViewModel PrepareSprintListViewModel(out Mock<ViewModel.SprintViewModel> sprintVM) { // creates a fake backlogservice Mock<Services.IBacklogService> backlogService = new Mock<Services.IBacklogService>(); backlogService.Setup(b => b.GetCurrentBacklog(It.IsAny<string>(), It.IsAny<short>(), DateTime.MinValue, DateTime.MinValue)) .Returns(new List<BacklogItem>()); // creates a immediate bg executor Mock<IBackgroundExecutor> executor = BackgroundExecutorMock.SetupExecutorForCollectionOf<BacklogItem>(null); BackgroundExecutorMock.SetupExecutorForAction(executor); // creates a sprint list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.IterationPlanningViewModel list = new ViewModel.IterationPlanningViewModel( backlogService.Object, null, executor.Object, null, aggregator, null); // assign a project to the list (no items yet, so no dispose by now) Project p = new Project(); p.Sprints = new List<Sprint>(); p.Sprints.Add(new Sprint() { SprintNumber = 1 }); aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, p); // create a sprint and adds to the backlog list view model System.Collections.ObjectModel.ObservableCollection<ViewModel.SprintViewModel> sprints = new System.Collections.ObjectModel.ObservableCollection<ViewModel.SprintViewModel>(); sprintVM = new Mock<ViewModel.SprintViewModel>( null, null, aggregator, p.Sprints[0], null); sprints.Add(sprintVM.Object); list.SprintPlans = sprints; return list; }
//[TestMethod] //public void Disposing_Sprints_On_Delete() { // Mock<ViewModel.SprintViewModel> sprintVM; // ViewModel.IterationPlanningViewModel list = PrepareSprintListViewModel(out sprintVM); // // verify dispose on load command // list.RemoveSprintCommand.Execute(sprintVM.Object); // sprintVM.Verify(i => i.Dispose(), "Dispose was not called"); //} private ViewModel.BacklogViewModel PrepareListViewModel(out Mock<ViewModel.BacklogItemViewModel> itemVM) { // creates a fake backlogservice Mock<Services.IBacklogService> backlogService = new Mock<Services.IBacklogService>(); backlogService.Setup(b => b.GetCurrentBacklog(It.IsAny<string>(), It.IsAny<short>(), DateTime.MinValue, DateTime.MinValue)) .Returns(new List<BacklogItem>()); // creates a immediate bg executor Mock<IBackgroundExecutor> executor = BackgroundExecutorMock.SetupExecutorForCollectionOf<BacklogItem>(null); BackgroundExecutorMock.SetupExecutorForAction(executor); // creates a backlog list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.BacklogViewModel list = new ViewModel.BacklogViewModel( backlogService.Object, null, executor.Object, aggregator, new Mock<IDialogService>().Object, null); // assign a project to the list (no items yet, so no dispose by now) aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, new Project()); // create a item and adds to the backlog list view model List<ViewModel.BacklogItemViewModel> items = new List<ViewModel.BacklogItemViewModel>(); itemVM = new Mock<ViewModel.BacklogItemViewModel>( null, null, aggregator, null, new Project() { Roles = new List<Role>() }, new BacklogItem()); items.Add(itemVM.Object); list.Items = items; return list; }
public void Disposing_Sprints_On_Project_Changed() { // creates a backlog list IEventAggregator aggregator = new ScrumFactory.Composition.EventAggregator(); ViewModel.IterationPlanningViewModel list = new ViewModel.IterationPlanningViewModel( null, null, null, null, aggregator, null); // create a item and adds to the backlog list view model System.Collections.ObjectModel.ObservableCollection<ViewModel.SprintViewModel> sprints = new System.Collections.ObjectModel.ObservableCollection<ViewModel.SprintViewModel>(); Mock<ViewModel.SprintViewModel> sprintVM = new Mock<ViewModel.SprintViewModel>( null, null, aggregator, new Sprint(), null); sprints.Add(sprintVM.Object); list.SprintPlans = sprints; // emulates a project change Project p = new Project(); p.Sprints = new List<Sprint>(); p.Sprints.Add(new Sprint()); aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, p); sprintVM.Verify(i => i.Dispose(), "Dispose was not called"); }