public async void GetAllCashAccountsWithDetailsReturnsEnumerableOfCashAccounts() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); ICashAccountDataService service = new CashAccountDataService(db); db.CashAccounts.Add(Cashact); var save = db.SaveChanges(); var some = new QueryCondition <CashAccount>(); some.QueryIncludes.Add(c => c.Incomes); some.QueryIncludes.Add(c => c.Expenses); some.QueryOrderBy.Add(c => c.CreatedDate); var result = await service.GetAllCashAccountsWithDetails(some); CashAccountModel account; using (var single = result.GetEnumerator()) { single.MoveNext(); account = single.Current; } var another = some; Assert.NotNull(result); Assert.Single(result); Assert.IsType <CashAccountModel>(account); } }
public async void GetAllExpensesWithDetailsReturnsEnumerableWithExpenses() { //Given using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IExpenseDataService service = new ExpenseDataService(db); db.Expenses.AddRange(Expense); var save = db.SaveChanges(); var some = new QueryCondition <Expense>(); some.QueryIncludes.Add(i => i.CashAccount); some.QueryOrderBy.Add(i => i.ExpenseDate); var result = await service.GetExpensesWithAllDetails(some, 2); ExpenseModel expense; using (var single = result.GetEnumerator()) { single.MoveNext(); expense = single.Current; } var another = some; Assert.NotNull(result); Assert.Equal(3, result.ToArray().Length); Assert.IsType <ExpenseModel>(expense); } }
public async void GetAllIncomesWithDetailsReturnsEnumerableWithIncomes() { //Given using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IIncomeDataService service = new IncomeDataService(db); db.Incomes.AddRange(Income); var save = db.SaveChanges(); var some = new QueryCondition <Income>(); some.QueryIncludes.Add(i => i.CashAccount); some.QueryOrderBy.Add(i => i.IncomeDate); var result = await service.GetAllIncomesWithDetails(some, 2); IncomeModel income; using (var single = result.GetEnumerator()) { single.MoveNext(); income = single.Current; } var another = some; Assert.NotNull(result); Assert.Equal(3, result.Count()); Assert.IsType <IncomeModel>(income); } }
public void GetAllReturnEnumerableOfEntity() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <Income> repo = new BaseDataService <Income>(db); db.Incomes.AddRange(Income); db.SaveChanges(); var result = repo.GetAll(new QueryCondition <Income>()); Assert.NotEmpty(result); Assert.Contains(result, i => i.GetType().Equals(typeof(Income))); } }
public void AddEntityCreatesEntityInDb() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); var collection = db.ChangeTracker.Entries(); Assert.Contains(collection, x => x.Entity.GetType() == typeof(CashAccount)); db.SaveChanges(); } }
public void GetByReturnEntityBasedOnPredicate() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); db.SaveChanges(); var condition = new QueryCondition <CashAccount>(); condition.QueryPredicates.Add(c => c.IsActivated); var result = repo.GetBy(condition); Assert.NotNull(result); Assert.IsType <CashAccount>(result); } }
public async void GetWithParameterFiltersAndReturnsExactlyOneCashAccount() { Cashact = new Faker <CashAccount>() .RuleFor(c => c.Incomes, Income) .RuleFor(c => c.Expenses, Expense) .RuleFor(c => c.AccountBalance, x => x.Random.Decimal(3m, 2430m)) .RuleFor(c => c.AccountName, "Abel Rosnovski") .RuleFor(c => c.IsActivated, true) .RuleFor(i => i.CashAccountId, x => x.Random.Guid()) .RuleFor(c => c.CreatedDate, DateTimeOffset.UtcNow) .Generate(); var Cashact1 = new Faker <CashAccount>() .RuleFor(c => c.Incomes, Income) .RuleFor(c => c.Expenses, Expense) .RuleFor(c => c.AccountBalance, x => x.Random.Decimal(3m, 2430m)) .RuleFor(c => c.AccountName, "Yakubu Shloniq") .RuleFor(c => c.IsActivated, true) .RuleFor(i => i.CashAccountId, x => x.Random.Guid()) .RuleFor(c => c.CreatedDate, DateTimeOffset.UtcNow) .Generate(); using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); db.CashAccounts.Add(Cashact); db.CashAccounts.Add(Cashact1); db.SaveChanges(); ICashAccountDataService repo = new CashAccountDataService(db); var controller = new CashAccountsController(repo, Conditions, db); var result = await controller.Get("Abel Rosnovski"); Assert.NotNull(result); var viewResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, viewResult.StatusCode); var acct = viewResult.Value as CashAccountDetailModel; Assert.Equal("Abel Rosnovski", acct.AccountName); } }
public void UpdateEntityChangesEntityStateToModified() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); db.SaveChanges(); var acct = db.CashAccounts.First(); acct.AccountBalance = 10m; repo.Update(acct); var collection = db.ChangeTracker.Entries(); Assert.Contains(collection, x => x.Entity.GetType() == typeof(CashAccount)); var one = collection.Where(c => c.State == EntityState.Modified).SingleOrDefault(); Assert.NotNull(one); //Assert.Equal(acct.AccountBalance, 10m); } }
public async void GetReturnsActionResultWithCashAccountEnumerable() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); db.CashAccounts.Add(Cashact); db.SaveChanges(); ICashAccountDataService repo = new CashAccountDataService(db); var controller = new CashAccountsController(repo, Conditions, db); //Act var result = await controller.Get(); //Assert var viewResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, viewResult.StatusCode); Assert.IsAssignableFrom <IEnumerable <CashAccountModel> >((IEnumerable <CashAccountModel>)viewResult.Value); } }
public async void GetByAsyncReturnsSingleCashAccountWithDetails() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); ICashAccountDataService service = new CashAccountDataService(db); Cashact.AccountName = "Someone Somewhere"; db.CashAccounts.Add(Cashact); var save = db.SaveChanges(); var some = new QueryCondition <CashAccount>(); some.QueryIncludes.Add(c => c.Incomes); some.QueryIncludes.Add(c => c.Expenses); some.QueryOrderBy.Add(c => c.CreatedDate); some.QueryPredicates.Add(c => c.AccountName.Contains("Someone")); var result = await service.GetByAsync(some); Assert.NotNull(result); Assert.IsType <CashAccountDetailModel>(result); } }