Пример #1
0
        public void saves_are_throttled_to_two_seconds()
        {
            new TestScheduler().With(scheduler =>
            {
                var api = new ApiMock();
                var sut = new DinosaurDetailsViewModel(
                    42,
                    new BitmapLoaderMock(),
                    api);
                sut
                .Activator
                .Activate();
                scheduler.AdvanceByMs(2000);

                sut.Name = "Barney";
                scheduler.AdvanceByMs(500);
                sut.Name = "Barney the Dinosaur";
                scheduler.AdvanceByMs(500);
                sut.Weight = "42";

                scheduler.AdvanceByMs(1999);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasNotCalled();

                scheduler.AdvanceByMs(1);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasCalledExactlyOnce();
            });
        }
Пример #2
0
        public void data_is_saved_immediately_upon_deactivation_even_if_two_seconds_has_not_elapsed_since_last_change()
        {
            new TestScheduler().With(scheduler =>
            {
                var api = new ApiMock();
                var sut = new DinosaurDetailsViewModel(
                    42,
                    new BitmapLoaderMock(),
                    api);
                sut
                .Activator
                .Activate();

                sut.Name = "Barney";
                scheduler.AdvanceByMs(1);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasNotCalled();

                sut
                .Activator
                .Deactivate();
                scheduler.AdvanceByMs(1);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasCalledExactlyOnce();
            });
        }
Пример #3
0
        public void data_is_saved_two_seconds_after_image_data_is_modified()
        {
            new TestScheduler().With(scheduler =>
            {
                var api = new ApiMock();
                var sut = new DinosaurDetailsViewModel(
                    42,
                    new BitmapLoaderMock(),
                    api);
                sut
                .Activator
                .Activate();
                scheduler.AdvanceByMs(2000);

                sut.Weight    = "42";
                sut.ImageData = new byte[] { 1, 2, 3 };
                scheduler.AdvanceByMs(1999);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasNotCalled();

                scheduler.AdvanceByMs(1);
                api
                .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
                .WasCalledExactlyOnce();
            });
        }
Пример #4
0
        public void data_is_not_retrieved_upon_construction()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api);

            api
            .Verify(x => x.GetDinosaur(It.IsAny <int>()))
            .WasNotCalled();
        }
Пример #5
0
        public void data_is_retrieved_upon_activation()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api);

            sut
            .Activator
            .Activate();

            api
            .Verify(x => x.GetDinosaur(42))
            .WasCalledExactlyOnce();
        }
Пример #6
0
        public void data_is_not_saved_if_it_is_invalid()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api);

            sut
            .Activator
            .Activate();

            sut.Weight = "42a";

            api
            .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
            .WasNotCalled();
        }
Пример #7
0
        public void data_is_deleted_if_user_confirms()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api);

            using (sut.ConfirmDeleteInteraction.RegisterHandler(context => context.SetOutput(true)))
            {
                sut
                .DeleteCommand
                .Execute()
                .Subscribe();
            }

            api
            .Verify(x => x.DeleteDinosaur(It.IsAny <int>()))
            .WasCalledExactlyOnce();
        }