public override void Update(ShoppingListDto dto) { var dbList = _listRepository.Get(dto.Id); if (dbList == null) { throw new KeyNotFoundException("No list with this ID was found."); } if (dto.Name == null) { dto.Name = dbList.Name; } if (dto.Path == null) { dto.Path = dbList.Path; } if (dto.ChosenSortingId == 0) { dto.ChosenSortingId = dbList.ChosenSorting_Id; } _repository.Update(new ShoppingList { Id = dto.Id, Name = dto.Name, Path = dto.Path, Timestamp = DateTime.Now, ChosenSorting_Id = dto.ChosenSortingId }); }
public void Get_ShouldRetriveAShoppingListAndPopulateListItems_WhenIncludeListItemsParameterIsTrue() { var testDataKeys = CreateTestData(); using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(testDataKeys.UserId))) using (IUnitOfWork unitOfWork = new EfUnitOfWork(dbContext)) { var shoppingListRepository = new ShoppingListRepository(dbContext); var shoppingList = shoppingListRepository.Get(testDataKeys.ShoppingListId, includeListItems: true); Assert.AreEqual(2, shoppingList.ListItems.Count); } }