Escali License control 1
PriceElementServiceTest.cs
Gå til dokumentasjonen til denne filen.
1using System;
5using Microsoft.EntityFrameworkCore;
6using Xunit;
7
9{
10
15{
16
22 {
23 return new PriceElement()
24 {
25 Price = 950,
26 ModuleLevelSeq = 1,
27 PriceListSeq = 1
28 };
29 }
30
35 [Fact]
36 public async void AddPriceElement_Success()
37 {
40 var priceElement = CreatePriceElement();
41
43 var res = await service.AddPriceElement(priceElement);
44
45 Assert.Equal(priceElement.Price, res.Price);
46 Assert.NotNull(priceElement.ModuleLevel);
47 Assert.NotNull(priceElement.PriceList);
48 }
49
53 [Fact]
54 public async void AddPriceElement_PriceIsNull()
55 {
58 var priceElement = CreatePriceElement();
59 priceElement.Price = null;
60
62 var op = async () => await service.AddPriceElement(priceElement);
63
64 await Assert.ThrowsAsync<DbUpdateException>(op);
65 }
66
71 [Fact]
72 public async void PriceElement_DeletingFKs()
73 {
76 var priceElement = CreatePriceElement();
77
79 await service.AddPriceElement(priceElement);
80
81 var priceList = await context.PriceLists.FindAsync(1);
82 var op = () => context.PriceLists.Remove(priceList);
83
84 Assert.Throws<InvalidOperationException>(op);
85 }
86
91 [Fact]
93 {
97 var priceElement = CreatePriceElement();
98
100 var op = async () => await service.AddPriceElement(priceElement);
101
102 await Assert.ThrowsAsync<DbUpdateException>(op);
103 }
104
109 [Fact]
111 {
114 var priceElement = CreatePriceElement();
115 var priceElementDb = context.PriceElements.Add(priceElement);
116 await context.SaveChangesAsync();
117
118 priceElementDb.Entity.Price = null;
119
121 var op = async () => await service.UpdatePriceElement(priceElementDb.Entity);
122
123 await Assert.ThrowsAsync<DbUpdateException>(op);
124 }
125
126 }
127}
var context
Definition: Program.cs:49
var service
Definition: Program.cs:48
PriceElementService class inserts and updates PriceElement in the Database
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
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
Definition: TestBase.cs:14
Reusable methods for inserting information into tests
Definition: TestData.cs:11
static DataContext InsertDataForPriceElement(DataContext context)
Definition: TestData.cs:120
static DataContext InsertProduct(DataContext context)
Inserts Product into the context Used for inserting product into the test environment
Definition: TestData.cs:28
static DataContext InsertPriceList(DataContext context)
Inserts a PriceList into DataContext Product must be inserted before this method is called
Definition: TestData.cs:100