Exemple #1
0
        // Handle DataRequested event and provide DataPackage
        private void OnShareDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            Models.TodoItem     sharedItem = ViewModel.GetItemById(currentId);
            var                 data       = args.Request.Data;
            DataRequestDeferral GetFiles   = args.Request.GetDeferral();

            try
            {
                data.Properties.Title       = sharedItem.Title;
                data.Properties.Description = sharedItem.Discription;
                var imageFile = sharedItem.ShareFile;
                if (imageFile != null)
                {
                    data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(imageFile);
                    data.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
                }
                else
                {
                    data.SetText(sharedItem.Discription);  // if no image, share text
                }
            }
            finally
            {
                GetFiles.Complete();
            }
        }
        public OwinServerFixture()
        {
            var list = new List<TodoItem> {
                new TodoItem() { Id = 1, Completed = false, Title = "Test 1" },
                new TodoItem() { Id = 2, Completed = true, Title = "Test 2" }
            };

            ServiceMock = new Moq.Mock<ITodoService>();
            ServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);

            var notCompleted = list.Where(x => x.Completed == false).ToList();
            ServiceMock.Setup(x => x.ClearCompleted()).ReturnsAsync(notCompleted);

            var newTask = new TodoItem() { Completed = false, Title = "Test 3" };
            ServiceMock.Setup(x => x.AddAsync(It.IsAny<TodoItem>())).ReturnsAsync(newTask);

            const int taskId = 2;
            var existingTask = new TodoItem() { Id = 2, Completed = false, Title = "Test 3" };
            ServiceMock.Setup(x => x.UpdateAsync(taskId, It.IsAny<TodoItem>())).ReturnsAsync(existingTask);
            ServiceMock.Setup(x => x.DeleteAsync(taskId)).ReturnsAsync(true);

            const int missingTaskId = 4;
            ServiceMock.Setup(x => x.UpdateAsync(missingTaskId, existingTask)).ReturnsAsync(null);
            ServiceMock.Setup(x => x.DeleteAsync(missingTaskId)).ReturnsAsync(false);

            TestServer = TestServer.Create(Configuration);
        }
		public async Task<TodoItem> AddAsync(TodoItem item)
		{
			await _db.CreateTableAsync<TodoItem>();

			var result = await _db.InsertAsync(item);

			return item;
		}
 public void AddTodo(TodoItem todo) {
   try {
     _em.AddEntity(todo);
   } catch (Exception e) {
     // most likely cause is tried to add entity before there is metadata
     _logger.Error(e);
     throw;
   }
 }
        public HttpResponseMessage Put(TodoItem todoItem)
        {
            if (TodoListController.TodoItems.All(t => t.Name != todoItem.Name))
            {
                TodoListController.TodoItems.Add(todoItem);

                return Request.CreateResponse(HttpStatusCode.OK, todoItem);
            }

            return Request.CreateResponse(HttpStatusCode.Conflict, new HttpError("Avoid duplicate."));
        }
    private void AddTodo(object sender, EventArgs e)
    {
      var description = newTodoView.Text.Trim();
      if (String.IsNullOrEmpty(description) || todos == null) { return; }

      var item = new TodoItem {Description = description};
      try   { _dataContext.AddTodo(item); }
      catch { return; } //eat the error because logging it at lower level
      newTodoView.Text = String.Empty;
      var vm = new TodoViewModel(item);
      todos.Insert(0, vm);                    // front of the list
      todoGridAdapter.NotifyDataSetChanged(); // redraw   
    }
		public async Task<TodoItem> UpdateAsync(int id, TodoItem todo)
		{
			await _db.CreateTableAsync<TodoItem>();

			var item = await _db.Table<TodoItem>().Where(x => x.Id == id).FirstOrDefaultAsync();

			if (item == null)
				return null;

			item.Title = todo.Title;
			item.Completed = todo.Completed;

			var result = await _db.UpdateAsync(item);

			return todo;
		}
Exemple #8
0
		public async Task Add_new_task()
		{
			// arrange
			var newTask = new TodoItem() { Completed = false, Title = "Test 3" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.AddAsync(newTask)).ReturnsAsync(newTask);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.AddTodo(newTask);

			// assert
			serviceMock.Verify(x => x.AddAsync(newTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(newTask, result);
		}
Exemple #9
0
		public async Task Change_completeness_of_task()
		{
			// arrange
			var existingTask = new TodoItem() { Id = 2, Completed = true, Title = "Test 1" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.UpdateAsync(existingTask.Id, existingTask)).ReturnsAsync(existingTask);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.UpdateTodo(existingTask.Id, existingTask);

			// assert
			serviceMock.Verify(x => x.UpdateAsync(existingTask.Id, existingTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(existingTask, result);
		}
 private void CreateButton_Click(object sender, RoutedEventArgs e)
 {
     Models.TodoItem TodoToCreate = new Models.TodoItem(TitleTextBox.Text,
                                                        DetailTextBox.Text, DueDatePicker.Date, TodoImage.Source, ImageFile);
     if (shareOp == null)
     {
         if (TodoToCreate.TodoInfoValidator())
         {
             ViewModel.AddTodoItem(TodoToCreate);
             ViewModel.NewestItem = TodoToCreate;
             Frame.Navigate(typeof(MainPage), ViewModel);
         }
     }
     else
     { // on sharing
         shareOp.ReportCompleted();
     }
 }
Exemple #11
0
		public void Status_not_found_when_changing_task_that_does_not_exist()
		{
			// arrange
			var taskId = 4;
			var existingTask = new TodoItem() { Id = 2, Completed = false, Title = "Test 3" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.UpdateAsync(taskId, existingTask)).ReturnsAsync(null);
			var controller = new TodoController(serviceMock.Object);

			// act
			var exc = Assert.Throws<AggregateException>(() => controller.UpdateTodo(taskId, existingTask).Result);
			var result = exc.InnerExceptions.Cast<HttpResponseException>().FirstOrDefault();

			// assert
			serviceMock.Verify(x => x.UpdateAsync(taskId, existingTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(HttpStatusCode.NotFound, result.Response.StatusCode);
		}
        public TodoItemPageModel(TodoItem model)
        {
            if (model == null)
                model = new TodoItem ();
            this.Model = model;

            this.Save = new Command (async () => {
                    if (string.IsNullOrWhiteSpace (this.Model.Name))
                    {
                        await App.Current.MainPage.DisplayAlert ("Validation Error", "Please enter a name", "OK");

                    } else
                    {
                        var dataService = DependencyService.Get<IDataService> ();
                        dataService.AddTodoItem (this.Model);
                        MessagingCenter.Send (this, "Reload");

                        await App.Current.MainPage.Navigation.PopAsync ();
                    }
                });
        }
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (ViewModel.SelectedItem != null)
            {
                // if not update image set to origin
                if (ImageFile == null)
                {
                    ImageFile = ViewModel.SelectedItem.ShareFile;
                }
                Models.TodoItem TodoToUpdate = new Models.TodoItem(TitleTextBox.Text,
                                                                   DetailTextBox.Text, DueDatePicker.Date, TodoImage.Source, ImageFile);

                TodoToUpdate.Id = ViewModel.SelectedItem.Id;
                if (TodoToUpdate.TodoInfoValidator())
                {
                    ViewModel.UpdateTodoItem(ViewModel.SelectedItem, TodoToUpdate);
                    ViewModel.NewestItem = TodoToUpdate;
                    Frame.Navigate(typeof(MainPage), ViewModel);
                }
            }
        }
        public TodoItemPage(TodoItem model)
        {
            this.BindingContext = new TodoItemPageModel (model);
            var title = model == null ? "New" : "Edit";

            // Modify already created objects, like this ContentPage, with handover as a parameter
            Create.ContentPage (this)
                .Title (title)
                .AddToolbarItem (Create.ToolbarItem ()
                    .Text ("Save")
                    .BindCommand ("Save"))
                .Content (Create.StackLayout ()
                    .Padding (1)
                    .AddChild (Create.Label ()
                        .Text ("Name"))
                    .AddChild (Create.Entry ()
                        .Placeholder ("Add a to-do...")
                        .BindText ("Model.Name"))
                    .AddChild (Create.Label ()
                        .Text ("Done"))
                    .AddChild (Create.Switch ()
                        .BindIsToggled ("Model.IsDone")))
                .Build ();
        }
Exemple #15
0
 protected bool Equals(TodoItem other)
 {
     return Id == other.Id && String.Equals(Title, other.Title) && Completed.Equals(other.Completed);
 }
Exemple #16
0
 private static TodoViewModel FromModelToItem(TodoItem item)
 {
     return new TodoViewModel() { Description = item.Description, Title = item.Title, Done = item.Done };
 }
 public void DeleteTodo(TodoItem todo) {
   todo.EntityAspect.Delete();
 }
 public TodoViewModel(TodoItem todo) {
   ViewKey = nextKey++;
   Todo = todo;
 }