public void TestThatFoodGroupTreeGetGetsFoodGroupTree()
        {
            IList <TranslationInfoSystemView> translationInfoCollection = GetTranslationInfoCollection();

            Assert.That(translationInfoCollection, Is.Not.Null);
            Assert.That(translationInfoCollection, Is.Not.Empty);

            foreach (var translationInfo in translationInfoCollection)
            {
                var query = new FoodGroupTreeGetQuery
                {
                    TranslationInfoIdentifier = translationInfo.TranslationInfoIdentifier
                };
                var foodGroupTree = _foodWasteHouseholdDataService.FoodGroupTreeGet(query);
                Assert.That(foodGroupTree, Is.Not.Null);
                Assert.That(foodGroupTree.FoodGroups, Is.Not.Null);
                Assert.That(foodGroupTree.FoodGroups.Count(), Is.GreaterThanOrEqualTo(0));
                Assert.That(foodGroupTree.DataProvider, Is.Not.Null);
            }
        }
Example #2
0
        public void TestThatFoodItemCollectionGetGetsFoodItemCollection()
        {
            IList <TranslationInfoSystemView> translationInfoCollection = GetTranslationInfoCollection();

            Assert.That(translationInfoCollection, Is.Not.Null);
            Assert.That(translationInfoCollection, Is.Not.Empty);

            foreach (var translationInfo in translationInfoCollection)
            {
                var foodGroupTreeGetQuery = new FoodGroupTreeGetQuery
                {
                    TranslationInfoIdentifier = translationInfo.TranslationInfoIdentifier
                };
                var foodGroupTree = _foodWasteSystemDataService.FoodGroupTreeGet(foodGroupTreeGetQuery);
                Assert.That(foodGroupTree, Is.Not.Null);
                Assert.That(foodGroupTree.FoodGroups, Is.Not.Null);

                var foodGroupIdentifiers = new List <Guid?> {
                    null
                };
                if (foodGroupTree.FoodGroups.Any())
                {
                    foodGroupIdentifiers.Add(foodGroupTree.FoodGroups.Take(1).ElementAt(0).FoodGroupIdentifier);
                }
                foreach (var foodGroupIdentifier in foodGroupIdentifiers)
                {
                    var foodItemCollectionGetQuery = new FoodItemCollectionGetQuery
                    {
                        TranslationInfoIdentifier = translationInfo.TranslationInfoIdentifier,
                        FoodGroupIdentifier       = foodGroupIdentifier
                    };
                    var foodItemCollection = _foodWasteSystemDataService.FoodItemCollectionGet(foodItemCollectionGetQuery);
                    Assert.That(foodItemCollection, Is.Not.Null);
                    Assert.That(foodItemCollection.FoodItems, Is.Not.Null);
                    Assert.That(foodItemCollection.FoodItems.Count(), Is.GreaterThanOrEqualTo(0));
                    Assert.That(foodItemCollection.DataProvider, Is.Not.Null);
                }
            }
        }
Example #3
0
        /// <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));
        }