public async Task Can_delete_currency_without_product_referencing_it() { // Arrange const string currencyId = "testCurrencyId"; var currency = CreateCurrency(currencyId); using (var db = _contextFactory.CreateDataContext()) { await db.Currencies.AddAsync(currency); await db.SaveChangesAsync(); } var repository = new CurrenciesRepository(_contextFactory); var service = new CurrenciesService(repository, _auditService, _cqrsMessageSender, _convertService); // Act const string userName = "******"; string correlationId = Guid.NewGuid().ToString("N"); var result = await service.DeleteAsync(currencyId, userName, correlationId); // Assert Assert.True(result.IsSuccess); using (var db = _contextFactory.CreateDataContext()) { Assert.True(await db.Currencies.AllAsync(x => x.Id != currencyId)); } }
public override void TestInitialize() { base.TestInitialize(); repository = new CurrenciesRepository(db); controller = "currencies"; detailsViewCaption = "Currency"; }
public async Task GetExchangeRatesTest() { //Arrange var repository = new CurrenciesRepository(); //Act var exchangeRates = await repository.GetExchangeRates(DateTime.Now); //Assert Assert.IsNotNull(exchangeRates); }
public void GetCurrencyRateInEuroReturnsNull_IfCacheIsEmptyTest() { //Arrange var repository = new CurrenciesRepository(); //Act var exchangeRate = repository.GetCurrencyRateInEuro("USD", DateTime.Now); //Assert Assert.IsNull(exchangeRate); }
public void GetExchangeRates_ReturnsNull_IfDateIsBelow2000_Test() { //Arrange var repository = new CurrenciesRepository(); var service = new CurrenciesService(repository); //Act var exchangeRates = service.GetExchangeRates(new DateTime(1998, 01 ,01)); Assert.IsNull(exchangeRates); }
public void GetExchangeRateTest(string from, string to, double amount) { //Arrange var repository = new CurrenciesRepository(); var service = new CurrenciesService(repository); //Act var rate = service.GetExchangeRate(from, to, DateTime.Now, amount); //Assert Assert.AreEqual(amount, rate); }
public void BindDDLs(ContractView contractView, ObjectContext db) { //contract validities ddl IContractValiditiesRepository contractValiditiesRepository = new ContractValiditiesRepository(db); contractView.ContractValidities = new SelectList(contractValiditiesRepository.GetValid().OrderBy("Name ASC").ToList(), "ContractValidityPK", "Name"); //currencies ddl ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); contractView.Currencies = new SelectList(currenciesRepository.GetValid().OrderBy(c => c.Name).Select(c => new { value = c.CurrencyPK, text = c.Name + " (" + c.Sign + ")" }), "value", "text"); }
public async Task GetCurrencyRateInEuroReturnsNull_IfCacheIsNotEmptyTest() { //Arrange var repository = new CurrenciesRepository(); //Act var exchangeRates = await repository.GetExchangeRates(DateTime.Now); var exchangeRate = repository.GetCurrencyRateInEuro("USD", DateTime.Now); //Assert Assert.IsNotNull(exchangeRate); }
public ActionResult GetAccounts() { CurrenciesRepository curRepository = new CurrenciesRepository(); var user = CurrentUser; var accounts = AccountsRepository.GetAccounts(user.CurrentCompany); var currencies = curRepository.GetCurrencies(); var accountTypes = AccountTypesRepository.GetAccountTypes(); var finInst = FinanceInstitutionRepository.Get(); var finLinks = FinanceInstitutionRepository.GetLinksToAccount(); foreach (var account in accounts) { account.Currency = currencies.Find(c => c.Id == account.CurrencyId).NameShort; account.FinInstitutionName = finInst.Find(c => c.Id == account.FinInstitutionId).Name; } return Json(new { items = accounts, currItems = currencies, typesItems = accountTypes, finInst, finLinks, accountTemplate = new Account() }); }
public ActionResult Delete(int?currencyPK) { ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); if (currencyPK != null) { Currency currency = currenciesRepository.GetCurrencyByPK((int)currencyPK); currency.Deleted = true; currenciesRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("DELETE", currency.CurrencyPK); } return(Redirect(Request.UrlReferrer.AbsoluteUri)); }
public ActionResult Edit(int?currencyPK) { if (currencyPK != null) { ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); Currency currency = currenciesRepository.GetCurrencyByPK((int)currencyPK); CurrencyView currencyView = new CurrencyView(); currencyView.ConvertFrom(currency, currencyView); return(View(currencyView)); } else { return(RedirectToAction("Index", "Currency")); } }
public ActionResult Index() { ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "CurrencyPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <Currency> currencies = currenciesRepository.GetValid() .OrderBy(ordering); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); currencies = currencies.Where(c => c.Name.Contains(searchString)); } currencies = currencies.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = currenciesRepository.GetValid().Where(c => c.Name.Contains(searchString)).Count(); } else { ViewData["numberOfRecords"] = currenciesRepository.GetValid().Count(); } int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("Currency?" + url + "page=" + numberOfPages)); } else { return(View("Index", currencies.ToList())); } }
public MenuService(AppDbContext dbContext, People logedInPerson) : base(dbContext, logedInPerson) { this.MenusRepo = new MenusRepository(dbContext); this.LanguageRepo = new LanguagesRepository(dbContext); this.MenuLanguagesRepo = new MenuLanguagesRepository(dbContext); this.CurrencyRepo = new CurrenciesRepository(dbContext); this.MenuCurrencyRepo = new MenuCurrenciesRepository(dbContext); this.CategoriesRepo = new CategoriesRepository(dbContext); this.MenuCategoriesRepo = new MenuCategoriesRepository(dbContext); this.MenuItemRepo = new MenuItemsRepository(dbContext); this.MenuItemContentRepo = new MenuItemContentRepository(dbContext); this.MenuItemValueRepo = new MenuItemValueRepository(dbContext); }
public ActionResult Edit(CurrencyView currencyModel) { if (ModelState.IsValid) { ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); Currency currency = currenciesRepository.GetCurrencyByPK((int)currencyModel.CurrencyPK); currencyModel.ConvertTo(currencyModel, currency); currenciesRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("UPDATE", currency.CurrencyPK); return(RedirectToAction("Index", "Currency")); } else { return(View(currencyModel)); } }
public ActionResult Add(CurrencyView currencyView) { if (ModelState.IsValid) { ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); Currency currency = new Currency(); currencyView.ConvertTo(currencyView, currency); currenciesRepository.Add(currency); currenciesRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("INSERT", currency.CurrencyPK); return(RedirectToAction("Index", "Currency")); } else { return(View(currencyView)); } }
public void ItReturnsNotNullModel() { // Arrange AviTradeContext dbContext = new AviTradeContext(); IItemsRepository itemsRepository = new ItemsRepository(dbContext); IAirportsRepository airportsRepository = new AirportsRepository(dbContext); IAircraftsRepository aircraftsRepository = new AircraftsRepository(dbContext); IContractsRepository contractsRepository = new ContractsRepository(dbContext); ITradersRepository tradersRepository = new TradersRepository(dbContext); IPeriodsRepository periodsRepository = new PeriodsRepository(dbContext); IInvoicesRepository invoicesRepository = new InvoicesRepository(dbContext, periodsRepository); ICurrenciesRepository currenciesRepository = new CurrenciesRepository(dbContext); IOrdersRepository ordersRepository = new OrdersRepository(dbContext, contractsRepository, airportsRepository, aircraftsRepository, itemsRepository, currenciesRepository, invoicesRepository); DataServiceController controller = null; // new DataServiceController(contractsRepository, tradersRepository, ordersRepository, itemsRepository, airportsRepository, aircraftsRepository); // Act AjaxOrdersViewModel model = controller.BuildAjaxOrdersViewModel(1, 0, "1,2,3,4", DateTime.Now.AddDays(30), true, 0, 20); // Assert Assert.IsNotNull(model); }
public async Task Cannot_delete_currency_with_product_referencing_it() { // Arrange const string currencyId = "testCurrencyId"; const string productId = "testProductId"; var currency = CreateCurrency(currencyId); var product = new ProductEntity { ProductId = productId, TradingCurrencyId = currencyId }; using (var db = _contextFactory.CreateDataContext()) { await db.Currencies.AddAsync(currency); await db.Products.AddAsync(product); await db.SaveChangesAsync(); } var repository = new CurrenciesRepository(_contextFactory); var service = new CurrenciesService(repository, _auditService, _cqrsMessageSender, _convertService); // Act const string userName = "******"; string correlationId = Guid.NewGuid().ToString("N"); var result = await service.DeleteAsync(currencyId, userName, correlationId); // Assert Assert.True(result.IsFailed); Assert.Equal(Core.Domain.CurrenciesErrorCodes.CannotDeleteCurrencyWithAttachedProducts, result.Error); using (var db = _contextFactory.CreateDataContext()) { Assert.True(await db.Currencies.AnyAsync(x => x.Id == currencyId)); Assert.True(await db.Products.AnyAsync(x => x.ProductId == productId)); } }
private static void SetupRepositories(AviTradeContext ctx) { _contractsRepository = new ContractsRepository(ctx); _airportsRepository = new AirportsRepository(ctx); _aircraftsRepository = new AircraftsRepository(ctx); _itemsRepository = new ItemsRepository(ctx); _currenciesRepository = new CurrenciesRepository(ctx); _periodsRepository = new PeriodsRepository(ctx); _invoicesRepository = new InvoicesRepository(ctx, _periodsRepository); _ordersRepository = new OrdersRepository(ctx, _contractsRepository, _airportsRepository, _aircraftsRepository, _itemsRepository, _currenciesRepository, _invoicesRepository); _tradersRepository = new TradersRepository(ctx); }
public CurrenciesController(CurrenciesRepository repo) { _repo = repo; }
public IEnumerable <Currency> GetCurrencies() { using var db = new CurrenciesRepository(); return(db.GetAll()); }
public DatabaseService(FamilyMembersRepository familyMembersRepository, CategoriesRepository categoriesRepository, CurrenciesRepository currenciesRepository) { _familyMembersRepository = familyMembersRepository; _categoriesRepository = categoriesRepository; _currenciesRepository = currenciesRepository; }
public DbUnit(AppContext context) { Context = context ?? new AppContext(); CurrencyRates = new CurrencyRatesRepository(Context); Currencies = new CurrenciesRepository(Context); }