/// <summary>
        /// Gets current account
        /// </summary>
        public Account GetCurrentAccount(ClaimsPrincipal principal)
        {
            var user = GetCurrentUser(principal);

            if (user == null)
            {
                return(null);
            }

            return(_accountFacade.GetAccount(user.AccountId));
        }
示例#2
0
        public void GetAccount_ExistingAccount_ReturnCorrectAccount()
        {
            var account = new Account
            {
                Badges = new List <AccountBadge>(),
                Costs  = new List <CostInfo>(),
                Name   = "ExpenseManagerAccount01"
            };
            var accountModel = _mapper.Map <Account, AccountModel>(account);

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Accounts.Add(accountModel);
                dbContext.SaveChanges();
            }
            var accountId = accountModel.Id;

            // Act
            var obtainedAccount = _accountFacade.GetAccount(accountId);

            // Assert
            Assert.AreEqual(obtainedAccount, account, "GetAccount failed - accounts do not match.");
        }
示例#3
0
        public void CheckBadgesRequirements()
        {
            const string accountName = "ExpenseManagerAccount01";
            const string typeName    = "Food";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            var type = new CostTypeModel
            {
                Name         = typeName,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var plan = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 1000,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan1 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 100000,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan2 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 1001,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan3 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan4 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            var plan5 = new PlanModel
            {
                Description  = "I want money for food!",
                PlanType     = PlanTypeModel.Save,
                PlannedMoney = 22221,
                PlannedType  = type,
                IsCompleted  = true,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Subtract(new TimeSpan(0, 0, 1, 0))
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                var accountId = account.Id;
                plan.AccountId    = accountId;
                plan.PlannedType  = type;
                plan1.AccountId   = accountId;
                plan1.PlannedType = type;
                plan2.AccountId   = accountId;
                plan2.PlannedType = type;
                plan3.AccountId   = accountId;
                plan3.PlannedType = type;
                plan4.AccountId   = accountId;
                plan4.PlannedType = type;
                plan5.AccountId   = accountId;
                plan5.PlannedType = type;

                db.Plans.Add(plan);
                db.Plans.Add(plan1);
                db.Plans.Add(plan2);
                db.Plans.Add(plan3);
                db.Plans.Add(plan4);
                db.Plans.Add(plan5);
                db.SaveChanges();
                var item = new CostInfoModel()
                {
                    Description          = "bread",
                    AccountId            = accountId,
                    TypeId               = type.Id,
                    IsIncome             = true,
                    Money                = 10001,
                    Created              = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                    Account              = db.Accounts.Find(accountId),
                    Type                 = db.CostTypes.Find(type.Id),
                    Periodicity          = PeriodicityModel.None,
                    PeriodicMultiplicity = 3
                };
                db.CostInfos.Add(item);

                db.Badges.Add(new BadgeModel
                {
                    Accounts    = new List <AccountBadgeModel>(),
                    BadgeImgUri = "badge.png",
                    Name        = "PlanCompleter",
                    Description = "Complete at least 5 plans"
                });

                db.SaveChanges();
            }
            _balanceFacade.CheckBadgesRequirements();
            var badgedAccount = _accountFacade.GetAccount(account.Id);

            Assert.IsTrue(badgedAccount.Badges.Count > 0);
        }