5using Microsoft.EntityFrameworkCore;
43 var res = await
service.AddPriceElement(priceElement);
45 Assert.Equal(priceElement.Price, res.Price);
46 Assert.NotNull(priceElement.ModuleLevel);
47 Assert.NotNull(priceElement.PriceList);
59 priceElement.Price =
null;
62 var op = async () => await
service.AddPriceElement(priceElement);
64 await Assert.ThrowsAsync<DbUpdateException>(op);
79 await
service.AddPriceElement(priceElement);
81 var priceList = await
context.PriceLists.FindAsync(1);
82 var op = () =>
context.PriceLists.Remove(priceList);
84 Assert.Throws<InvalidOperationException>(op);
100 var op = async () => await
service.AddPriceElement(priceElement);
102 await Assert.ThrowsAsync<DbUpdateException>(op);
115 var priceElementDb =
context.PriceElements.Add(priceElement);
116 await
context.SaveChangesAsync();
118 priceElementDb.Entity.Price =
null;
121 var op = async () => await
service.UpdatePriceElement(priceElementDb.Entity);
123 await Assert.ThrowsAsync<DbUpdateException>(op);
PriceElementService class inserts and updates PriceElement in the Database
PriceElementService Testing Environment
async void PriceElement_DeletingFKs()
passes if trying to remove pricelist when it is referencing priceelement and throws InvalidOperationE...
async void UpdatePriceElement_PriceIsNull()
passes when trying to set priceelement-price to null, and update the priceelement,...
async void AddPriceElement_PriceIsNull()
passes if priceelement-price is null, and throws DbUpdateException
async void AddPriceElement_ModuleLevelFKNotExisting()
passes if trying to add priceelement without reference to modulelevel, and throws DbUpdateException
PriceElement CreatePriceElement()
Creates a new PriceElement
async void AddPriceElement_Success()
passses if priceelement-price equals returned priceelement-price, and priceelement reference to modul...
static DataContext GetContext()
Creates a testcontext for testing
Reusable methods for inserting information into tests
static DataContext InsertDataForPriceElement(DataContext context)
static DataContext InsertProduct(DataContext context)
Inserts Product into the context Used for inserting product into the test environment
static DataContext InsertPriceList(DataContext context)
Inserts a PriceList into DataContext Product must be inserted before this method is called