Exemplo n.º 1
0
        public void TestThatFoodItemGetAllForFoodGroupReturnsFoodItem()
        {
            var dataProvider = _systemDataRepository.DataProviderForFoodItemsGet();

            Assert.That(dataProvider, Is.Not.Null);

            var primaryFoodGroup = _systemDataRepository.Insert(new FoodGroup {
                Parent = null, IsActive = true
            });

            try
            {
                var foodItem = _systemDataRepository.Insert(new FoodItem(primaryFoodGroup)
                {
                    IsActive = true
                });
                try
                {
                    // ReSharper disable PossibleInvalidOperationException
                    var foreignKey = _systemDataRepository.Insert(new ForeignKey(dataProvider, foodItem.Identifier.Value, foodItem.GetType(), "ForeignKeyToFoodItem"));
                    // ReSharper restore PossibleInvalidOperationException
                    try
                    {
                        var result = _systemDataRepository.FoodItemGetByForeignKey(dataProvider, "ForeignKeyToFoodItem");
                        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(foodItem.Identifier.Value));
                        // ReSharper restore PossibleInvalidOperationException
                    }
                    finally
                    {
                        _systemDataRepository.Delete(foreignKey);
                    }
                }
                finally
                {
                    _systemDataRepository.Delete(foodItem);
                }
            }
            finally
            {
                _systemDataRepository.Delete(primaryFoodGroup);
            }
        }
Exemplo n.º 2
0
        /// <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));
        }