Ejemplo n.º 1
0
        public async Task CreateAsync_WithName_HasNoError(string name)
        {
            // arrange
            var vm = new TrackerViewModel(new MockTrackerService())
            {
                Name = name
            };

            // act
            await vm.CreateAsync();

            // assert
            Assert.False(vm.HasError);
        }
Ejemplo n.º 2
0
        public async Task CreateAsync_ServiceCallFailure_HasError()
        {
            // arrange
            string name = "Collen";
            var    vm   = new TrackerViewModel(new FailingTrackerService())
            {
                Name = name
            };

            // act
            await vm.CreateAsync();

            // assert
            Assert.True(vm.HasError);
        }
Ejemplo n.º 3
0
        public async Task CreateAsync_WithName_AddsToAllTrackers()
        {
            // arrange
            string name = "Collen";
            var    vm   = new TrackerViewModel(new MockTrackerService())
            {
                Name = name
            };

            // act
            await vm.CreateAsync();

            // assert
            Assert.Contains(vm.AllTrackers, tracker => tracker.Name == name);
        }
Ejemplo n.º 4
0
        public async Task CreateAsync_AnyError_DoesNotSendMessage(string name)
        {
            // arrange
            var vm = new TrackerViewModel(new FailingTrackerService())
            {
                Name = name
            };

            bool messageSent = false;

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

            // act
            await vm.CreateAsync();

            // assert
            Assert.False(messageSent);
        }
Ejemplo n.º 5
0
        public async Task CreateAsync_WithName_SendsMessageWithTracker()
        {
            // arrange
            string name = "Collen";
            var    vm   = new TrackerViewModel(new MockTrackerService())
            {
                Name = name
            };

            Tracker createdTracker = null;

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

            // act
            await vm.CreateAsync();

            // assert
            Assert.Equal(name, createdTracker?.Name);
        }