5using Microsoft.EntityFrameworkCore;
7using Xunit.Abstractions;
32 PriceListName =
"2022",
33 DateFrom = DateTime.Parse(
"2018-01-01"),
34 DateTo = DateTime.Parse(
"2018-12-31"),
53 PriceListName =
"2022",
54 DateFrom = DateTime.Parse(
"2018-01-01"),
55 DateTo = DateTime.Parse(
"2018-12-31"),
61 Assert.NotNull(res.Currency);
62 Assert.NotNull(res.Product);
63 Assert.Equal(
"2022", res.PriceListName);
80 PriceListName =
string.Empty,
81 DateFrom = DateTime.Parse(
"2018-01-01"),
82 DateTo = DateTime.Parse(
"2018-12-31"),
90 Assert.Equal(
"", res.PriceListName);
107 PriceListName =
"2022",
108 DateFrom = DateTime.Parse(
"2018-12-31"),
109 DateTo = DateTime.Parse(
"2018-01-01"),
114 await Assert.ThrowsAsync<InvalidOperationException>(op);
130 PriceListName =
"2022",
136 var op = async () => await
service.AddPriceList(priceList);
138 await Assert.ThrowsAsync<DbUpdateException>(op);
155 PriceListName =
"2022",
156 DateFrom = DateTime.Parse(
"2018-01-01"),
157 DateTo = DateTime.Parse(
"2018-01-01"),
162 await Assert.ThrowsAsync<InvalidOperationException>(op);
179 PriceListName =
"2022",
180 DateFrom = DateTime.Parse(
"2018-01-01"),
181 DateTo = DateTime.Parse(
"2018-12-31"),
185 await Assert.ThrowsAsync<DbUpdateException>(op);
201 var priceListDb =
context.PriceLists.Add(priceList);
202 await
context.SaveChangesAsync();
206 priceListDb.Entity.DateFrom = DateTime.Parse(
"2017-01-01");
207 var updatedPriceList = await
service.UpdatePriceList(priceListDb.Entity);
209 Assert.Equal(priceList.PriceListName, updatedPriceList.PriceListName);
225 var priceListDb =
context.PriceLists.Add(priceList);
226 await
context.SaveChangesAsync();
230 priceListDb.Entity.DateFrom = DateTime.Parse(
"2019-01-01");
231 var op = async () => await
service.UpdatePriceList(priceListDb.Entity);
233 await Assert.ThrowsAsync<InvalidOperationException>(op);
PriceListService class inserts and updates PriceList in the Database
PriceListService Testing Environtment
async void UpdatePriceList_Success()
passes if pricelist is correctly inserted into the pricelist-list
async void AddPriceList_Success()
passes if pricelist is correctly added to productlist-list
async void AddPriceList_DatesAreEqual()
Passes if pricelist datefrom and dateto is same date, and InvalidOperationException is thrown
async void AddPriceList_DatesAreNull()
passes if dates is not set on pricelist, and DbUpdateException is thrown
async void AddPriceList_DateFromNotBeforeDateTo()
passes if dateto is before datefrom, and InvalidOperationException is thrown
async void AddPriceList_NameIsEmptyString()
passes if inserted pricelist has empty string name
readonly ITestOutputHelper _testOutputHelper
async void UpdatePriceList_DateFromNotBeforeDateTo()
passes if dateFrom not before dateto, throws InvalidOperationException
async void AddPriceList_MissingCurrencyFK()
passes ip pricelist is missing a currency reference, and throws a DbUpdateException
PriceListServiceTest(ITestOutputHelper testOutputHelper)
PriceList CreatePriceList()
Creates a new pricelist
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
static DataContext InsertCurrency(DataContext context)
Inserts Currency into DataContext