Пример #1
0
        public void TestGetRecordModel()
        {
            EZMoneyModel ezMoneyModel = new EZMoneyModel(); // TODO: 初始化為適當值
            RecordModel  recordModel  = ezMoneyModel.RecordModel;

            Assert.AreEqual(recordModel, ezMoneyModel.RecordModel);
        }
Пример #2
0
        public RecordTemplateModel Create(RecordModel model, Action <RecordTemplateModel> overrides = null)
        {
            var record = new RecordTemplateModel()
            {
                Name                 = model.Description,
                CategoryId           = model.CategoryId,
                Commission           = model.Commission,
                CommissionType       = model.CommissionType,
                CurrencyExchangeRate = model.CurrencyExchangeRate,
                CurrencyId           = model.Currency.Id,
                Description          = model.Description,
                RecordType           = model.RecordType,
                StorageId            = model.StorageId,
                Value                = model.Value,
                UserId               = model.UserId,
                Remark               = model.Remark,
                DebtId               = model.DebtId,
                Debt                 = model.Debt,
                Storage              = model.Storage,
                Category             = model.Category
            };

            overrides?.Invoke(record);
            return(record);
        }
Пример #3
0
 public DbRecord(RecordModel record)
 {
     Id        = record.Id;
     AppName   = record.AppName;
     StartTime = record.StartTime;
     EndTime   = record.EndTime;
 }
Пример #4
0
        public IActionResult Record(RecordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var s = Request.HttpContext.User.Identity.Name;
                if (s == null)
                {
                    return(RedirectToAction("Error"));
                }
                var         user   = _db.User.FirstOrDefault(u => u.Name == s);
                string      stoId  = Request.Path.ToString().Remove(0, 12);
                RecordModel coment = new RecordModel()
                {
                    FIO         = model.FIO,
                    STOId       = stoId,
                    UserId      = user.Id,
                    ModelCar    = model.ModelCar,
                    PhoneNumber = model.PhoneNumber
                };

                _db.Record.Add(coment);
                _db.SaveChanges();
                return(RedirectToAction("Index", new RouteValueDictionary(new { controller = "STO", action = "Index", Id = coment.STOId })));
            }

            return(View(model));
        }
Пример #5
0
        private async Task SetPreviewForRecord(RecordModel record, SaveFileResponseModel response)
        {
            var recordFromSavedFile = MapToRecord(response, "");

            record.Preview = recordFromSavedFile.File;
            await _recordComponent.Update(record);
        }
Пример #6
0
        /// <summary>
        /// Reads each line of the MemoryStream. Foreach line a new Model class is created and the line is writen to the Class property.
        /// Next the RecordModel Class is added to the List<IRecordModel>.
        /// </summary>
        public void ReadMemoryStream()
        {
            MemoryStream MS = GetMemoryStream();

            using (StreamReader sr = new StreamReader(MS))
            {
                try
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        IRecordModel newRecord = new RecordModel();
                        newRecord.RecordLine = line;
                        Records.Add(newRecord);
                    }
                }
                catch (OutOfMemoryException outEx)
                {
                    Console.WriteLine($"OutOfMemoryException: {outEx.Message}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception: {ex.Message} {ex.InnerException} {ex.StackTrace}");
                }
            }
        }
 //constructor of statistic presentation model
 public StatisticPresentationModel(EZMoneyModel ezMoneyModel)
 {
     _categoryModel = ezMoneyModel.CategoryModel;
     _recordModel = ezMoneyModel.RecordModel;
     _statisticModel = ezMoneyModel.StatisticModel;
     InitializeState();
 }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
0
        public void SetSynced(int localRecordId)
        {
            RecordModel record = database.Table <RecordModel>().Where(p => p.LocalRecordId == localRecordId).FirstOrDefaultAsync().Result;

            record.IsEditable = false;
            UpdateRecord(record);
        }
Пример #12
0
 public IActionResult UpdateRecord([FromBody] RecordModel recordModel)
 {
     _logger.LogInformation($"{nameof(RecordController)} : {nameof(UpdateRecord)} was called.");
     try
     {
         if (recordModel == null)
         {
             return(BadRequest("Record is required"));
         }
         if (_recordService.FindById(recordModel.Id) == null)
         {
             return(NotFound("Record not found"));
         }
         _recordService.Update(recordModel);
         _recordService.Save();
         return(Ok());
     }
     catch (DbException exception)
     {
         _logger.LogError(exception.Message);
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception.Message);
         throw;
     }
 }
Пример #13
0
        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);
        }
Пример #14
0
        public async Task <ActionResult> Translate([FromQuery] RecordModel model)
        {
            var record = mapper.Map <RecordModel, Record>(model);
            var result = await service.GetKeywords(record);

            return(Ok(result));
        }
Пример #15
0
 private void CompareRecordDate(RecordModel model)
 {
     if (model.DTime.Date != fileCreateDate.Date)
     {
         CreateFile();
     }
 }
Пример #16
0
        public ActionResult Index()
        {
            RecordModel rm      = new RecordModel();
            var         records = rm.Records.ToList();;

            return(View(records));
        }
Пример #17
0
        public IActionResult PostRecord([FromBody] RecordModel recordModel)
        {
            _logger.LogInformation($"{nameof(RecordController)} : {nameof(PostRecord)} was called.");
            try
            {
                if (recordModel == null)
                {
                    return(BadRequest("Record is required"));
                }

                if (_recordService.FindById(recordModel.Id) != null)
                {
                    return(Conflict("Record already exists"));
                }

                _recordService.Create(recordModel);
                _recordService.Save();
                return(Ok("Record Created"));
            }
            catch (DbException exception)
            {
                _logger.LogError(exception.Message);
                return(BadRequest(exception.Message));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw;
            }
        }
Пример #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());
        }
Пример #19
0
        public void UpdateRecordReturnsBadRequestWhenModelIsInvalid()
        {
            var invalidModel = new RecordModel
            {
                FuelCardId       = 1,
                CorporationId    = 1,
                CostAllocationId = 1
            };

            var fuelCard       = new FuelCard();
            var corporation    = new Corporation();
            var costAllocation = new CostAllocation();

            _fuelCardRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(fuelCard);
            _corporationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(corporation);
            _costAllocationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(costAllocation);

            _sut.ModelState.AddModelError("name", "name is required");

            var result = _sut.UpdateEntity(invalidModel, 1) as BadRequestResult;

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

            _recordRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <Record>()), Times.Never);
            _fuelCardRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _corporationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _costAllocationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _recordRepositoryMock.Verify(m => m.Find(It.IsAny <Expression <Func <Record, bool> > >()), Times.Once);
        }
Пример #20
0
        public void UpdateRecordReturnsOkWhenEverythingIsCorrect()
        {
            var validModel = new RecordModel
            {
                Id               = 1,
                FuelCardId       = 1,
                CorporationId    = 1,
                CostAllocationId = 1
            };

            var fuelCard       = new FuelCard();
            var corporation    = new Corporation();
            var costAllocation = new CostAllocation();

            _recordRepositoryMock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <Record>()))
            .Returns(true);
            _fuelCardRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(fuelCard);
            _corporationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(corporation);
            _costAllocationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(costAllocation);

            var result = _sut.UpdateEntity(validModel, validModel.Id) as OkResult;

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

            _recordRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <Record>()), Times.Once);
            _fuelCardRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _corporationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _costAllocationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _recordRepositoryMock.Verify(m => m.Find(It.IsAny <Expression <Func <Record, bool> > >()), Times.Once);
        }
Пример #21
0
        public ActionResult AddRecord(int patientId)
        {
            if (Session["DoctorId"] != null)
            {
                int docId = int.TryParse(Session["DoctorId"].ToString(), out docId) ? docId : 0;

                if (docId > 0)
                {
                    DbWork db = new DbWork();

                    RecordModel model = new RecordModel();
                    model.Patient = patientId;

                    var diagnosis = db.GetDiagnoses();

                    foreach (var d in diagnosis)
                    {
                        model.Diagnoses.Add(new DiagnosisModel(d));
                    }

                    return(View(model));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #22
0
        public ActionResult AddRecord(RecordModel model)
        {
            if (Session["DoctorId"] != null)
            {
                int docId = int.TryParse(Session["DoctorId"].ToString(), out docId) ? docId : 0;

                if (docId > 0)
                {
                    DbWork db = new DbWork();

                    if (ModelState.IsValid)
                    {
                        db.AddDiagnosis(new Record
                        {
                            Id        = 0,
                            Diagnosis = model.Diagnosis,
                            Patient   = model.Patient,
                            Therapy   = model.Therapy
                        });

                        return(RedirectToAction("Patients", "Doctor"));
                    }
                    else
                    {
                        return(View(model));
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #23
0
 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);
 }
Пример #24
0
        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);
        }
Пример #25
0
 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);
 }
Пример #26
0
        public static bool Update(RecordModel record)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(@"update Record set
				user_id = @user_id,
				description = @description,
                answers = @answers
				time = @time,
                citycode = @citycode,
                score = @score
				where record_id = @record_id"                ,
                                          new SqlParameter("@user_id", record.User_id),
                                          new SqlParameter("@description", SqlHelper.ToDBValue(record.Description)),
                                          new SqlParameter("@answers", SqlHelper.ToDBValue(record.Answers)),
                                          new SqlParameter("@time", record.Time),
                                          new SqlParameter("@citycode", SqlHelper.ToDBValue(record.Citycode)),
                                          new SqlParameter("@score", SqlHelper.ToDBValue(record.Score)),
                                          new SqlParameter("@record_id", record.Record_id)
                                          );
                return(true);
            }
            catch (SqlException)
            {
                return(false);
            }
        }
 private void OpenDetails(RecordModel model, bool isNew = false)
 {
     this.OpenDetailsWindow(new RecordDetailsView(_recordService, model, isNew), () =>
     {
         RefreshTodayTransactions();
     });
 }
Пример #28
0
        public void PostRecordReturnsNotFoundWhenCostAllocationIsNotFound()
        {
            var validModel = new RecordModel
            {
                FuelCardId       = 1,
                CorporationId    = 1,
                CostAllocationId = 1
            };

            var            fuelCard       = new FuelCard();
            var            corporation    = new Corporation();
            CostAllocation costAllocation = null;

            _fuelCardRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(fuelCard);
            _corporationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(corporation);
            _costAllocationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(costAllocation);

            var result = _sut.PostEntity(validModel) as NotFoundObjectResult;

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

            _recordRepositoryMock.Verify(m => m.Add(It.IsAny <Record>()), Times.Never);
            _fuelCardRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _corporationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _costAllocationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _recordRepositoryMock.Verify(m => m.Find(It.IsAny <Expression <Func <Record, bool> > >()), Times.Never);
        }
Пример #29
0
        private void AddTrackedProcess(string appName, DateTime startTime)
        {
            RecordModel record = new RecordModel(appName, startTime);

            DataAccess.AddRecord(ref record);
            CurrentlyTracked.Add(record);
        }
Пример #30
0
        public void PostRecordReturnsOkWhenModelIsValid()
        {
            var validModel = new RecordModel
            {
                FuelCardId       = 1,
                CorporationId    = 1,
                CostAllocationId = 1
            };

            var fuelCard       = new FuelCard();
            var corporation    = new Corporation();
            var costAllocation = new CostAllocation();

            _fuelCardRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(fuelCard);
            _corporationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(corporation);
            _costAllocationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(costAllocation);
            _mapperMock.Setup(m => m.Map <RecordReturnModel>(It.IsAny <Record>()))
            .Returns(new RecordReturnModel());
            _mapperMock.Setup(m => m.Map <Record>(It.IsAny <RecordModel>()))
            .Returns(new Record());
            var result = _sut.PostEntity(validModel) as OkObjectResult;

            Assert.That(result, Is.Not.Null);
            Assert.That((RecordReturnModel)result.Value, Is.Not.Null);

            _recordRepositoryMock.Verify(m => m.Add(It.IsAny <Record>()), Times.Once);
            _fuelCardRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _corporationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _costAllocationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _recordRepositoryMock.Verify(m => m.Find(It.IsAny <Expression <Func <Record, bool> > >()), Times.Once);
        }
Пример #31
0
        public async Task <IActionResult> Get(int Id)
        {
            Stopwatch st = new Stopwatch();

            st.Start();

            RecordModel data   = null;
            string      result = await cache.GetStringAsync($"{Id}-record");

            if (result != null)
            {
                data = JsonConvert.DeserializeObject <RecordModel>(result);
            }
            else
            {
                result = await GetResponseString($"remotestore/{Id}");

                await cache.SetStringAsync($"{Id}-record", result);

                data = JsonConvert.DeserializeObject <RecordModel>(result);
            }

            st.Stop();

            return(new JsonResult(new { elapsed = TimeSpan.FromMilliseconds(st.ElapsedMilliseconds).ToString(), data }));
        }
Пример #32
0
        public void UpdateRecordReturnsBadRequestWhenIdFromModelDoesNotMatchIdFromQueryParameter()
        {
            var validModel = new RecordModel
            {
                FuelCardId       = 1,
                CorporationId    = 1,
                CostAllocationId = 1
            };

            var fuelCard       = new FuelCard();
            var corporation    = new Corporation();
            var costAllocation = new CostAllocation();

            _fuelCardRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(fuelCard);
            _corporationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(corporation);
            _costAllocationRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(costAllocation);

            var result = _sut.UpdateEntity(validModel, validModel.Id + 1) as BadRequestObjectResult;

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

            _recordRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <Record>()), Times.Never);
            _fuelCardRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _corporationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _costAllocationRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
            _recordRepositoryMock.Verify(m => m.Find(It.IsAny <Expression <Func <Record, bool> > >()), Times.Once);
        }
Пример #33
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);
        }
Пример #34
0
 //constructor
 public EZMoneyModel()
 {
     _categoryModel = new CategoryModel();
     _categoryModel.ReadCategoryFromFile();
     _recordModel = new RecordModel(_categoryModel);
     _recordModel.ReadRecordFromFile();
     _statisticModel = new StatisticModel(_categoryModel, _recordModel);
 }
Пример #35
0
 public void TestIncomeStatistics()
 {
     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> statistics = statisticModel.GetIncomeStatistics();
     Assert.AreEqual(1, statistics.Count);
     int amount = 0;
     foreach (Statistic statistic in statistics)
     {
         amount += statistic.Amounts;
     }
     Assert.AreEqual(10000, amount);
 }
Пример #36
0
 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);
 }
Пример #37
0
 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);
 }
Пример #38
0
 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);
 }
Пример #39
0
 //constructor
 public StatisticModel(CategoryModel categoryModel, RecordModel recordModel)
 {
     _categoryModel = categoryModel;
     _recordModel = recordModel;
 }