5using Microsoft.EntityFrameworkCore;
7using Xunit.Abstractions;
30 return new Currency() {CurrencyName =
"USD"};
42 await
context.SaveChangesAsync();
47 var allCurrencies = await
context.Currencies.ToListAsync();
49 await Assert.ThrowsAsync<InvalidOperationException>(op);
50 Assert.Single(allCurrencies);
63 var res = await
service.AddCurrency(
new Currency() {CurrencyName =
"usd"});
65 Assert.Equal(
"USD", res.CurrencyName);
79 await
context.SaveChangesAsync();
83 PriceListName =
"2022 USD",
84 DateFrom = DateTime.Now,
85 DateTo = DateTime.Now,
90 await
context.SaveChangesAsync();
93 var op = async () => await
service.DeleteCurrency(1);
95 await Assert.ThrowsAsync<InvalidOperationException>(op);
106 var currencyDb =
context.Currencies.Add(currency);
107 await
context.SaveChangesAsync();
110 var res = await
service.GetCurrencyByName(currency.CurrencyName);
112 Assert.Equal(currencyDb.Entity.CurrencySeq, res.CurrencySeq);
124 var res = await
service.GetCurrencyByName(
"USD");
CurrencyService class inserts and updates Currency in the Database
CurrencyService Testing Environment
CurrencyServiceTest(ITestOutputHelper testOutputHelper)
async void DeleteCurrency_ShouldNotBeDeletedWhenUsedAsFK()
passes if trying to delete currency while it is referenced in pricelist, and throws InvalidOperationE...
async void AddCurrency_NameConvertedToUpperChars()
passes if after adding currencyname is converted to upperchars
readonly ITestOutputHelper _testOutputHelper
async void GetCurrencyByName_Success()
passes if correctly retrieved currency by currencyname
async void AddCurrency_DuplicateName()
passes if currencyname already exist, and it throws InvalidOperationException, and list only has one ...
async void GetCurrencyByName_Fail()
passes if there does not exist a currency with the retrieved currency by currencyname
Currency CreateCurrency()
Creates a currency
static DataContext GetContext()
Creates a testcontext for testing
Reusable methods for inserting information into tests
static DataContext InsertProduct(DataContext context)
Inserts Product into the context Used for inserting product into the test environment