Escali License control 1
AgreementElementServiceTest.cs
Gå til dokumentasjonen til denne filen.
1using System;
5using Xunit;
6
8{
9
14{
20 {
21 return new AgreementElement()
22 {
23 Price = 950.0M,
24 Discount = 50.0M,
25 DateFrom = DateTime.Parse("2020-01-01"),
26 DateTo = DateTime.Parse("2020-12-31"),
27 AgreementSeq = 1,
28 ModuleLevelSeq = 1,
29 AgreementElementUpdated = DateTime.Now,
30 AgreementElementCreated = DateTime.Now
31 };
32 }
33
37 [Fact]
39 {
42 var res = await service.GetAllAgreementElements();
43 Assert.Empty(res);
44 }
45
49 [Fact]
51 {
54
55 var ae = CreateAgreementElement();
56 context.Add(ae);
57 await context.SaveChangesAsync();
58
60 var res = await service.GetAllAgreementElements();
61 Assert.NotEmpty(res);
62 }
63
67 [Fact]
69 {
72
73 var ae = CreateAgreementElement();
74 context.Add(ae);
75 await context.SaveChangesAsync();
76
78 var res = await service.GetAgreementElementById(1);
79
80 Assert.Equal(ae.DateFrom, res.DateFrom);
81 Assert.NotNull(res.Agreement);
82 Assert.NotNull(res.ModuleLevel);
83 }
84
88 [Fact]
89 public async void AddAgreementElement_Success()
90 {
94
95 var ae = CreateAgreementElement();
96 var res = await service.AddAgreementElement(ae);
97
98 Assert.Equal(ae.Discount, res.Discount);
99
100 }
101
105 [Fact]
107 {
111
112 var ae = CreateAgreementElement();
113
114 var res = await service.AddAgreementElement(ae);
115
116 Assert.Equal(ae.Discount, res.Discount);
117
118 }
119
123 [Fact]
125 {
128
130 var ae = CreateAgreementElement();
131 ae.DateFrom = DateTime.Parse("2021-01-01");
132 var op = async () => await service.AddAgreementElement(ae);
133
134 await Assert.ThrowsAsync<InvalidOperationException>(op);
135
136 }
137
138 }
139}
var context
Definition: Program.cs:49
var service
Definition: Program.cs:48
AgreementElementService class inserts and updates AgreementElement in the Database
async void GetAgreementElementsById_Success()
passes if agreementelement is added to list and found by id in the agreementelementlist
async void AddAgreementElement_FieldMissing()
passes if added agreementelement with missing fields
async void AddAgreementElement_DateFromNotBeforeDateTo()
passes if datefrom is after dateto, and throws InvalidOperationException
async void GetAllAgreementElements_Empty()
passes if agreementelement-list is empty
async void GetAllAgreementElements_NotEmpty()
passses if agreementelement-list is not empty after insertion
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 InsertDataForAgreementElement(DataContext context)
Uses InsertDataForAgreement Then add agreement with references to a currency, a product and a custome...
Definition: TestData.cs:220