public void TestThatFoodGroupGetByForeignKeyReturnsFoodGroup() { var dataProvider = _systemDataRepository.DataProviderForFoodGroupsGet(); Assert.That(dataProvider, Is.Not.Null); var foodGroup = _systemDataRepository.Insert(new FoodGroup { Parent = null, IsActive = true }); try { // ReSharper disable PossibleInvalidOperationException var foreignKey = _systemDataRepository.Insert(new ForeignKey(dataProvider, foodGroup.Identifier.Value, foodGroup.GetType(), "ForeignKeyToFoodGroup")); // ReSharper restore PossibleInvalidOperationException try { var result = _systemDataRepository.FoodGroupGetByForeignKey(dataProvider, "ForeignKeyToFoodGroup"); Assert.That(result, Is.Not.Null); Assert.That(result.Identifier, Is.Not.Null); // ReSharper disable ConditionIsAlwaysTrueOrFalse Assert.That(result.Identifier.HasValue, Is.True); // ReSharper restore ConditionIsAlwaysTrueOrFalse // ReSharper disable PossibleInvalidOperationException Assert.That(result.Identifier.Value, Is.EqualTo(foodGroup.Identifier.Value)); // ReSharper restore PossibleInvalidOperationException } finally { _systemDataRepository.Delete(foreignKey); } } finally { _systemDataRepository.Delete(foodGroup); } }
/// <summary> /// Functionality which handles a query for getting the tree of food groups. /// </summary> /// <param name="query">Query for getting the tree of food groups.</param> /// <returns>Tree of food groups.</returns> public virtual TFoodGroupTreeView Query(FoodGroupTreeGetQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var dataProvider = _systemDataRepository.DataProviderForFoodGroupsGet(); var foodGroups = _systemDataRepository.FoodGroupGetAllOnRoot() .Where(foodGroup => foodGroup.ForeignKeys != null && foodGroup.ForeignKeys.Any(foreignKey => foreignKey.DataProvider != null && foreignKey.DataProvider.Identifier == dataProvider.Identifier)) .ToList(); dataProvider.Translate(translationInfo.CultureInfo); var foodGroupCollection = new FoodGroupCollection(foodGroups, dataProvider); if (OnlyActive) { foodGroupCollection.RemoveInactiveFoodGroups(); } return(_foodWasteObjectMapper.Map <IFoodGroupCollection, TFoodGroupTreeView>(foodGroupCollection, translationInfo.CultureInfo)); }