Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        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);
                }
        }