Ejemplo n.º 1
0
        public void TestThatTranslateCallsTranslateOnParentWhenParentIsNotNullAndHasNotBeenTranslated()
        {
            var cultureInfo = CultureInfo.CurrentUICulture;

            var parentFoodGroupMock = MockRepository.GenerateMock <IFoodGroup>();

            parentFoodGroupMock.Stub(m => m.Identifier)
            .Return(Guid.NewGuid())
            .Repeat.Any();
            parentFoodGroupMock.Stub(m => m.Translation)
            .Return(null)
            .Repeat.Any();

            var foodGroup = new FoodGroup
            {
                Parent = parentFoodGroupMock
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.EqualTo(parentFoodGroupMock));
            Assert.That(foodGroup.Parent.Translation, Is.Null);

            foodGroup.Translate(cultureInfo);

            parentFoodGroupMock.AssertWasCalled(m => m.Translate(Arg <CultureInfo> .Is.Equal(cultureInfo)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] FoodGroup foodGroup)
        {
            if (id != foodGroup.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foodGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodGroupExists(foodGroup.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(foodGroup));
        }
Ejemplo n.º 3
0
        public void TestThatTranslateDoesNotCallTranslateOnParentWhenParentIsNotNullAndHasBeenTranslated()
        {
            var cultureInfo = CultureInfo.CurrentUICulture;

            var parentFoodGroupIdentifier = Guid.NewGuid();
            var parentFoodGroupMock       = MockRepository.GenerateMock <IFoodGroup>();

            parentFoodGroupMock.Stub(m => m.Identifier)
            .Return(parentFoodGroupIdentifier)
            .Repeat.Any();
            parentFoodGroupMock.Stub(m => m.Translation)
            .Return(DomainObjectMockBuilder.BuildTranslationMock(parentFoodGroupIdentifier))
            .Repeat.Any();

            var foodGroup = new FoodGroup
            {
                Parent = parentFoodGroupMock
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.EqualTo(parentFoodGroupMock));
            Assert.That(foodGroup.Parent.Translation, Is.Not.Null);

            foodGroup.Translate(cultureInfo);

            parentFoodGroupMock.AssertWasNotCalled(m => m.Translate(Arg <CultureInfo> .Is.Anything));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add food to a food group for all slimes inside that group
        /// </summary>
        /// <param name="id">ID of the food to add</param>
        /// <param name="group">Group of food to add in</param>
        /// <param name="favoritedBy">The IDs for the slimes that favorite this food</param>
        public static void AddFoodToGroup(Identifiable.Id id, FoodGroup group, ICollection <Identifiable.Id> favoritedBy = null)
        {
            foreach (SlimeDefinition def in GameContext.Instance.SlimeDefinitions.Slimes)
            {
                if (def.Diet == null || !HasFoodGroup(def.Diet, group) || def.Diet.EatMap == null || def.Diet.EatMap.Count <= 0)
                {
                    continue;
                }

                if (def.Diet.EatMap.Exists(e => e.eats == id))
                {
                    continue;
                }

                def.Diet.EatMap.Add(new SlimeDiet.EatMapEntry()
                {
                    becomesId  = Identifiable.Id.NONE,
                    driver     = SlimeEmotions.Emotion.HUNGER,
                    eats       = id,
                    extraDrive = DEFAULT_EXTRA_DRIVE,
                    favoriteProductionCount = DEFAULT_FAV_COUNT,
                    isFavorite = favoritedBy?.Contains(def.IdentifiableId) ?? false,
                    minDrive   = EAT_MIN_DRIVE,
                    producesId = SlimeToPlort(def.IdentifiableId)
                });
            }
        }
Ejemplo n.º 5
0
        public void TestThatParentSetterThrowsArgumentExceptionWhenValueEqualsFoodGroupWhichUpdatesParent()
        {
            var foodGroup = new FoodGroup
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Identifier, Is.Not.Null);
            Assert.That(foodGroup.Identifier.HasValue, Is.True);
            Assert.That(foodGroup.Parent, Is.Null);

            var exception = Assert.Throws <ArgumentException>(() => foodGroup.Parent = foodGroup);

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("value"));
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            // ReSharper disable NotResolvedInText
            Assert.That(exception.Message, Is.EqualTo((new ArgumentException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, foodGroup, "value"), "value")).Message));
            // ReSharper restore NotResolvedInText
            Assert.That(exception.InnerException, Is.Null);
        }
Ejemplo n.º 6
0
        public void TestFoodGroupParse()
        {
            string input = "~0100~^~Dairy and Egg Products~";
            FoodGroup fg = new FoodGroup(input);

            Assert.AreEqual(100, fg.USDAID);
            Assert.AreEqual("Dairy and Egg Products", fg.GroupName);
        }
        public ActionResult DeleteConfirmed(long id)
        {
            FoodGroup foodGroup = db.FoodGroups.Find(id);

            db.FoodGroups.Remove(foodGroup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <FoodGroup> DeleteOneAsync(FoodGroup foodGroup)
        {
            _context.FoodGroups.Remove(foodGroup);
            await _context.SaveChangesAsync();

            _context.Entry(foodGroup).State = EntityState.Detached;
            return(foodGroup);
        }
Ejemplo n.º 9
0
 public static FoodGroupJson FromFoodGroup(FoodGroup foodGroup)
 {
     return(new FoodGroupJson
     {
         Code = foodGroup.Code,
         Description = foodGroup.Description
     });
 }
        public async Task <FoodGroup> CreateOneAsync(FoodGroup foodGroup)
        {
            await _context.FoodGroups.AddAsync(foodGroup);

            await _context.SaveChangesAsync();

            _context.Entry(foodGroup).State = EntityState.Detached;
            return(foodGroup);
        }
Ejemplo n.º 11
0
 public static FoodGroupDetailJson FromFoodGroupAndFoodItemList(FoodGroup foodGroup, IEnumerable <FoodItem> foods)
 {
     return(new FoodGroupDetailJson
     {
         Code = foodGroup.Code,
         Description = foodGroup.Description,
         Foods = foods.Select(food => FoodItemJson.FromFoodItem(food)).OrderBy(food => food.ShortDescription).ToArray()
     });
 }
 public ActionResult Edit([Bind(Include = "ID,FoodGroup1")] FoodGroup foodGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(foodGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(foodGroup));
 }
Ejemplo n.º 13
0
        public List <FoodGroup> getCategoryeMenu(MODEL.Criteria.reqeMenu req)
        {
            SqlConnection    conn = new SqlConnection(DataHelper.GetConnectionString());
            DataSet          ds   = new DataSet();
            List <FoodGroup> res  = new List <FoodGroup>();

            try
            {
                conn.Open();
                StringBuilder sqlstr = new StringBuilder();
                //sqlstr.Append("select LV1.category_lv1_id,LV1.category_lv1_name");
                //sqlstr.Append(" from tb_Category_LV1 as [LV1]");
                //sqlstr.Append(" group by LV1.category_lv1_id,LV1.category_lv1_name");
                sqlstr.Append("select LV1.category_lv1_id,LV1.category_lv1_name");
                sqlstr.Append(",LV2.category_lv2_id,LV2.category_lv2_name");
                sqlstr.Append(" from tb_Menu as menu");
                sqlstr.Append(" inner join tb_Category_LV1 as [LV1] on LV1.category_lv1_id = menu.menu_category_lv1");
                sqlstr.Append(" inner join tb_Category_LV2 as [LV2] on LV2.category_lv2_id = menu.menu_category_lv2");
                sqlstr.Append(" where menu.restaurant_id = '" + req.restaurantID + "'");
                if (req.recommend == "2")
                {
                    sqlstr.Append(" and LV2.category_lv2_id = 24");
                }
                sqlstr.Append(" group by LV1.category_lv1_id,LV1.category_lv1_name,LV2.category_lv2_id,LV2.category_lv2_name");
                SqlDataAdapter adp = new SqlDataAdapter(sqlstr.ToString(), conn);
                adp.SelectCommand.CommandType = CommandType.Text;
                adp.Fill(ds);
                DataTable dt = new DataTable();
                dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    FoodGroup f;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        f = new FoodGroup();
                        f.foodsTypeIDLevel1   = dt.Rows[i]["category_lv1_id"].ToString().Trim();
                        f.foodsTypeNameLevel1 = dt.Rows[i]["category_lv1_name"].ToString().Trim();
                        f.foodsTypeIDLevel2   = dt.Rows[i]["category_lv2_id"].ToString().Trim();
                        f.foodsTypeNameLevel2 = dt.Rows[i]["category_lv2_name"].ToString().Trim();
                        res.Add(f);
                    }
                }
            }
            catch (Exception ex)
            {
                res = null;

                //throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(res);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Name")] FoodGroup foodGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(foodGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(foodGroup));
        }
Ejemplo n.º 15
0
    public void IncreaseScore(FoodGroup foodGroup, int score, int bonus)
    {
        if (!canScore)
        {
            return;
        }

        scores[foodGroup] += score;
        bonusScore        += bonus;
        scoreCanvas.UpdateScore(scores, bonusScore);
    }
        public ActionResult Create([Bind(Include = "ID,FoodGroup1")] FoodGroup foodGroup)
        {
            if (ModelState.IsValid)
            {
                db.FoodGroups.Add(foodGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(foodGroup));
        }
Ejemplo n.º 17
0
        public void TestThatIsActiveSetterSetsValueToFalse()
        {
            var foodGroup = new FoodGroup
            {
                IsActive = true
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.IsActive, Is.True);

            foodGroup.IsActive = false;
            Assert.That(foodGroup.IsActive, Is.False);
        }
Ejemplo n.º 18
0
        public void TestThatParentSetterSetsValueWhichAreNull()
        {
            var foodGroup = new FoodGroup
            {
                Parent = DomainObjectMockBuilder.BuildFoodGroupMock()
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.Not.Null);

            foodGroup.Parent = null;
            Assert.That(foodGroup.Parent, Is.Null);
        }
Ejemplo n.º 19
0
        public void TestThatParentSetterSetsValueWhichAreNotNull()
        {
            var foodGroup = new FoodGroup();

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.Null);

            var parentFoodGroupMock = DomainObjectMockBuilder.BuildFoodGroupMock();

            foodGroup.Parent = parentFoodGroupMock;
            Assert.That(foodGroup.Parent, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.EqualTo(parentFoodGroupMock));
        }
Ejemplo n.º 20
0
        public void TestThatForeignKeyAddThrowsArgumentNullExceptionWhenForeignKeyIsNull()
        {
            var foodGroup = new FoodGroup();

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

            var exception = Assert.Throws <ArgumentNullException>(() => foodGroup.ForeignKeyAdd(null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("foreignKey"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public async Task <FoodGroupResponseObject> CreateOneAsync(FoodGroup t)
        {
            var item = await _foodGroupRepository.FindOneByNameAsync(t.Name);

            if (item != null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound,
                                                $"FoodGroup with name {t.Name} already exists");
            }

            await _foodGroupRepository.CreateOneAsync(t);

            return(FoodGroupResponseObject.FromEntity(t));
        }
Ejemplo n.º 22
0
        public void TestThatTranslationAddThrowsArgumentNullExceptionWhenTranslationIsNull()
        {
            var foodGroup = new FoodGroup();

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

            var exception = Assert.Throws <ArgumentNullException>(() => foodGroup.TranslationAdd(null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("translation"));
            Assert.That(exception.InnerException, Is.Null);
        }
        // GET: FoodGroups/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FoodGroup foodGroup = db.FoodGroups.Find(id);

            if (foodGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(foodGroup));
        }
Ejemplo n.º 24
0
        public void TestThatParentSetterThrowsArgumentExceptionWhenValueMakesCurcularReference()
        {
            var foodGroupLevel1 = new FoodGroup
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(foodGroupLevel1, Is.Not.Null);
            Assert.That(foodGroupLevel1.Identifier, Is.Not.Null);
            Assert.That(foodGroupLevel1.Identifier.HasValue, Is.True);
            Assert.That(foodGroupLevel1.Parent, Is.Null);

            var foodGroupLevel2 = new FoodGroup
            {
                Identifier = Guid.NewGuid(),
                Parent     = foodGroupLevel1
            };

            Assert.That(foodGroupLevel2, Is.Not.Null);
            Assert.That(foodGroupLevel2.Identifier, Is.Not.Null);
            Assert.That(foodGroupLevel2.Identifier.HasValue, Is.True);
            Assert.That(foodGroupLevel2.Parent, Is.Not.Null);
            Assert.That(foodGroupLevel2.Parent, Is.EqualTo(foodGroupLevel1));

            var foodGroupLevel3 = new FoodGroup
            {
                Identifier = Guid.NewGuid(),
                Parent     = foodGroupLevel2
            };

            Assert.That(foodGroupLevel3, Is.Not.Null);
            Assert.That(foodGroupLevel3.Identifier, Is.Not.Null);
            Assert.That(foodGroupLevel3.Identifier.HasValue, Is.True);
            Assert.That(foodGroupLevel3.Parent, Is.Not.Null);
            Assert.That(foodGroupLevel3.Parent, Is.EqualTo(foodGroupLevel2));

            var exception = Assert.Throws <ArgumentException>(() => foodGroupLevel1.Parent = foodGroupLevel3);

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("value"));
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            // ReSharper disable NotResolvedInText
            Assert.That(exception.Message, Is.EqualTo((new ArgumentException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, foodGroupLevel3, "value"), "value").Message)));
            // ReSharper restore NotResolvedInText
            Assert.That(exception.InnerException, Is.Null);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FoodGroup = await _context.FoodGroup.FirstOrDefaultAsync(m => m.FoodGroupId == id);

            if (FoodGroup == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> OnPostAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FoodGroup = await _context.FoodGroup.FindAsync(id);

            if (FoodGroup != null)
            {
                _context.FoodGroup.Remove(FoodGroup);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 27
0
        public void TestThatConstructorInitializeForeignKey()
        {
            var foodGroup = new FoodGroup();

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Identifier, Is.Null);
            Assert.That(foodGroup.Identifier.HasValue, Is.False);
            Assert.That(foodGroup.Parent, Is.Null);
            Assert.That(foodGroup.IsActive, Is.False);
            Assert.That(foodGroup.Children, Is.Not.Null);
            Assert.That(foodGroup.Children, Is.Empty);
            Assert.That(foodGroup.Translation, Is.Null);
            Assert.That(foodGroup.Translations, Is.Not.Null);
            Assert.That(foodGroup.Translations, Is.Empty);
            Assert.That(foodGroup.ForeignKeys, Is.Not.Null);
            Assert.That(foodGroup.ForeignKeys, Is.Empty);
        }
Ejemplo n.º 28
0
        public List <FoodGroup> getMenuCategoryLV2(string CategoryLV1)
        {
            SqlConnection    conn = new SqlConnection(DataHelper.GetConnectionString());
            DataSet          ds   = new DataSet();
            List <FoodGroup> res  = new List <FoodGroup>();

            try
            {
                conn.Open();
                StringBuilder sqlstr = new StringBuilder();
                sqlstr.Append("SELECT [category_lv2_id]");
                sqlstr.Append(",[category_lv2_name]");
                sqlstr.Append(",[flag]");
                sqlstr.Append(" FROM [Restaurant].[dbo].[tb_Category_LV2]");
                sqlstr.Append(" where flag = '1'");
                sqlstr.Append(" and category_lv1_id = '" + CategoryLV1 + "'");

                SqlDataAdapter adp = new SqlDataAdapter(sqlstr.ToString(), conn);
                adp.SelectCommand.CommandType = CommandType.Text;
                adp.Fill(ds);
                DataTable dt = new DataTable();
                FoodGroup Group;
                dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Group = new FoodGroup();
                        Group.foodsTypeIDLevel2   = dt.Rows[i]["category_lv2_id"].ToString().Trim();
                        Group.foodsTypeNameLevel2 = dt.Rows[i]["category_lv2_name"].ToString().Trim();
                        res.Add(Group);
                    }
                }
            }
            catch (Exception ex)
            {
                res = null;

                //throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(res);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets all slime diets from a Food Group
        /// </summary>
        /// <param name="group">Group to search for</param>
        public static List <SlimeDiet> GetFoodGroupDiets(FoodGroup group)
        {
            List <SlimeDiet> diets = new List <SlimeDiet>();

            foreach (SlimeDefinition def in GameContext.Instance.SlimeDefinitions.Slimes)
            {
                if (def.Diet == null)
                {
                    continue;
                }

                if (HasFoodGroup(def.Diet, group))
                {
                    diets.Add(def.Diet);
                }
            }

            return(diets);
        }
Ejemplo n.º 30
0
        public void TestThatForeignKeyAddAddsForeignKey()
        {
            var foodGroup = new FoodGroup
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.ForeignKeys, Is.Not.Null);
            Assert.That(foodGroup.ForeignKeys, Is.Empty);

            // ReSharper disable PossibleInvalidOperationException
            var foreignKeyMock = DomainObjectMockBuilder.BuildForeignKeyMock(foodGroup.Identifier.Value, foodGroup.GetType());

            // ReSharper restore PossibleInvalidOperationException

            foodGroup.ForeignKeyAdd(foreignKeyMock);
            Assert.That(foodGroup.ForeignKeys, Is.Not.Null);
            Assert.That(foodGroup.ForeignKeys, Is.Not.Empty);
            Assert.That(foodGroup.ForeignKeys.Count(), Is.EqualTo(1));
            Assert.That(foodGroup.ForeignKeys.Contains(foreignKeyMock), Is.True);
        }
Ejemplo n.º 31
0
        public void TestThatParentSetterThrowsArgumentExceptionWhenValueHasNoIdentifier()
        {
            var foodGroup = new FoodGroup();

            Assert.That(foodGroup, Is.Not.Null);
            Assert.That(foodGroup.Parent, Is.Null);

            var exception = Assert.Throws <ArgumentException>(() => foodGroup.Parent = new FoodGroup {
                Identifier = null
            });

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("value"));
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            // ReSharper disable NotResolvedInText
            Assert.That(exception.Message, Is.EqualTo((new ArgumentException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "Identifier"), "value")).Message));
            // ReSharper restore NotResolvedInText
            Assert.That(exception.InnerException, Is.Null);
        }
Ejemplo n.º 32
0
 public Food(string name, FoodGroup group)
 {
     _name = name;
     _group = group;
 }
Ejemplo n.º 33
0
 public CookedFood(string name, FoodGroup group, string cookingMethod)
     : base(name, group)
 {
     _cookingMethod = cookingMethod;
 }