public void TestThatFoodItemGetAllGetsAllFoodItems() { var primaryFoodGroup = _systemDataRepository.Insert(new FoodGroup { Parent = null, IsActive = true }); try { var foodItem = _systemDataRepository.Insert(new FoodItem(primaryFoodGroup) { IsActive = true }); try { var result = _systemDataRepository.FoodItemGetAll(); // ReSharper disable PossibleMultipleEnumeration Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.Empty); Assert.That(result.Any(fi => fi.Identifier.HasValue && fi.Identifier.Equals(foodItem.Identifier)), Is.True); // ReSharper restore PossibleMultipleEnumeration } finally { _systemDataRepository.Delete(foodItem); } } finally { _systemDataRepository.Delete(primaryFoodGroup); } }
/// <summary> /// Functionality which handles a query for getting the collection of food items. /// </summary> /// <param name="query">Query for getting the collection of food items.</param> /// <returns>Collection of food items.</returns> public virtual TFoodItemCollectionView Query(FoodItemCollectionGetQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var dataProvider = _systemDataRepository.DataProviderForFoodItemsGet(); IFoodGroup foodGroup = null; if (query.FoodGroupIdentifier.HasValue) { foodGroup = _systemDataRepository.Get <IFoodGroup>(query.FoodGroupIdentifier.Value); } dataProvider.Translate(translationInfo.CultureInfo); var foodItemCollection = foodGroup == null ? GetFoodItemsForDataProvider(_systemDataRepository.FoodItemGetAll(), dataProvider) : GetFoodItemsForDataProvider(_systemDataRepository.FoodItemGetAllForFoodGroup(foodGroup), dataProvider); if (OnlyActive) { foodItemCollection.RemoveInactiveFoodItems(); } return(_foodWasteObjectMapper.Map <IFoodItemCollection, TFoodItemCollectionView>(foodItemCollection, translationInfo.CultureInfo)); }