Ejemplo n.º 1
0
        public void saves_are_throttled_to_two_seconds()
        {
            var scheduler = new TestScheduler();
            var api       = new ApiMock();
            var sut       = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                scheduler);

            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();
        }
Ejemplo n.º 2
0
        public void data_is_saved_immediately_upon_deactivation_even_if_two_seconds_has_not_elapsed_since_last_change()
        {
            var scheduler = new TestScheduler();
            var api       = new ApiMock();
            var sut       = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                scheduler);

            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();
        }
Ejemplo n.º 3
0
        public void data_is_saved_two_seconds_after_image_data_is_modified()
        {
            var scheduler = new TestScheduler();
            var api       = new ApiMock();
            var sut       = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                scheduler);

            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();
        }
Ejemplo n.º 4
0
        public void data_is_not_retrieved_upon_construction()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                CurrentThreadScheduler.Instance);

            api
            .Verify(x => x.GetDinosaur(It.IsAny <int>()))
            .WasNotCalled();
        }
Ejemplo n.º 5
0
        public void data_is_retrieved_upon_activation()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                CurrentThreadScheduler.Instance);

            sut
            .Activator
            .Activate();

            api
            .Verify(x => x.GetDinosaur(42))
            .WasCalledExactlyOnce();
        }
Ejemplo n.º 6
0
        public void data_is_not_saved_if_it_is_invalid()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                CurrentThreadScheduler.Instance);

            sut
            .Activator
            .Activate();

            sut.Weight = "42a";

            api
            .Verify(x => x.SaveDinosaur(It.IsAny <Dinosaur>()))
            .WasNotCalled();
        }
Ejemplo n.º 7
0
        public void data_is_deleted_if_user_confirms()
        {
            var api = new ApiMock();
            var sut = new DinosaurDetailsViewModel(
                42,
                new BitmapLoaderMock(),
                api,
                CurrentThreadScheduler.Instance);

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

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