コード例 #1
0
ファイル: WorkspaceTests.cs プロジェクト: ganesum/Naru
                public void is_called_multiple_time_then_OnInitialised_event_is_only_fired_once()
                {
                    var container = AutoMock.GetLoose();

                    var eventWasFired = 0;

                    var testDispatcherSchedulerProvider = new TestDispatcherSchedulerProvider();
                    var testScheduler = testDispatcherSchedulerProvider.Dispatcher.RX as TestScheduler;

                    container.Provide<IDispatcherSchedulerProvider>(testDispatcherSchedulerProvider);

                    var viewModel = container.Create<WorkspaceViewModel>();

                    Assert.That(eventWasFired, Is.EqualTo(0));

                    viewModel.ActivationStateViewModel.OnInitialise
                        .ObserveOn(testScheduler)
                        .Subscribe(_ => eventWasFired++);

                    viewModel.ActivationStateViewModel.Activate();
                    viewModel.ActivationStateViewModel.DeActivate();
                    viewModel.ActivationStateViewModel.Activate();

                    testScheduler.AdvanceBy(1);

                    Assert.That(eventWasFired, Is.EqualTo(1));
                }
コード例 #2
0
ファイル: ViewModelHelpersTests.cs プロジェクト: ganesum/Naru
        public void when_parent_activation_state_changes_then_the_toolbaritem_activate_state_changes()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var toolBarItem1 = new ToolBarButtonItem(testSchedulerProvider);
            var toolBarItem2 = new ToolBarButtonItem(testSchedulerProvider);

            var viewModel = new SupportActivationState(testSchedulerProvider);
            viewModel.ActivationStateViewModel.Activate();

            viewModel.SyncToolBarItemWithViewModelActivationState(toolBarItem1, toolBarItem2);

            Assert.That(viewModel.ActivationStateViewModel.IsActive, Is.True);

            Assert.That(toolBarItem1.IsVisible, Is.True);
            Assert.That(toolBarItem2.IsVisible, Is.True);

            viewModel.ActivationStateViewModel.DeActivate();

            Assert.That(viewModel.ActivationStateViewModel.IsActive, Is.False);

            Assert.That(toolBarItem1.IsVisible, Is.False);
            Assert.That(toolBarItem2.IsVisible, Is.False);

            viewModel.ActivationStateViewModel.Activate();

            Assert.That(viewModel.ActivationStateViewModel.IsActive, Is.True);

            Assert.That(toolBarItem1.IsVisible, Is.True);
            Assert.That(toolBarItem2.IsVisible, Is.True);
        }
コード例 #3
0
        public void when_IsActive_is_set_to_true_then_ActivationStateChanged_pumps_true()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var activationStateViewModel = new ActivationStateViewModel(new NoOpLogger(), testSchedulerProvider);

            var result = false;

            activationStateViewModel.ActivationStateChanged
                                    .Subscribe(isActive => result = isActive);

            activationStateViewModel.Activate();

            Assert.That(result, Is.True);
        }
コード例 #4
0
        public void the_first_time_IsActive_is_set_to_true_then_OnInitialise_pumps()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var activationStateViewModel = new ActivationStateViewModel(new NoOpLogger(), testSchedulerProvider);

            var result = false;

            activationStateViewModel.OnInitialise
                                    .Subscribe(_ => result = true);

            activationStateViewModel.Activate();

            Assert.That(result, Is.True);
        }
コード例 #5
0
        public void when_SelectedItem_is_set_then_the_SelectedItemChanged_pumps_the_value()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = Guid.Empty;

            var reactiveSingleSelectCollection = new ReactiveSingleSelectCollection<Guid>(new BindableCollection<Guid>(testSchedulerProvider),
                                                                                          testSchedulerProvider);
            reactiveSingleSelectCollection.SelectedItemChanged
                                          .Subscribe(x => result = x);

            var selectedItem = Guid.NewGuid();

            reactiveSingleSelectCollection.SelectedItem = selectedItem;

            Assert.That(selectedItem.Equals(result));
        }
コード例 #6
0
        public void when_SelectedItem_is_set_then_the_SelectedItemChanged_pumps_the_value()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = new List<int>();

            var reactiveMultiSelectCollection = new ReactiveMultiSelectCollection<int>(new BindableCollection<int>(testSchedulerProvider),
                                                                                       testSchedulerProvider);
            reactiveMultiSelectCollection.SelectedItemsChanged
                                          .Subscribe(x => result = x.ToList());

            var selectedItem = Enumerable.Range(0,1).ToList();

            reactiveMultiSelectCollection.SelectedItems = selectedItem;

            Assert.That(selectedItem.SequenceEqual(result));
        }
コード例 #7
0
        public void when_RaiseAndSetIfChanged_is_called_with_a_different_value_then_it_is_set()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var viewModel = new TestViewModel(testSchedulerProvider);

            Assert.That(viewModel.Name, Is.Null);

            var value1 = Guid.NewGuid().ToString();
            viewModel.Name = value1;

            Assert.That(viewModel.Name, Is.EqualTo(value1));

            var value2 = Guid.NewGuid().ToString();
            viewModel.Name = value2;

            Assert.That(viewModel.Name, Is.EqualTo(value2));
        }
コード例 #8
0
ファイル: ViewModelHelpersTests.cs プロジェクト: ganesum/Naru
        public void when_header_is_created_the_properties_have_the_correct_values()
        {
            var container = AutoMock.GetLoose();

            var testDispatcherSchedulerProvider = new TestDispatcherSchedulerProvider();
            container.Provide<IDispatcherSchedulerProvider>(testDispatcherSchedulerProvider);

            var workspace = container.Create<WorkspaceViewModel>();

            var displayName = "DisplayName";
            var imageuri = "ImageUri";

            workspace.SetupHeader(testDispatcherSchedulerProvider, displayName, imageuri);

            var headerViewModel = workspace.Header as HeaderViewModel;

            Assert.That(headerViewModel, Is.Not.Null);
            Assert.That(headerViewModel.DisplayName, Is.EqualTo(displayName));
            Assert.That(headerViewModel.ImageName, Is.EqualTo(imageuri));
        }
コード例 #9
0
        public void when_AddRangeAsync_is_called_then_Reset_event_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<int>(testSchedulerProvider);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Reset)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.AddRangeAsync(Enumerable.Range(0, 1));

            Assert.That(result, Is.True);
        }
コード例 #10
0
        public void when_ConnectINPCProperty_is_setup_then_when_ObservableProperty_changes_then_INPC_is_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var viewModel = new TestViewModel(testSchedulerProvider);

            var result = false;

            viewModel.PropertyChanged += (sender, args) =>
                                         {
                                             var propertyName = PropertyExtensions.ExtractPropertyName(() => viewModel.Name);
                                             if (args.PropertyName == propertyName)
                                             {
                                                 result = true;
                                             }
                                         };

            viewModel.Name = Guid.NewGuid().ToString();

            ((TestScheduler)testSchedulerProvider.Dispatcher.RX).AdvanceBy(1);

            Assert.That(result, Is.True);
        }
コード例 #11
0
        public void when_SelectedItem_is_set_then_the_SelectedItems_INPC_is_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var reactiveMultiSelectCollection = new ReactiveMultiSelectCollection<int>(new BindableCollection<int>(testSchedulerProvider),
                                                                                       testSchedulerProvider);

            var result = false;

            reactiveMultiSelectCollection.PropertyChanged += (sender, args) =>
                                                             {
                                                                 var propertyName = PropertyExtensions.ExtractPropertyName(() => reactiveMultiSelectCollection.SelectedItems);
                                                                 if (args.PropertyName == propertyName)
                                                                 {
                                                                     result = true;
                                                                 }
                                                             };

            reactiveMultiSelectCollection.SelectedItems = Enumerable.Range(0, 1).ToList();
            ((TestScheduler)testSchedulerProvider.Dispatcher.RX).AdvanceBy(1);

            Assert.That(result, Is.True);
        }
コード例 #12
0
ファイル: ViewModelHelpersTests.cs プロジェクト: ganesum/Naru
        public void when_child_isbusy_changes_then_the_parent_isbusy_changes()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var parent = new SupportBusyViewModel(testSchedulerProvider);
            var child = new SupportBusyViewModel(testSchedulerProvider);

            parent.SyncViewModelBusy(child);

            Assert.That(parent.BusyViewModel.IsActive, Is.False);
            Assert.That(child.BusyViewModel.IsActive, Is.False);

            child.BusyViewModel.Active(string.Empty);

            Assert.That(child.BusyViewModel.IsActive, Is.True);

            Assert.That(parent.BusyViewModel.IsActive, Is.True);

            child.BusyViewModel.InActive();

            Assert.That(child.BusyViewModel.IsActive, Is.False);

            Assert.That(parent.BusyViewModel.IsActive, Is.False);
        }
コード例 #13
0
        public void when_items_are_added_those_items_are_pumped_onto_AddedItemsCollectionChanged()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var results = new List<Guid>();

            var bindableCollection = new BindableCollection<Guid>(testSchedulerProvider);
            bindableCollection.AddedItemsCollectionChanged
                              .Subscribe(x => results.AddRange(x));

            var items = Enumerable.Range(0, 10)
                                  .Select(_ => Guid.NewGuid())
                                  .ToList();

            bindableCollection.AddRange(items);

            var intersectionCount = results.Intersect(items).Count();

            Assert.That(intersectionCount, Is.EqualTo(items.Count));
        }
コード例 #14
0
        public void when_ClearAsync_is_called_and_IsNotifying_is_false_then_Reset_event_is_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<Guid>(testSchedulerProvider);

            var newGuid = Guid.NewGuid();

            bindableCollection.Add(newGuid);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Reset)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.IsNotifying = false;

            bindableCollection.ClearAsync();

            Assert.That(result, Is.False);
        }
コード例 #15
0
        public void when_Add_is_called_and_IsNotifying_is_false_then_Add_event_is_not_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<int>(testSchedulerProvider);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Add)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.IsNotifying = false;

            bindableCollection.Add(1);

            Assert.That(result, Is.False);
        }
コード例 #16
0
ファイル: WorkspaceTests.cs プロジェクト: ganesum/Naru
                public void is_called_then_Disposables_are_disposed()
                {
                    var container = AutoMock.GetLoose();

                    var testDispatcherSchedulerProvider = new TestDispatcherSchedulerProvider();
                    var testScheduler = testDispatcherSchedulerProvider.Dispatcher.RX as TestScheduler;

                    container.Provide<IDispatcherSchedulerProvider>(new TestDispatcherSchedulerProvider());

                    var eventWasFired = false;

                    var viewModel = container.Create<WorkspaceViewModel>();

                    Assert.That(eventWasFired, Is.False);

                    viewModel.DisposablesWasDisposed += (s, e) => eventWasFired = true;

                    viewModel.ClosingStrategy.Close();

                    Assert.That(eventWasFired, Is.True);
                }
コード例 #17
0
ファイル: WorkspaceTests.cs プロジェクト: ganesum/Naru
                public void is_called_then_OnDeActivate_is_called()
                {
                    var container = AutoMock.GetLoose();

                    var eventWasFired = false;

                    var testDispatcherSchedulerProvider = new TestDispatcherSchedulerProvider();
                    var testScheduler = testDispatcherSchedulerProvider.Dispatcher.RX as TestScheduler;

                    container.Provide<IDispatcherSchedulerProvider>(testDispatcherSchedulerProvider);

                    var viewModel = container.Create<WorkspaceViewModel>();

                    viewModel.ActivationStateViewModel.Activate();

                    Assert.That(eventWasFired, Is.False);

                    viewModel.OnDeActivateWasCalled += (s, e) => eventWasFired = true;

                    viewModel.ActivationStateViewModel.DeActivate();

                    testScheduler.AdvanceBy(2);

                    Assert.That(eventWasFired, Is.True);
                }
コード例 #18
0
        public void when_RemoveRange_is_called_and_IsNotifying_is_false_then_Reset_event_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<int>(testSchedulerProvider);

            var items = Enumerable.Range(0, 1).ToList();

            bindableCollection.AddRange(items);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Reset)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.IsNotifying = false;

            bindableCollection.RemoveRange(items);

            Assert.That(result, Is.False);
        }
コード例 #19
0
        public void when_Remove_is_called_then_Remove_event_is_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<Guid>(testSchedulerProvider);

            var newGuid = Guid.NewGuid();

            bindableCollection.Add(newGuid);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Remove)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.Remove(newGuid);

            Assert.That(result, Is.True);
        }
コード例 #20
0
ファイル: WorkspaceTests.cs プロジェクト: ganesum/Naru
                public void is_called_then_OnActivationStateChanged_event_is_fired()
                {
                    var container = AutoMock.GetLoose();

                    var eventWasFired = false;

                    var testDispatcherSchedulerProvider = new TestDispatcherSchedulerProvider();
                    var testScheduler = testDispatcherSchedulerProvider.Dispatcher.RX as TestScheduler;

                    container.Provide<IDispatcherSchedulerProvider>(new TestDispatcherSchedulerProvider());

                    var viewModel = container.Create<WorkspaceViewModel>();

                    viewModel.ActivationStateViewModel.Activate();

                    Assert.That(eventWasFired, Is.False);

                    viewModel.ActivationStateViewModel.ActivationStateChanged
                             .ObserveOn(testScheduler)
                             .Subscribe(x => eventWasFired = true);

                    viewModel.ActivationStateViewModel.DeActivate();

                    testScheduler.AdvanceBy(1);

                    Assert.That(eventWasFired, Is.True);
                }