Exemple #1
0
        public void TestWriteRecordToFile()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel         = new RecordModel(categoryModel);
            DateTime    now                 = DateTime.Now;
            DateTime    date                = new DateTime(now.Year, now.Month, now.Day);
            Record      recordMoviePositive = new Record(date, categoryMovie, 100);
            Record      recordMovieNegative = new Record(date, categoryMovie, -100);
            Record      recordWorkPositive  = new Record(date, categoryWork, 100);
            Record      recordWorkNegative  = new Record(date, categoryWork, -100);

            recordModel.AddRecord(recordMoviePositive);
            recordModel.AddRecord(recordMovieNegative);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkNegative);
            BindingList <Record> records = recordModel.Records;

            recordModel.WriteRecordToFile();
            recordModel = new RecordModel(categoryModel);
            recordModel.ReadRecordFromFile();
            Assert.AreEqual(records.Count, recordModel.Records.Count);
        }
        public void TestStatistic()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
            DateTime    now         = DateTime.Now;
            DateTime    date        = new DateTime(now.Year, now.Month, now.Day);
            Record      workRecord  = new Record(date, categoryWork, 1000);

            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 2000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 3000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 4000);
            recordModel.AddRecord(workRecord);
            StatisticModel statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            Statistic      statistic      = statisticModel.GetStatistic(categoryWork, true);

            Assert.AreEqual(10000, statistic.Amounts);
            Assert.AreEqual(categoryWork, statistic.Category);
            Assert.AreEqual(4, statistic.Count);
        }
        public void TestGetBalance()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
            DateTime    now         = DateTime.Now;
            DateTime    date        = new DateTime(now.Year, now.Month, now.Day);
            Record      movieRecord = new Record(date, categoryMovie, -1000);

            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -2000);
            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -3000);
            recordModel.AddRecord(movieRecord);
            Record workRecord = new Record(date, categoryWork, 1000);

            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 2000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 3000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 4000);
            recordModel.AddRecord(workRecord);
            StatisticModel statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            int            balance        = statisticModel.GetBalance(recordModel.Records);

            Assert.AreEqual(4000, balance);
        }
        public void TestGetExpenseStatistics()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
            DateTime    now         = DateTime.Now;
            DateTime    date        = new DateTime(now.Year, now.Month, now.Day);
            Record      movieRecord = new Record(date, categoryMovie, 1000);

            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, 1000);
            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -1000);
            recordModel.AddRecord(movieRecord);
            Record workRecord = new Record(date, categoryWork, 1000);

            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 2000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 3000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 4000);
            recordModel.AddRecord(workRecord);
            StatisticModel          statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            BindingList <Statistic> statistics;

            statistics = statisticModel.GetExpenseStatistics();
            Assert.AreEqual(1, statistics.Count);
        }
        public void TestGetAmounts()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
            DateTime    now         = DateTime.Now;
            DateTime    date        = new DateTime(now.Year, now.Month, now.Day);
            Record      movieRecord = new Record(date, categoryMovie, -1000);

            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -2000);
            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -3000);
            recordModel.AddRecord(movieRecord);
            Record workRecord = new Record(date, categoryWork, 1000);

            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 2000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 3000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 4000);
            recordModel.AddRecord(workRecord);
            StatisticModel statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            int            income         = statisticModel.GetAmounts(recordModel.Records, true);

            Assert.AreEqual(10000, income);
            int expense = statisticModel.GetAmounts(recordModel.Records, false);

            Assert.AreEqual(-6000, expense);
        }
        public void TestSetPercent()
        {
            const String  SEVENTY_FIVE_PERCENT  = "75%";
            const String  TWENTY_FIVE_PERCENT   = "25%";
            CategoryModel categoryModel         = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie         = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryEntertainment = new Category(CATEGORY_NAME_ENTERTAINMENT);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryEntertainment);
            RecordModel             recordModel    = new RecordModel(categoryModel);                 // TODO: 初始化為適當值
            StatisticModel          statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            BindingList <Statistic> statistics     = new BindingList <Statistic>();                  // TODO: 初始化為適當值
            Statistic statisticMovie         = new Statistic(categoryMovie);
            Statistic statisticEntertainment = new Statistic(categoryEntertainment);

            statisticMovie.Amounts = 1000;
            statistics.Add(statisticMovie);
            statisticEntertainment.Amounts = 3000;
            statistics.Add(statisticEntertainment);
            int amounts = 4000; // TODO: 初始化為適當值

            statisticModel.SetPercent(statistics, amounts);
            Assert.AreEqual(TWENTY_FIVE_PERCENT, statisticMovie.Percent);
            Assert.AreEqual(SEVENTY_FIVE_PERCENT, statisticEntertainment.Percent);
        }
Exemple #7
0
        public void TestGetRecordsByCategory()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel         = new RecordModel(categoryModel);
            DateTime    now                 = DateTime.Now;
            DateTime    date                = new DateTime(now.Year, now.Month, now.Day);
            Record      recordMoviePositive = new Record(date, categoryMovie, 100);
            Record      recordMovieNegative = new Record(date, categoryMovie, -100);
            Record      recordWorkPositive  = new Record(date, categoryWork, 100);
            Record      recordWorkNegative  = new Record(date, categoryWork, -100);

            recordModel.AddRecord(recordMoviePositive);
            recordModel.AddRecord(recordMovieNegative);
            recordModel.AddRecord(recordMovieNegative);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            BindingList <Record> movieRecords;

            movieRecords = recordModel.GetRecords(categoryMovie);
            Assert.AreEqual(3, movieRecords.Count);
            BindingList <Record> workRecords;

            workRecords = recordModel.GetRecords(categoryWork);
            Assert.AreEqual(7, workRecords.Count);
        }
Exemple #8
0
        public void TestAddRecord()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel         = new RecordModel(categoryModel);
            DateTime    now                 = DateTime.Now;
            DateTime    date                = new DateTime(now.Year, now.Month, now.Day);
            Record      recordMoviePositive = new Record(date, categoryMovie, 100);
            Record      recordMovieNegative = new Record(date, categoryMovie, -100);
            Record      recordWorkPositive  = new Record(date, categoryWork, 100);
            Record      recordWorkNegative  = new Record(date, categoryWork, -100);

            recordModel.AddRecord(recordMoviePositive);
            Assert.AreEqual(1, recordModel.Records.Count);
            recordModel.AddRecord(recordMovieNegative);
            Assert.AreEqual(2, recordModel.Records.Count);
            recordModel.AddRecord(recordWorkPositive);
            Assert.AreEqual(3, recordModel.Records.Count);
            recordModel.AddRecord(recordWorkNegative);
            Assert.AreEqual(4, recordModel.Records.Count);
        }
Exemple #9
0
        public void TestAddCategory1()
        {
            CategoryModel categoryModel = new CategoryModel();

            categoryModel.AddCategory(CATEGORY_NAME_MOVIE);
            Assert.AreEqual(1, categoryModel.Categories.Count);
            categoryModel.AddCategory(CATEGORY_NAME_WORK);
            Assert.AreEqual(2, categoryModel.Categories.Count);
        }
Exemple #10
0
        public void TestIsExistByCategoryName()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值

            categoryModel.AddCategory(new Category(CATEGORY_NAME_MOVIE));
            categoryModel.AddCategory(new Category(CATEGORY_NAME_WORK));
            Assert.IsTrue(categoryModel.IsExist(CATEGORY_NAME_MOVIE));
            Assert.IsTrue(categoryModel.IsExist(CATEGORY_NAME_WORK));
            Assert.IsFalse(categoryModel.IsExist(CATEGORY_NAME_ENTERTAINMENT));
        }
Exemple #11
0
        public void TestGetCategories()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            Assert.AreEqual(categoryMovie, categoryModel.Categories[0]);
            Assert.AreEqual(categoryWork, categoryModel.Categories[1]);
        }
Exemple #12
0
        public void TestGetCategoryIndex()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            Assert.AreEqual(0, categoryModel.GetCategoryIndex(categoryMovie));
            Assert.AreEqual(1, categoryModel.GetCategoryIndex(categoryWork));
        }
Exemple #13
0
        public void TestGetCategory()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            Assert.AreEqual(categoryMovie, categoryModel.GetCategory(0));
            Assert.AreEqual(categoryWork, categoryModel.GetCategory(1));
            Assert.AreEqual(new Category(string.Empty), categoryModel.GetCategory(2));
        }
Exemple #14
0
        public void TestGetCategoryModel()
        {
            EZMoneyModel  ezMoneyModel  = new EZMoneyModel();                // TODO: 初始化為適當值
            Category      movieCategory = new Category(CATEGORY_NAME_MOVIE); // TODO: 初始化為適當值
            Category      workCategory  = new Category(CATEGORY_NAME_WORK);  // TODO: 初始化為適當值
            CategoryModel categoryModel = ezMoneyModel.CategoryModel;

            categoryModel.AddCategory(movieCategory);
            categoryModel.AddCategory(workCategory);
            Assert.AreEqual(0, categoryModel.GetCategoryIndex(movieCategory));
            Assert.AreEqual(1, categoryModel.GetCategoryIndex(workCategory));
        }
Exemple #15
0
        public void TestIsExist()
        {
            CategoryModel categoryModel         = new CategoryModel();
            Category      categoryMovie         = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork          = new Category(CATEGORY_NAME_WORK);
            Category      categoryEntertainment = new Category(CATEGORY_NAME_ENTERTAINMENT);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            Assert.IsTrue(categoryModel.IsExist(categoryMovie));
            Assert.IsTrue(categoryModel.IsExist(categoryWork));
            Assert.IsFalse(categoryModel.IsExist(categoryEntertainment));
        }
Exemple #16
0
        protected void btnAddCategory_Click(object sender, EventArgs e)
        {
            categoryLogic = new CategoryModel();
            categoryLogic.AddCategory(txtCategoryName.Text);

            Response.Redirect("category.aspx");
        }
Exemple #17
0
        public void TestChangeAmount()
        {
            EZMoneyModel            ezMoneyModel  = new EZMoneyModel();                        // TODO: 初始化為適當值
            RecordPresentationModel recordPModel  = new RecordPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            RecordModel             recordModel   = ezMoneyModel.RecordModel;
            CategoryModel           categoryModel = ezMoneyModel.CategoryModel;

            recordModel.Records.Clear();
            categoryModel.Categories.Clear();
            Category category = new Category(CATEGORY_NAME_MOVIE);

            categoryModel.AddCategory(category);
            DateTime date   = DateTime.Now; // TODO: 初始化為適當值
            Record   record = new Record(date, category, 100);

            recordModel.AddRecord(record);
            recordPModel.SelectRecord(0);
            const String AMOUNT_ORIGIN = "100";
            const string AMOUNT_AFTER  = "200";

            Assert.AreEqual(AMOUNT_ORIGIN, recordPModel.Amount);
            recordPModel.ChangeAmount(AMOUNT_AFTER);
            Assert.AreEqual(AMOUNT_AFTER, recordPModel.Amount);
            recordPModel.IsSelectionMode = false;
            recordPModel.ChangeAmount(AMOUNT_AFTER);
            Assert.AreEqual(AMOUNT_AFTER, recordPModel.Amount);
        }
Exemple #18
0
        public void TestModify()
        {
            EZMoneyModel            ezMoneyModel  = new EZMoneyModel();                        // TODO: 初始化為適當值
            RecordPresentationModel recordPModel  = new RecordPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            RecordModel             recordModel   = ezMoneyModel.RecordModel;
            CategoryModel           categoryModel = ezMoneyModel.CategoryModel;

            recordModel.Records.Clear();
            categoryModel.Categories.Clear();
            Category category = new Category(CATEGORY_NAME_MOVIE);

            categoryModel.AddCategory(category);
            DateTime     date          = DateTime.Now; // TODO: 初始化為適當值
            int          categoryIndex = 0;            // TODO: 初始化為適當值
            string       amount        = string.Empty; // TODO: 初始化為適當值
            const string NEW_AMOUNT    = "100";

            recordPModel.Add(date, categoryIndex, amount);
            Assert.AreEqual(1, recordModel.Records.Count);
            recordPModel.Modify(date, 0, NEW_AMOUNT);
            Assert.AreEqual(1, recordModel.Records.Count);
            Assert.AreEqual(NEW_AMOUNT, recordModel.Records[0].Amount.ToString());
            recordPModel.IsIncomeCheck  = false;
            recordPModel.IsExpenseCheck = true;
            recordPModel.Modify(date, 0, NEW_AMOUNT);
            Assert.AreEqual(1, recordModel.Records.Count);
            Assert.AreEqual("-" + NEW_AMOUNT, recordModel.Records[0].Amount.ToString());
        }
        public void TestStatisticDataGridViewDataSource()
        {
            CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
            DateTime    now         = DateTime.Now;
            DateTime    date        = new DateTime(now.Year, now.Month, now.Day);
            Record      movieRecord = new Record(date, categoryMovie, -1000);

            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -2000);
            recordModel.AddRecord(movieRecord);
            movieRecord = new Record(date, categoryMovie, -3000);
            recordModel.AddRecord(movieRecord);
            Record workRecord = new Record(date, categoryWork, 1000);

            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 2000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 3000);
            recordModel.AddRecord(workRecord);
            workRecord = new Record(date, categoryWork, 4000);
            recordModel.AddRecord(workRecord);
            StatisticModel          statisticModel    = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
            BindingList <Statistic> incomeStatistics  = statisticModel.GetStatisticDataGridViewDataSource(true);
            BindingList <Statistic> expenseStatistics = statisticModel.GetStatisticDataGridViewDataSource(false);

            Assert.AreEqual(1, incomeStatistics.Count);
            int incomeAmount = 0;

            foreach (Statistic statistic in incomeStatistics)
            {
                incomeAmount += statistic.Amounts;
            }
            Assert.AreEqual(10000, incomeAmount);
            int expenseAmount = 0;

            foreach (Statistic statistic in expenseStatistics)
            {
                expenseAmount += statistic.Amounts;
            }
            Assert.AreEqual(-6000, expenseAmount);
        }
Exemple #20
0
 public IActionResult Create(CategoryModel categoryModel)
 {
     if (ModelState.IsValid)
     {
         categoryModel.AddCategory();
     }
     return(RedirectToAction("GetAll"));
 }
Exemple #21
0
        public void TestWriteCategoryToFile()
        {
            CategoryModel categoryModel         = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie         = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork          = new Category(CATEGORY_NAME_WORK);
            Category      categoryEntertainment = new Category(CATEGORY_NAME_ENTERTAINMENT);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            categoryModel.AddCategory(categoryEntertainment);
            Assert.AreEqual(3, categoryModel.Categories.Count);
            categoryModel.WriteCategoryToFile();
            categoryModel = new CategoryModel();
            categoryModel.ReadCategoryFromFile();
            Assert.AreEqual(3, categoryModel.Categories.Count);
            Assert.AreEqual(categoryMovie, categoryModel.GetCategory(0));
            Assert.AreEqual(categoryWork, categoryModel.GetCategory(1));
            Assert.AreEqual(categoryEntertainment, categoryModel.GetCategory(2));
        }
Exemple #22
0
        public void TestGetRecordsWithCategoryAndPositive()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            RecordModel recordModel         = new RecordModel(categoryModel);
            DateTime    now                 = DateTime.Now;
            DateTime    date                = new DateTime(now.Year, now.Month, now.Day);
            Record      recordMoviePositive = new Record(date, categoryMovie, 100);
            Record      recordMovieNegative = new Record(date, categoryMovie, -100);
            Record      recordWorkPositive  = new Record(date, categoryWork, 100);
            Record      recordWorkNegative  = new Record(date, categoryWork, -100);

            recordModel.AddRecord(recordMoviePositive);
            recordModel.AddRecord(recordMovieNegative);
            recordModel.AddRecord(recordMovieNegative);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkPositive);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            recordModel.AddRecord(recordWorkNegative);
            BindingList <Record> positiveMovieRecords;

            positiveMovieRecords = recordModel.GetRecords(categoryMovie, true);
            Assert.AreEqual(1, positiveMovieRecords.Count);
            BindingList <Record> negativeMovieRecords;

            negativeMovieRecords = recordModel.GetRecords(categoryMovie, false);
            Assert.AreEqual(2, negativeMovieRecords.Count);
            BindingList <Record> positiveWorkRecords;

            positiveWorkRecords = recordModel.GetRecords(categoryWork, true);
            Assert.AreEqual(3, positiveWorkRecords.Count);
            BindingList <Record> negativeWorkRecords;

            negativeWorkRecords = recordModel.GetRecords(categoryWork, false);
            Assert.AreEqual(4, negativeWorkRecords.Count);
        }
Exemple #23
0
        public void TestSelectCategory()
        {
            EZMoneyModel            ezMoneyModel  = new EZMoneyModel();                        // TODO: 初始化為適當值
            RecordPresentationModel recordPModel  = new RecordPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            RecordModel             recordModel   = ezMoneyModel.RecordModel;
            CategoryModel           categoryModel = ezMoneyModel.CategoryModel;

            recordPModel.InitializeState();
            categoryModel.AddCategory(CATEGORY_NAME_WORK);
            recordPModel.SelectCategory(0);
            Assert.AreEqual(0, recordPModel.CategoryIndex);
        }
        public void TestClickDataGridView()
        {
            EZMoneyModel ezMoneyModel = new EZMoneyModel();                                            // TODO: 初始化為適當值
            StatisticPresentationModel statisticPModel = new StatisticPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            CategoryModel categoryModel = ezMoneyModel.CategoryModel;
            RecordModel   recordModel   = ezMoneyModel.RecordModel;
            Category      category1     = new Category(CATEGORY_NAME_WORK);
            Category      category2     = new Category(CATEGORY_NAME_MOVIE);

            categoryModel.AddCategory(category1);
            categoryModel.AddCategory(category2);
            DateTime date    = DateTime.Now;
            Record   record1 = new Record(date, category1, 100);
            Record   record2 = new Record(date, category1, 200);
            Record   record3 = new Record(date, category1, 300);
            Record   record4 = new Record(date, category1, 400);
            Record   record5 = new Record(date, category2, -100);
            Record   record6 = new Record(date, category2, -200);
            Record   record7 = new Record(date, category2, -300);

            recordModel.AddRecord(record1);
            recordModel.AddRecord(record2);
            recordModel.AddRecord(record3);
            recordModel.AddRecord(record4);
            recordModel.AddRecord(record5);
            recordModel.AddRecord(record6);
            recordModel.AddRecord(record7);
            statisticPModel.InitializeState();
            BindingList <Record> records = statisticPModel.ClickDataGridView(category1);

            Assert.AreEqual(4, statisticPModel.RecordList.Count);
            Assert.AreEqual(records, statisticPModel.RecordList);
            statisticPModel.ChangeRadioButton(false);
            statisticPModel.ClickDataGridView(category2);
            Assert.AreEqual(3, statisticPModel.RecordList.Count);
        }
Exemple #25
0
        public ActionResult Create(CATEGORY category)
        {
            try
            {
                jsonResultMessage = categoryContainsError(category);
                if (jsonResultMessage == "")
                {
                    CategoryModel.AddCategory(category);
                }
            }
            catch
            {
                jsonResultMessage = ErrorMessage.INTERNAL_ERROR;
            }

            return(Json(jsonResultMessage == "" ? "" : jsonResultMessage, JsonRequestBehavior.AllowGet));
        }
Exemple #26
0
        public HttpResponseMessage Post(CategoryDTO categoryDTO)
        {
            HttpResponseMessage responseMessage;

            bool response = categoryModel.AddCategory(categoryDTO);

            if (response)
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.ExpectationFailed);
            }

            return(responseMessage);
        }
Exemple #27
0
        public HttpResponseMessage Post(CategoryDTO categoryDTO)
        {
            HttpResponseMessage responseMessage;
            JSendMessage        json;
            bool response = categoryModel.AddCategory(categoryDTO);

            if (response)
            {
                json            = new JSendMessage("success", "Category successfully added");
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "Something bad happened");
                responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json);
            }

            return(responseMessage);
        }
 public ActionResult AddCategory(CategoryModel Category)
 {
     if (Convert.ToInt32(Session["UserRollId"]) == 1)
     {
         CategoryModel categories = new CategoryModel();
         if (Category.categoryId == 0)
         {
             categories.AddCategory(Category);
             return(Json("Category added Succesfully ", JsonRequestBehavior.AllowGet));
         }
         else
         {
             categories.UpdateCategory(Category);
             return(Json("Category Update Succesfully ", JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         return(Redirect("/Admin/index"));
     }
 }
Exemple #29
0
        public void TestIsValidRecordAdd()
        {
            EZMoneyModel            ezMoneyModel  = new EZMoneyModel();                        // TODO: 初始化為適當值
            RecordPresentationModel recordPModel  = new RecordPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            RecordModel             recordModel   = ezMoneyModel.RecordModel;
            CategoryModel           categoryModel = ezMoneyModel.CategoryModel;

            recordPModel.InitializeState();
            const string AMOUNT       = "100";
            const string NOT_NUMBER   = "A";
            string       errorMessage = string.Empty;
            Category     category     = new Category(CATEGORY_NAME_MOVIE);

            categoryModel.AddCategory(category);
            Assert.IsFalse(recordPModel.IsValidRecordAdd(-1, AMOUNT, ref errorMessage));
            Assert.AreEqual(RecordPresentationModel.NO_SELECT_CATEGORY_INFO, errorMessage);
            Assert.IsTrue(recordPModel.IsValidRecordAdd(0, AMOUNT, ref errorMessage));
            Assert.AreEqual(RecordPresentationModel.EMPTY_ERROR_MESSAGE, errorMessage);
            Assert.IsFalse(recordPModel.IsValidRecordAdd(0, NOT_NUMBER, ref errorMessage));
            Assert.AreEqual(RecordPresentationModel.TEXT_IS_NOT_NUMBER_INFO, errorMessage);
        }
Exemple #30
0
        public void TestCancel()
        {
            EZMoneyModel            ezMoneyModel  = new EZMoneyModel();                        // TODO: 初始化為適當值
            RecordPresentationModel recordPModel  = new RecordPresentationModel(ezMoneyModel); // TODO: 初始化為適當值
            RecordModel             recordModel   = ezMoneyModel.RecordModel;
            CategoryModel           categoryModel = ezMoneyModel.CategoryModel;

            recordModel.Records.Clear();
            categoryModel.Categories.Clear();
            Category category = new Category(CATEGORY_NAME_MOVIE);

            categoryModel.AddCategory(category);
            DateTime date   = DateTime.Now; // TODO: 初始化為適當值
            Record   record = new Record(date, category, 100);

            recordModel.AddRecord(record);
            recordPModel.SelectRecord(0);
            Assert.AreEqual(true, recordPModel.IsSelectionMode);
            recordPModel.Cancel();
            Assert.AreEqual(false, recordPModel.IsSelectionMode);
        }