Beispiel #1
0
		public TodoViewModel( Todo todo )
		{
			MessengerInstance.Register<TagAddedMessage>( this, OnTagAdded );
			MessengerInstance.Register<TagRemovedMessage>( this, OnTagRemoved );

			TodoRepo = new TodoRepository( App.Session );
			Model = todo;
			_Done = Model.Done;

			if( Model?.Project?.Tags != null )
			{
				AllTags = new ObservableCollection<TodoTagViewModel>( Model.Project.Tags.Select( t => new TodoTagViewModel( t )
				{
					IsSelected = Model.Tags.Contains( t )
				} ) );
			}
			else
			{
				AllTags = new ObservableCollection<TodoTagViewModel>();
			}

			foreach( var t in AllTags )
			{
				t.Selected += Tag_Selected;
				t.Deselected += Tag_Deselected;
			}

			Tags = new ObservableCollection<TodoTagViewModel>( AllTags.Where( t => t.IsSelected ) );
		}
Beispiel #2
0
        public void NewTodoIsNotDone()
        {
            // Arrange

            // Act
            var todo = new Todo();

            // Assert
            Assert.IsFalse( todo.Done );
        }
        public void ConstructorExtractsCorrectModelData()
        {
            // Arrange
            var todo = new Todo {Summary = "summary", Details = "details"};
            var entry = new TodoViewModel( todo );

            // Act
            var vm = new EditEntryViewModel( entry );

            // Assert
            Assert.AreEqual( "summary", vm.Summary );
            Assert.AreEqual( "details", vm.Details );
        }
        public void SaveCommandNeedsSummary()
        {
            // Arrange
            var todo = new Todo {Summary = "summary", Details = "details"};
            var entry = new TodoViewModel( todo );
            var vm = new EditEntryViewModel( entry );

            // Act
            bool withSummary = vm.SaveCommand.CanExecute( null );
            vm.Summary = string.Empty;
            bool withoutSummary = vm.SaveCommand.CanExecute( null );

            // Assert
            Assert.IsTrue( withSummary );
            Assert.IsFalse( withoutSummary );
        }
Beispiel #5
0
 public EntryAddedMessage( Todo entry )
 {
     Entry = entry;
 }
Beispiel #6
0
        private void ExecuteAddCommand()
        {
            var todo = new Todo
            {
                Summary = Summary,
                Details = Details,
                Project = CurrentProject.Model
            };

            TodoRepo.Add( todo );

            foreach( var tag in Tags.Where( t => t.IsSelected ) )
            {
                todo.Tags.Add( tag.Tag.Model );
            }

            TodoRepo.Update( todo );

            CurrentProject.Todos.Add( new TodoViewModel( todo ) );
            Reset();

            if( !StayOpen )
            {
                MessengerInstance.Send( new FlyoutMessage( FlyoutMessage.AddEntryFlyoutName ) );
            }

            MessengerInstance.Send( new EntryAddedMessage( todo ) );
        }