public ActionResult DeleteTest(int?id, string name, int page)
        {
            var model = new TestEditorViewModel();

            if (!ReferenceEquals(id, null))
            {
                _testService.DeleteTest(Convert.ToInt32(id));
            }


            List <TestViewModel> tests;

            if (ReferenceEquals(name, null) || name == string.Empty)
            {
                tests          = _testService.GetAllTests().Select(u => u.ToMvcTest()).ToList();
                model.Tests    = tests;
                model.PageInfo = new PageInfoViewModel(page, 10, tests.Count, null);
            }
            else
            {
                tests          = _testService.GetAllTests().Select(u => u.ToMvcTest()).Where(a => a.Name.Contains(name) || a.Creator.Contains(name)).ToList();
                model.Tests    = tests;
                model.PageInfo = new PageInfoViewModel(page, 10, tests.Count, name);
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("TestsEditor", model));
            }

            return(View("TestsEditor", model));
        }
Exemplo n.º 2
0
        public async Task SetModelPropertyAsync_should_set_UpdateErrorMessage_if_there_was_an_error()
        {
            var vm = new TestEditorViewModel(s_bonusBar);
            await vm.SetModelPropertyAsync(() => Task.FromException(new InvalidOperationException()), "Error");

            vm.UpdateErrorMessage.Should().NotBeNullOrWhiteSpace();
        }
Exemplo n.º 3
0
        public void SetPropertyAndPerformAsyncUpdate_should_not_invoke_the_update_func_if_loading()
        {
            var vm = new TestEditorViewModel(s_bonusBar);

            typeof(EditorViewModel)
            .InvokeMember(
                "IsLoading",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetProperty,
                Type.DefaultBinder,
                vm,
                new object[] { true });

            int  value = 0;
            bool invokedUpdateAction = false;

            vm.SetPropertyAndPerformAsyncUpdate(
                ref value,
                10,
                () =>
            {
                invokedUpdateAction = true;
                return(Task.CompletedTask);
            },
                TimeSpan.FromMinutes(1).Milliseconds,
                // ReSharper disable once ExplicitCallerInfoArgument
                "TestProperty")
            .Should()
            .BeTrue();

            invokedUpdateAction.Should().BeFalse();
        }
Exemplo n.º 4
0
        public async Task SetModelPropertyAsync_should_set_UpdateErrorMessage_if_there_was_a_timeout()
        {
            var vm = new TestEditorViewModel(s_bonusBar);
            await vm.SetModelPropertyAsync(() => Task.Delay(TimeSpan.FromMinutes(1)), "LongProperty", 1);

            vm.UpdateErrorMessage.Should().NotBeNullOrWhiteSpace();
        }
Exemplo n.º 5
0
        public async Task LoadAsync_should_start_a_timer_for_the_progress_bar_then_run_the_action()
        {
            var dispatcher = new UnitTestThreadDispatcher();
            var vm         = new TestEditorViewModel(s_bonusBar, dispatcher);

            await vm.LoadAsync(new FakeRegistryService());

            dispatcher.Runs.Should().ContainInOrder(DispatchRunKind.UIThreadDelayed, DispatchRunKind.BackgroundThread);
        }
Exemplo n.º 6
0
        public async Task LoadAsync_should_invoke_LoadInternalAsync_using_the_correct_parameters()
        {
            var vm = new TestEditorViewModel(s_bonusBar);
            CancellationToken cancellationToken = new CancellationTokenSource().Token;
            await vm.LoadAsync(new FakeRegistryService(), cancellationToken : cancellationToken);

            vm.LoadInternalAsyncCalled.Should().BeTrue();
            vm.LoadInternalAsyncCancellationToken.Should().Be(cancellationToken);
        }
Exemplo n.º 7
0
        public async Task IsContentReady_should_be_true_after_LoadAsync_returns()
        {
            var vm         = new TestEditorViewModel(s_bonusBar);
            var dispatcher = new UnitTestThreadDispatcher();

            await vm.LoadAsync(new FakeRegistryService());

            vm.IsContentReady.Should().BeTrue();
        }
Exemplo n.º 8
0
        public async Task IsIndeterminateProgressBarVisible_should_be_false_after_the_load_returns()
        {
            var vm         = new TestEditorViewModel(s_bonusBar);
            var dispatcher = new UnitTestThreadDispatcher();

            await vm.LoadAsync(new FakeRegistryService());

            vm.IsIndeterminateProgressBarVisible.Should().BeFalse();
        }
        public ActionResult TestsEditor(string searchItem, bool showNotValid = false, int page = 1)
        {
            var model = new TestEditorViewModel();
            List <TestViewModel> tests;

            if (ReferenceEquals(searchItem, null))
            {
                if (showNotValid)
                {
                    tests =
                        _testService.GetAllTests()
                        .Select(u => u.ToMvcTest())
                        .Where(m => m.IsValid == false)
                        .ToList();
                }
                else
                {
                    tests =
                        _testService.GetAllTests()
                        .Select(u => u.ToMvcTest())
                        .ToList();
                }
                model.PageInfo = new PageInfoViewModel(page, 10, tests.Count, null);
            }
            else
            {
                if (showNotValid)
                {
                    tests =
                        _testService.GetAllTests()
                        .Select(u => u.ToMvcTest())
                        .Where(m => m.IsValid == false && (m.Name.Contains(searchItem) || m.Creator.Contains(searchItem)))
                        .ToList();
                }
                else
                {
                    tests =
                        _testService.GetAllTests()
                        .Select(u => u.ToMvcTest())
                        .Where(m => m.Name.Contains(searchItem) || m.Creator.Contains(searchItem))
                        .ToList();
                }

                model.PageInfo = new PageInfoViewModel(page, 10, tests.Count, searchItem);
            }
            model.ShowNotValid = showNotValid;
            model.Tests        = tests.Skip((page - 1) * 10).Take(10);
            if (Request.IsAjaxRequest())
            {
                return(PartialView(model));
            }
            return(View(model));
        }
Exemplo n.º 10
0
        public async Task SetModelPropertyAsync_should_invoke_the_task()
        {
            var  vm         = new TestEditorViewModel(s_bonusBar);
            bool wasInvoked = false;
            await vm.SetModelPropertyAsync(() =>
            {
                wasInvoked = true;
                return(Task.CompletedTask);
            }, "PropertyName");

            wasInvoked.Should().BeTrue();
        }
Exemplo n.º 11
0
        IsIndeterminateProgressBarVisible_should_be_true_after_a_delay_and_the_content_is_not_yet_ready()
        {
            var cancellationSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationSource.Token;

            var dispatcher =
                new UnitTestThreadDispatcher(backgroundAsyncThreadInvoker: action => Task.Delay(-1, cancellationToken));
            var vm = new TestEditorViewModel(s_bonusBar, dispatcher);

            Task task = vm.LoadAsync(new FakeRegistryService(), 0, cancellationToken);

            vm.IsIndeterminateProgressBarVisible.Should().BeTrue();
            cancellationSource.Cancel();

            Func <Task> func = async() => await task;
            await func.Should().ThrowExactlyAsync <TaskCanceledException>();
        }
Exemplo n.º 12
0
        public async Task LoadAsync_should_pass_in_the_delay_to_the_delayInvoker()
        {
            const int delay             = 1;
            var       cancellationToken = new CancellationToken();

            var dispatcher = new UnitTestThreadDispatcher(
                delayInvoker: (ms, token) =>
            {
                ms.Should().Be(delay);
                token.Should()
                .NotBe(cancellationToken, "because the progress bar cancellation should be different");
                return(Task.CompletedTask);
            });
            var vm = new TestEditorViewModel(s_bonusBar, dispatcher);

            await vm.LoadAsync(new FakeRegistryService(), delay, cancellationToken);
        }
Exemplo n.º 13
0
        public void SetPropertyAndPerformAsyncUpdate_should_not_do_anything_if_the_property_has_not_chnaged()
        {
            string fakeProperty = "Nothing";

            var vm = new TestEditorViewModel(s_bonusBar);

            vm.SetPropertyAndPerformAsyncUpdate(
                ref fakeProperty,
                "Nothing",
                () => Task.CompletedTask,
                TimeSpan.FromMinutes(1).Milliseconds,
                // ReSharper disable once ExplicitCallerInfoArgument
                "TestProperty")
            .Should()
            .BeFalse();

            fakeProperty.Should().Be("Nothing");
        }
Exemplo n.º 14
0
        public void IsIndeterminateProgressBarVisible_should_be_false_initially()
        {
            var vm = new TestEditorViewModel(s_bonusBar);

            vm.IsIndeterminateProgressBarVisible.Should().BeFalse();
        }
Exemplo n.º 15
0
        public void IsContentReady_should_be_false_initially()
        {
            var vm = new TestEditorViewModel(s_bonusBar);

            vm.IsContentReady.Should().BeFalse();
        }