public DistributionModelTests()
        {
            DebitCardAccount = new AccountModel
            {
                Id           = 1,
                AccountType  = AccountType.DebitCard,
                AvailBalance = 15000
            };
            CashAccount = new AccountModel
            {
                Id           = 2,
                AccountType  = AccountType.Cash,
                AvailBalance = 1200
            };
            FoodFlow = new ExpenseFlowModel
            {
                Id      = 1,
                Balance = 100,
            };
            TechFlow = new ExpenseFlowModel
            {
                Id      = 2,
                Balance = 0
            };

            Debit = new DistributionAccount
            {
                Account           = DebitCardAccount,
                UseInDistribution = true
            };
            Cash = new DistributionAccount
            {
                Account           = CashAccount,
                UseInDistribution = true
            };

            Food = new DistributionItem
            {
                Flow   = FoodFlow,
                Mode   = DistributionMode.RegularExpenses,
                Amount = 10000
            };
            Tech = new DistributionItem
            {
                Flow   = TechFlow,
                Mode   = DistributionMode.Accumulation,
                Amount = 1000
            };

            Model = new DistributionModel
            {
                Accounts = new List <DistributionAccount> {
                    Debit, Cash
                },
                Items = new List <DistributionItem> {
                    Food, Tech
                }
            };
        }
Example #2
0
 public static void ToExpenseFlowModel(this EditExpenseFlow flow, ExpenseFlowModel model)
 {
     model.Number      = flow.Number;
     model.DateCreated = flow.CreationDate.ParseDtFromStandardString();
     model.Name        = flow.Name;
     model.Balance     = flow.Balance.ParseMoneyInvariant();
     model.Categories  = flow.Categories.ToIntList();
 }
Example #3
0
 public ExpenseFlowCommandsTests()
 {
     _model = new ExpenseFlowModel
     {
         Id          = -1,
         Name        = "Путешествия",
         Number      = 1,
         Balance     = 100.50m,
         DateCreated = DateTime.Today.AddHours(3).AddMinutes(45),
     };
 }
Example #4
0
 public static EditExpenseFlow ToEditExpenseFlow(this ExpenseFlowModel model)
 {
     return(new EditExpenseFlow
     {
         Id = model.Id,
         Number = model.Number,
         CreationDate = model.DateCreated.ToStandardString(),
         Name = model.Name,
         OriginalName = model.Name,
         Balance = model.Balance.ToStandardString(),
         Categories = model.Categories.ToCsvString()
     });
 }
Example #5
0
        public async Task <ExpenseFlowModel> Update(ExpenseFlowModel model)
        {
            var other = await _repository.FindByNameAsync <ExpenseFlow>(_currentSession.UserId, model.Name);

            if (other != null)
            {
                if (other.Id != model.Id)
                {
                    throw new ArgumentException("Категория расходов с таким названием уже есть");
                }
                else
                {
                    _repository.Detach(other);
                }
            }

            var flow = new ExpenseFlow
            {
                Name        = model.Name,
                Balance     = model.Balance,
                DateCreated = model.DateCreated,
                Number      = model.Number,
                IsDeleted   = false,
                OwnerId     = _currentSession.UserId
            };

            if (model.Id < 0)
            {
                flow.Version = 1;
                _repository.Create(flow);
            }
            else
            {
                flow.Id      = model.Id;
                flow.Version = model.Version + 1;
                _repository.Update(flow);
                if (model.Categories != null)
                {
                    UpdateFlowCategories(flow.Id, model.Categories);
                }
            }

            await _repository.SaveChangesAsync().ConfigureAwait(false);

            model.Id      = flow.Id;
            model.Version = flow.Version;
            return(model);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            return(await ExpenseFlow.ProcessAsync(ModelState, nameof(ExpenseFlow),
                                                  async() =>
            {
                var model = new ExpenseFlowModel {
                    Id = -1
                };
                ExpenseFlow.ToExpenseFlowModel(model);
                await _expenseFlowCommands.Update(model);
                return RedirectToPage("./ExpenseFlows");
            },

                                                  async() => await Task.FromResult(Page())
                                                  ));
        }
Example #7
0
        public async void Update_NewFlow_VersionEqualsOne()
        {
            using (var session = await CreateDefaultSession())
            {
                var queries = session.UnitOfWork.GetQueryRepository <ExpenseFlow>();
                var efc     = session.CreateExpenseFlowCommands();
                _model = await efc.Update(_model);

                Assert.True(_model.Id > 0);

                var flow = await queries.GetById(_model.Id);

                flow.Should().NotBeNull();
                flow.Name.ShouldBeEquivalentTo(_model.Name);
                flow.Balance.ShouldBeEquivalentTo(_model.Balance);
                flow.DateCreated.ShouldBeEquivalentTo(_model.DateCreated);
                flow.Version.ShouldBeEquivalentTo(1);
            }
        }
Example #8
0
        public async void Update_UpdateFlow_VersionIncreased()
        {
            using (var session = await CreateDefaultSession())
            {
                var efc = session.CreateExpenseFlowCommands();
                _model.DateCreated = DateTime.Today;
                _model             = await efc.Update(_model); // created first

                _model.Id.Should().BeGreaterThan(0);
            }

            using (var session = await CreateDefaultSession())
            {
                var efc     = session.CreateExpenseFlowCommands();
                var queries = session.UnitOfWork.GetQueryRepository <ExpenseFlow>();
                _model.Balance -= 50;
                await efc.Update(_model); // flow updated

                var flow = await queries.GetById(_model.Id);

                flow.Version.ShouldBeEquivalentTo(2);
            }
        }