Ejemplo n.º 1
0
        public async Task UpdateAsync_WithName_SendsMessageWithTracker()
        {
            // arrange
            int    id   = 0;
            string name = "Collen";

            var service = new MockTrackerService();

            service.Trackers.Add(new Tracker {
                Id = 0, Name = "Bob"
            });

            var vm = new TrackerViewModel(service)
            {
                Id   = 0,
                Name = name
            };

            Tracker updatedTracker = null;

            MessagingCenter.Subscribe <TrackerViewModel, Tracker>(this, nameof(vm.UpdateCommand),
                                                                  (sender, tracker) => updatedTracker = tracker);

            // act
            await vm.UpdateAsync();

            // assert
            Assert.Equal(id, updatedTracker?.Id);
            Assert.Equal(name, updatedTracker?.Name);
        }
Ejemplo n.º 2
0
        public async Task UpdateAsync_WithName_UpdatesTracker()
        {
            // arrange
            int    id   = 0;
            string name = "Collen";

            var service = new MockTrackerService();

            service.Trackers.Add(new Tracker {
                Id = 0, Name = "Bob"
            });

            var vm = new TrackerViewModel(service)
            {
                Id   = id,
                Name = name
            };

            // act
            await vm.UpdateAsync();

            // assert
            Assert.Single(vm.AllTrackers);
            Assert.Contains(vm.AllTrackers, tracker => tracker.Name == name && tracker.Id == id);
        }
Ejemplo n.º 3
0
        public async Task UpdateAsync_NoName_HasError(string name)
        {
            // arrange
            var vm = new TrackerViewModel(new MockTrackerService())
            {
                Id   = 0,
                Name = name
            };

            // act
            await vm.UpdateAsync();

            // assert
            Assert.True(vm.HasError);
        }
Ejemplo n.º 4
0
        public async Task UpdateAsync_ServiceCallFailure_HasError()
        {
            // arrange
            string name = "Collen";
            var    vm   = new TrackerViewModel(new FailingTrackerService())
            {
                Id   = 0,
                Name = name
            };

            // act
            await vm.UpdateAsync();

            // assert
            Assert.True(vm.HasError);
        }
Ejemplo n.º 5
0
        public async Task UpdateAsync_AnyError_DoesNotSendMessage(string name)
        {
            // arrange
            var vm = new TrackerViewModel(new FailingTrackerService())
            {
                Id   = 0,
                Name = name
            };

            bool messageSent = false;

            MessagingCenter.Subscribe <TrackerViewModel, Tracker>(this, nameof(vm.UpdateCommand),
                                                                  (sender, tracker) => messageSent = true);

            // act
            await vm.UpdateAsync();

            // assert
            Assert.False(messageSent);
        }
Ejemplo n.º 6
0
        public async Task UpdateAsync_WithName_HasNoError(string name)
        {
            // arrange
            var service = new MockTrackerService();

            service.Trackers.Add(new Tracker {
                Id = 0, Name = "Bob"
            });

            var vm = new TrackerViewModel(service)
            {
                Id   = 0,
                Name = name
            };

            // act
            await vm.UpdateAsync();

            // assert
            Assert.False(vm.HasError);
        }