public void Setup() { userId = Guid.NewGuid().ToString(); listId = ObjectId.GenerateNewId(); toDoListData = new ToDoListDataModel { Id = listId, Name = "Test List", UserId = userId, Items = new List <ToDoItemDataModel> { new ToDoItemDataModel { Id = ObjectId.GenerateNewId(), Name = "Item 1", Complete = false, CompletedAt = null }, new ToDoItemDataModel { Id = ObjectId.GenerateNewId(), Name = "Item 2", Complete = true, CompletedAt = DateTime.Now } } }; }
public void SaveMultipleItems() { createdList = repository.CreateEmptyList(userId, "My Test List"); repository.AddItem(userId, createdList.Id.ToString(), newItemName1); repository.AddItem(userId, createdList.Id.ToString(), newItemName2); listWithThreeItems = repository.AddItem(userId, createdList.Id.ToString(), newItemName3); endList = repository.GetList(userId, listWithThreeItems.Id.ToString()); }
public ToDoList MapToDoList(ToDoListDataModel listData) { return(new ToDoList { _id = listData.Id.ToString(), Items = listData.Items.Select(x => MapToDoItem(x)), Name = listData.Name, UserId = listData.UserId }); }
private int GetItemIndexWithId(ToDoListDataModel list, string itemId) { var itemToUpdateIndex = list.Items.FindIndex(x => x.Id == new ObjectId(itemId)); if (itemToUpdateIndex < 0) { throw new Exception("Unable to find item with id " + itemId); } return(itemToUpdateIndex); }
public ToDoListDataModel CreateEmptyList(string userId, string listName) { var newList = new ToDoListDataModel { UserId = userId, Name = listName, Items = new List <ToDoItemDataModel>() }; _db.Lists.InsertOne(newList); return(newList); }