示例#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);
            }
        }