コード例 #1
0
        /// <summary>
        /// Intial System consists of:
        /// Three user: daniel with $120, jennie with $100, tom with $80
        /// Private Recipes: daniel has 2, jennie has 1, tom has 1 purchased from the market
        /// Public reicpes: daniel has 1 with price of 20, with review from tom
        /// </summary>
        public void InitializeSystem()
        {
            var userDaniel = DomainObjectsGenerator.GenerateRandoMoneyAccount("daniel");
            var userJennie = DomainObjectsGenerator.GenerateRandoMoneyAccount("jennie");
            var userTom = DomainObjectsGenerator.GenerateRandoMoneyAccount("tom");

            var recipeDaniel1 = DomainObjectsGenerator.GenerateRandomPrivateRecipe(4, userDaniel.UserId);
            var recipeDaniel2 = DomainObjectsGenerator.GenerateRandomPrivateRecipe(2, userDaniel.UserId);
            var recipeJennie1 = DomainObjectsGenerator.GenerateRandomPrivateRecipe(5, userJennie.UserId);

            var recipeOnMarket = PublicRecipe.ConvertFromPrivateRecipe(recipeDaniel1);
            recipeOnMarket.Id = GetRandomInt();
            if (recipeOnMarket.Items != null)
            {
                foreach (var recipeItem in recipeOnMarket.Items)
                {
                    recipeItem.Id = GetRandomInt();
                }
            }
            recipeOnMarket.Price = 20;
            recipeOnMarket.TimePublished = new DateTime(2016, 3, 20, 11, 0, 0);

            var tomsReview = DomainObjectsGenerator.GenerateRandomReview(recipeOnMarket);
            tomsReview.ReviewerUserId = userTom.UserId;
            tomsReview.Comment = "Good recipe";
            tomsReview.Rating = 4;
            recipeOnMarket.AddReview(tomsReview);

            _moneyAccounts = new List<MoneyAccount>
            {
                userDaniel,
                userJennie,
                userTom
            };

            _marketRecipes = new List<PublicRecipe>
            {
                recipeOnMarket
            };

            _moneyAccountRepository = new MoneyAccountRepository(_moneyAccounts);
            _publicRecipeRepository = new PublicRecipeRepository(_marketRecipes);

            _market = new Market(_publicRecipeRepository, _moneyAccountRepository);

            var recipeTom = _market.Purchase(recipeOnMarket.Id, "tom");
            recipeTom.PurchaseInformation.TimePurchased = new DateTime(2016, 4, 1, 9, 0, 0);

            _userRecipes = new List<PrivateRecipe>
            {
                recipeDaniel1,
                recipeDaniel2,
                recipeJennie1,
                recipeTom
            };
            _privateRecipeRepository = new PrivateRecipeRepository(_userRecipes);
        }