Example #1
0
        public void GetUser_ExistingUser_ReturnCorrectUser()
        {
            Guid userId;
            var  user = new User
            {
                AccessType = AccountAccessType.Full,
                Email      = "*****@*****.**",
                Name       = "SomeUser"
            };
            var userModel = _mapper.Map <User, UserModel>(user);

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Users.Add(userModel);
                dbContext.SaveChanges();
                userId = userModel.Id;
            }
            user.Id = userId;

            // Act
            var obtainedUser = _accountFacade.GetUser(user.Id);

            // Assert
            Assert.AreEqual(obtainedUser, user, "GetUser failed - users do not match.");
        }
Example #2
0
        public void ListUsers_CoupleOfExistingUsers_FiltersUser()
        {
            var user1 = new User
            {
                AccessType = AccountAccessType.Full,
                Email      = "*****@*****.**",
                Name       = "SomeUser"
            };
            var userModel1 = _mapper.Map <User, UserModel>(user1);
            var user2      = new User
            {
                AccessType = AccountAccessType.Read,
                Email      = "*****@*****.**",
                Name       = "SomeUser2"
            };
            var userModel2 = _mapper.Map <User, UserModel>(user2);

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Users.Add(userModel1);
                dbContext.Users.Add(userModel2);
                dbContext.SaveChanges();
            }

            // Act
            var obtainedUsers = _accountFacade.ListUsers(null, AccountAccessType.Read, null, null);

            // Assert
            Assert.That(obtainedUsers.Count == 1 && obtainedUsers.First().AccessType == AccountAccessType.Read, "ListUsers failed - actual result does not match the expected one.");
        }
Example #3
0
        public void ListBadgesTest2()
        {
            // Arrange
            const string badgeName1 = "Organizer";
            const string badgeName2 = "Survivor";

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Badges.Add(new BadgeModel()
                {
                    Name        = badgeName1,
                    Description = "Add your first expense",
                    BadgeImgUri = "picture"
                });
                dbContext.Badges.Add(new BadgeModel()
                {
                    Name        = badgeName2,
                    Description = "I will survive",
                    BadgeImgUri = "picture"
                });
                dbContext.SaveChanges();
            }

            // Act
            var badges = _balanceFacade.ListBadges(badgeName1, null);

            // Assert
            Assert.That(badges.Count == 1, "Badge was not listed.");
        }
Example #4
0
        public void DeleteUser_ExistingUser_UserIsNotPresentInTheDB()
        {
            Guid userId;
            var  user = new User
            {
                AccessType = AccountAccessType.Full,
                Email      = "*****@*****.**",
                Name       = "SomeUser"
            };
            var userModel = _mapper.Map <User, UserModel>(user);

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Users.Add(userModel);
                dbContext.SaveChanges();
                userId = userModel.Id;
            }
            user.Id = userId;

            // Act
            _accountFacade.DeleteUser(user.Id);

            // Assert
            bool userExistsInDb;

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                userExistsInDb = dbContext.Users.Find(user.Id) != null;
            }

            Assert.AreEqual(userExistsInDb, false, "DeleteUser failed - users still exists in the db.");
        }
Example #5
0
        public void UpdateBadgeTest()
        {
            // Arrange
            const string badgeName1  = "Organizer";
            const string badgeName2  = "Survivor";
            var          editedBadge = new Badge
            {
                Name        = badgeName2,
                BadgeImgUri = "picture",
                Description = "I will survive"
            };

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Badges.Add(new BadgeModel()
                {
                    Name        = badgeName1,
                    Description = "Add your first expense",
                    BadgeImgUri = "picture"
                });
                dbContext.SaveChanges();
            }

            // Act
            _balanceFacade.UpdateBadge(editedBadge);

            // Assert
            var updatedBadge = GetBadgeByName(badgeName2);

            Assert.That(updatedBadge != null, "Badge was not updated.");
        }
Example #6
0
        public void GetBadgeTest()
        {
            // Arrange
            const string badgeName = "Organizer";
            var          badge     = new BadgeModel()
            {
                Name        = badgeName,
                Description = "Add your first expense",
                BadgeImgUri = "picture"
            };
            Guid badgeId;

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Badges.Add(badge);
                dbContext.SaveChanges();
                badgeId = badge.Id;
            }

            // Act
            var myBadge = _balanceFacade.GetBadge(badgeId);

            // Assert
            Assert.That(myBadge.Name == badgeName, "Badge was not got.");
        }
Example #7
0
        public void UpdateAccount_ExistingAccount_UpdatesAccountName()
        {
            // Arrange
            const string accountName2 = "ExpenseManagerAccount02";
            Guid         accountId;
            var          accountEntity = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = "ExpenseManagerAccount01"
            };

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                dbContext.Accounts.Add(accountEntity);
                dbContext.SaveChanges();
                accountId = accountEntity.Id;
            }
            var editedAccount = _mapper.Map <AccountModel, Account>(accountEntity);

            editedAccount.Name = accountName2;

            // Act
            _accountFacade.UpdateAccount(editedAccount);

            // Assert
            var updatedAccount = GetAccountById(accountId);

            Assert.That(updatedAccount.Name.Equals(accountName2), "Account name was not updated.");
        }
Example #8
0
        public void ListAccounts_CoupleOfExistingAccounts_FiltersAccount()
        {
            const string account2Name = "ExpenseManagerAccount02";
            var          account1     = new Account
            {
                Badges = new List <AccountBadge>(),
                Costs  = new List <CostInfo>(),
                Name   = "ExpenseManagerAccount01"
            };
            var accountModel1 = _mapper.Map <Account, AccountModel>(account1);
            var account2      = new Account
            {
                Badges = new List <AccountBadge>(),
                Costs  = new List <CostInfo>(),
                Name   = account2Name
            };
            var accountModel2 = _mapper.Map <Account, AccountModel>(account2);

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

            // Act
            var obtainedAccounts = _accountFacade.ListAccounts(account2Name, null);

            // Assert
            Assert.That(obtainedAccounts.Count == 1 && obtainedAccounts.First().Name.Equals(account2Name), "ListAccounts failed - actual result does not match with expected one");
        }
Example #9
0
        public void CheckAllMaxSpendDeadlinesTest()
        {
            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.MaxSpend,
                PlannedMoney = 10000,
                PlannedType  = type,
                IsCompleted  = false,
                Start        = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                Deadline     = DateTime.Now.Add(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;
                db.Plans.Add(plan);
                db.SaveChanges();
                var item = new CostInfoModel()
                {
                    Description          = "bread",
                    AccountId            = accountId,
                    TypeId               = type.Id,
                    IsIncome             = true,
                    Money                = 999,
                    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.SaveChanges();
            }
            _balanceFacade.CheckAllMaxSpendDeadlines();
            Assert.IsTrue(_balanceFacade.ListPlans(null, null).Count == 1);
            Assert.IsTrue(_balanceFacade.ListPlans(null, null).Single().IsCompleted);
        }
Example #10
0
 public ExpenseController(ExpenseDbContext expenseDbContext, IPhotoService photoService,
                          ILogger <ExpenseController> logger)
 {
     _expenseDbContext = expenseDbContext;
     _photoService     = photoService;
     _logger           = logger;
 }
Example #11
0
        public void ClosePlanTest()
        {
            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 = 10000,
                IsCompleted  = false,
            };

            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;
                db.Plans.Add(plan);
                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.SaveChanges();
            }
            var closeable = _balanceFacade.ListAllCloseablePlans(account.Id);
            var balance   = _balanceFacade.GetBalance(account.Id);

            Assert.IsTrue(closeable.Count == 1, "Plan not found as closeable");
            _balanceFacade.ClosePlan(closeable.Single());
            Assert.IsTrue(balance == _expenseFacade.ListItems(null, null, null, null, null, null, null, false, null).Single().Money + _balanceFacade.GetBalance(account.Id));
        }
Example #12
0
        public void UpdateItemTest()
        {
            // Arrange
            const string accountName = "ExpenseManagerAccount01";
            const string typeName    = "Food";
            Guid         accountId;
            Guid         typeId;
            Guid         infoId;
            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 info = new CostInfoModel
            {
                Description = "bread",
                IsIncome    = true,
                Money       = 25,
                Created     = DateTime.Now
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                accountId      = account.Id;
                typeId         = type.Id;
                info.AccountId = accountId;
                info.TypeId    = typeId;
                db.CostInfos.Add(info);
                db.SaveChanges();
                infoId = info.Id;
            }

            // Act
            _expenseFacade.UpdateItem(new CostInfo
            {
                Id          = infoId,
                Description = "bread",
                AccountId   = accountId,
                TypeId      = typeId,
                IsIncome    = true,
                Money       = 50,
                Created     = DateTime.Now
            });

            // Assert
            Assert.That(GetItemById(infoId).Money == 50, "Item was not updated.");
        }
Example #13
0
 public void PerformAfterTestCleanup()
 {
     using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
     {
         dbContext.Database.Initialize(true);
     }
 }
Example #14
0
 private static void PerformExpenseDbContextSeed()
 {
     using (var expenseDbContext = new ExpenseDbContext("Server=(localdb)\\mssqllocaldb;Database=ExpenseManagerDB;Trusted_Connection=True;MultipleActiveResultSets=true"))
     {
         ExpenseDbInitializer.InitializeDatabase(expenseDbContext);
     }
 }
Example #15
0
 private static AccountModel GetAccountById(Guid accountId)
 {
     using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
     {
         return(dbContext.Accounts.Find(accountId));
     }
 }
Example #16
0
 private static AccountModel GetAccountByName(string accountName)
 {
     using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
     {
         return(dbContext.Accounts.FirstOrDefault(account => account.Name.Equals(accountName)));
     }
 }
Example #17
0
        public void DeleteAccount_ExistingAccount_AccountIsNotPresentInTheDB()
        {
            // Arrange
            var accountModel = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = "ExpenseManagerAccount01"
            };

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

            // Act
            _accountFacade.DeleteAccount(accountId);

            // Assert
            bool accountExistsInDb;

            using (var dbContext = new ExpenseDbContext(Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                accountExistsInDb = dbContext.Users.Find(accountId) != null;
            }

            Assert.That(!accountExistsInDb, "Account was not removed.");
        }
Example #18
0
 public ExpenseService(
     ILogger <ExpenseService> logger,
     ExpenseDbContext dbContext)
 {
     dbContext.Database.EnsureCreated();
     _dbContext = dbContext;
     _logger    = logger;
 }
Example #19
0
 private static void TruncateDB(ExpenseDbContext context)
 {
     DeleteAll <PlanModel>(context);
     DeleteAll <CostInfoModel>(context);
     DeleteAll <CostTypeModel>(context);
     DeleteAll <UserModel>(context);
     DeleteAll <AccountModel>(context);
     DeleteAll <BadgeModel>(context);
 }
Example #20
0
 private static CostTypeModel GetTypeByName(string typeName)
 {
     using (
         var db =
             new ExpenseDbContext(
                 Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
     {
         return(db.CostTypes.FirstOrDefault(model => model.Name.Equals(typeName)));
     }
 }
Example #21
0
 private static CostInfoModel GetItemById(Guid id)
 {
     using (
         var db =
             new ExpenseDbContext(
                 Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
     {
         return(db.CostInfos.Find(id));
     }
 }
Example #22
0
        public void RecomputePeriodicCosts()
        {
            // Arrange
            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
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                var accountId = account.Id;
                var typeId    = type.Id;
                var item      = new CostInfoModel()
                {
                    Description          = "bread",
                    AccountId            = accountId,
                    TypeId               = typeId,
                    IsIncome             = true,
                    Money                = 25,
                    Created              = DateTime.Now.Subtract(new TimeSpan(100, 0, 0, 0)),
                    Account              = db.Accounts.Find(accountId),
                    Type                 = db.CostTypes.Find(typeId),
                    Periodicity          = PeriodicityModel.Month,
                    PeriodicMultiplicity = 3
                };
                db.CostInfos.Add(item);
                db.SaveChanges();
            }


            _balanceFacade.RecomputePeriodicCosts();
            var result = _expenseFacade.ListItems(null, Periodicity.None, null);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result.Single().Description.Equals("bread"));
        }
Example #23
0
        public static async Task Initialize(ExpenseDbContext context, ILogger logger)
        {
            logger?.LogInformation("{0} has been invoked", nameof(SeedProvider));
            var Providers = new Provider[]
            {
                new Provider {
                    ProviderName     = "ALF SAHEL", CountryAddress = "Morocco", CityAddress = "Casablanca", PostalCode = "20100",
                    RouteAddress     = "Route D El Jadida", MilePostAddress = "Km 28", Email = "*****@*****.**",
                    PhoneCountryCode = "212", PhoneLocal = "(0)5229-64705",
                    Facebook         = @"https://www.facebook.com/pages/alf-sahel/172709959593562",
                    CreationDateTime = DateTime.Parse("2013-09-01")
                },

                new Provider {
                    ProviderName = "DISTICA", CountryAddress = "Morocco", CityAddress = "Kenitra", CreationDateTime = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    ProviderName     = "ALF AL  ATLAS", CountryAddress = "Morocco", CityAddress = "Casablanca", PostalCode = "20000",
                    StreetAddress    = "105, Bd. d’Anfa", Email = "*****@*****.**", Website = @"http://zalar.ma/en/animal-feed-production/",
                    PhoneCountryCode = "212", PhoneLocal = "(0)5 22 33 15 42",
                    CreationDateTime = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    ProviderName     = "EDDIK", CountryAddress = "Morocco", CityAddress = "Berrechid", PostalCode = "26100",
                    MilePostAddress  = "Km 4,5", RouteAddress = "Main Road 7", StreetAddress = "118", Email = "*****@*****.**",
                    PhoneCountryCode = "212", PhoneLocal = "(0)522-336797",
                    CreationDateTime = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    ProviderName = "INAAM", CountryAddress = "Morocco", CreationDateTime = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    ProviderName     = "SOPROMAL", CountryAddress = "Morocco", CityAddress = "Témara ", PostalCode = "12050",
                    StreetAddress    = "Zone Industrielle Temara1,",
                    PhoneCountryCode = "212", PhoneLocal = "(0)527-740696",
                    CreationDateTime = DateTime.Parse("2013-09-01")
                }
            };

            foreach (Provider s in Providers)
            {
                context.Set <Provider>().Add(s);
            }
            try
            {
                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #24
0
        public void DeletePlanTest()
        {
            // Arrange
            Guid         planId;
            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 = 10000,
                Deadline     = DateTime.Today,
                IsCompleted  = false,
            };

            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;
                db.Plans.Add(plan);
                db.SaveChanges();
                planId = plan.Id;
            }

            // Act
            _balanceFacade.DeletePlan(planId);

            // Assert
            var deletedPlan = GetPlanById(planId);

            Assert.That(deletedPlan == null, "Plan was not deleted.");
        }
Example #25
0
        public void CreateItemTest()
        {
            // Arrange
            Guid         accountId;
            Guid         typeId;
            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
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                accountId = account.Id;
                typeId    = type.Id;
            }

            var item = new CostInfo()
            {
                Description = "bread",
                AccountId   = accountId,
                TypeId      = typeId,
                IsIncome    = true,
                Money       = 25,
                Created     = DateTime.Now
            };

            // Act
            var createdId = _expenseFacade.CreateItem(item);

            // Assert
            var createdItem = GetItemById(createdId);

            Assert.That(createdItem != null, "Item was not created.");
        }
Example #26
0
        public void UpdateItemTypeTest()
        {
            // Arrange
            const string accountName = "ExpenseManagerAccount01";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };
            const string typeName1 = "Food";
            const string typeName2 = "PC";
            Guid         typeId;
            var          type = new CostTypeModel
            {
                Name         = typeName1,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.Accounts.Add(account);
                db.CostTypes.Add(type);
                db.SaveChanges();
                typeId = type.Id;
            }

            // Act
            _expenseFacade.UpdateItemType(new CostType
            {
                Id           = typeId,
                Name         = typeName2,
                CostInfoList = new EditableList <CostInfo>(),
                AccountId    = account.Id
            });

            // Assert
            var updatedType = GetTypeByName(typeName2);

            Assert.That(updatedType != null, "Type was not updated.");
        }
Example #27
0
        public void ListItemTypesTest2()
        {
            // Arrange
            const string accountName = "ExpenseManagerAccount01";
            var          account     = new AccountModel
            {
                Badges = new List <AccountBadgeModel>(),
                Costs  = new List <CostInfoModel>(),
                Name   = accountName
            };

            const string typeName1 = "Food";
            const string typeName2 = "PC";
            var          type1     = new CostTypeModel
            {
                Name         = typeName1,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };
            var type2 = new CostTypeModel
            {
                Name         = typeName2,
                CostInfoList = new EditableList <CostInfoModel>(),
                Account      = account
            };

            using (
                var db =
                    new ExpenseDbContext(
                        Effort.DbConnectionFactory.CreatePersistent(TestInstaller.ExpenseManagerTestDbConnection)))
            {
                db.CostTypes.Add(type1);
                db.CostTypes.Add(type2);
                db.SaveChanges();
            }

            // Act
            var types = _expenseFacade.ListItemTypes("PC", account.Id, null);

            // Assert
            Assert.That(types.Count == 1, "Type was not listed.");
        }
Example #28
0
        public void ListPlansTest1()
        {
            // Arrange
            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 = 10000,
                Deadline     = DateTime.Today,
                IsCompleted  = false,
            };

            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;
                db.Plans.Add(plan);
                db.SaveChanges();
            }
            Assert.IsTrue(_balanceFacade.ListPlans(null, null).Count > 0);
        }
Example #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpenseManagerUnitOfWork"/> class.
        /// </summary>
        public ExpenseManagerUnitOfWork(IUnitOfWorkProvider provider, bool reuseParentContext)
        {
            if (reuseParentContext)
            {
                var parentunitOfWork = provider.GetCurrent() as ExpenseManagerUnitOfWork;
                if (parentunitOfWork != null)
                {
                    this.Context = parentunitOfWork.Context;
                    return;
                }
            }

            var unitOfWorkProvider = (ExpenseManagerUnitOfWorkProvider)provider;

            Context = unitOfWorkProvider.ConnectionOptions == null
                ? unitOfWorkProvider.DbContextFactory?.Invoke() as ExpenseDbContext
                      // internal DbContext shall not be injected in some scenarios in order to increase persistence separation
                : new ExpenseDbContext(unitOfWorkProvider.ConnectionOptions.ConnectionString);

            _hasOwnContext = true;
        }
Example #30
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.");
        }