@@ -32,6 +32,31 @@ await WithCartDiscount(
32
32
cartDiscount => { Assert . Equal ( key , ( string ) cartDiscount . Key ) ; } ) ;
33
33
}
34
34
35
+ [ Fact ]
36
+ public async Task CreateCartDiscountWithFixedValue ( )
37
+ {
38
+ var key = $ "CreateCartDiscount-{ TestingUtility . RandomString ( ) } ";
39
+ await WithCartDiscount (
40
+ client ,
41
+ cartDiscountDraft =>
42
+ {
43
+ var draft = DefaultCartDiscountDraftWithKey ( cartDiscountDraft , key ) ;
44
+ draft . Value = new FixedCartDiscountValue
45
+ {
46
+ Money = new List < Money >
47
+ {
48
+ new Money { CurrencyCode = "EUR" , CentAmount = TestingUtility . RandomInt ( 100 , 1000 ) }
49
+ }
50
+ } ;
51
+ return draft ;
52
+ } ,
53
+ cartDiscount =>
54
+ {
55
+ Assert . Equal ( key , ( string ) cartDiscount . Key ) ;
56
+ Assert . Equal ( "fixed" , cartDiscount . Value . Type ) ;
57
+ } ) ;
58
+ }
59
+
35
60
36
61
[ Fact ]
37
62
public async Task GetCartDiscountById ( )
@@ -60,16 +85,20 @@ await WithCartDiscount(
60
85
Assert . Equal ( key , retrievedCartDiscount . Key ) ;
61
86
} ) ;
62
87
}
63
-
88
+
64
89
[ Fact ]
65
90
public async Task GetMultiBuyLineItemCartDiscount ( )
66
91
{
67
92
await WithCartDiscount (
68
93
client , cartDiscountDraft =>
69
94
{
70
95
var draft = DefaultCartDiscountDraft ( cartDiscountDraft ) ;
71
- draft . Value = new RelativeCartDiscountValue { Permyriad = 10000 } ;
72
- draft . Target = new MultiBuyLineItemTarget { Predicate = "1 = 1" , TriggerQuantity = 2 , MaxOccurrence = 1 , DiscountedQuantity = 1 , SelectionMode = SelectionMode . Cheapest } ;
96
+ draft . Value = new RelativeCartDiscountValue { Permyriad = 10000 } ;
97
+ draft . Target = new MultiBuyLineItemTarget
98
+ {
99
+ Predicate = "1 = 1" , TriggerQuantity = 2 , MaxOccurrence = 1 , DiscountedQuantity = 1 ,
100
+ SelectionMode = SelectionMode . Cheapest
101
+ } ;
73
102
return draft ;
74
103
} ,
75
104
async cartDiscount =>
@@ -87,8 +116,12 @@ await WithCartDiscount(
87
116
client , cartDiscountDraft =>
88
117
{
89
118
var draft = DefaultCartDiscountDraft ( cartDiscountDraft ) ;
90
- draft . Value = new RelativeCartDiscountValue { Permyriad = 10000 } ;
91
- draft . Target = new MultiBuyCustomLineItemTarget { Predicate = "1 = 1" , TriggerQuantity = 2 , MaxOccurrence = 1 , DiscountedQuantity = 1 , SelectionMode = SelectionMode . Cheapest } ;
119
+ draft . Value = new RelativeCartDiscountValue { Permyriad = 10000 } ;
120
+ draft . Target = new MultiBuyCustomLineItemTarget
121
+ {
122
+ Predicate = "1 = 1" , TriggerQuantity = 2 , MaxOccurrence = 1 , DiscountedQuantity = 1 ,
123
+ SelectionMode = SelectionMode . Cheapest
124
+ } ;
92
125
return draft ;
93
126
} ,
94
127
async cartDiscount =>
@@ -98,7 +131,7 @@ await WithCartDiscount(
98
131
Assert . IsType < MultiBuyCustomLineItemTarget > ( retrievedCartDiscount . Target ) ;
99
132
} ) ;
100
133
}
101
-
134
+
102
135
[ Fact ]
103
136
public async Task QueryCartDiscounts ( )
104
137
{
@@ -155,7 +188,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
155
188
{
156
189
var updatedCartDiscount = await client
157
190
. ExecuteAsync ( cartDiscount . UpdateById (
158
- actions => actions . AddUpdate ( new SetKeyUpdateAction ( ) { Key = newKey } )
191
+ actions => actions . AddUpdate ( new SetKeyUpdateAction ( ) { Key = newKey } )
159
192
)
160
193
) ;
161
194
@@ -174,7 +207,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
174
207
{
175
208
var updatedCartDiscount = await client
176
209
. ExecuteAsync ( cartDiscount . UpdateByKey ( actions =>
177
- actions . AddUpdate ( new ChangeValueUpdateAction { Value = newAbsoluteValue } )
210
+ actions . AddUpdate ( new ChangeValueUpdateAction { Value = newAbsoluteValue } )
178
211
)
179
212
) ;
180
213
@@ -213,7 +246,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
213
246
[ Fact ]
214
247
public async Task UpdateCartDiscountChangeTarget ( )
215
248
{
216
- var newCartDiscountTarget = new LineItemsCartDiscountTarget ( ) { Predicate = " 1 <> 1" } ;
249
+ var newCartDiscountTarget = new LineItemsCartDiscountTarget ( ) { Predicate = " 1 <> 1" } ;
217
250
await WithUpdateableCartDiscount ( client , async cartDiscount =>
218
251
{
219
252
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
@@ -241,7 +274,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
241
274
{
242
275
var newIsActive = ! cartDiscount . IsActive ;
243
276
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
244
- var changeIsActiveAction = new ChangeIsActiveUpdateAction { IsActive = newIsActive } ;
277
+ var changeIsActiveAction = new ChangeIsActiveUpdateAction { IsActive = newIsActive } ;
245
278
updateActions . Add ( changeIsActiveAction ) ;
246
279
247
280
var updatedCartDiscount = await client
@@ -259,7 +292,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
259
292
{
260
293
var newName = new LocalizedString { { "en" , TestingUtility . RandomString ( ) } } ;
261
294
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
262
- var action = new ChangeNameUpdateAction { Name = newName } ;
295
+ var action = new ChangeNameUpdateAction { Name = newName } ;
263
296
updateActions . Add ( action ) ;
264
297
265
298
var updatedCartDiscount = await client
@@ -277,7 +310,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
277
310
{
278
311
var newDescription = new LocalizedString { { "en" , TestingUtility . RandomString ( ) } } ;
279
312
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
280
- var action = new SetDescriptionUpdateAction { Description = newDescription } ;
313
+ var action = new SetDescriptionUpdateAction { Description = newDescription } ;
281
314
updateActions . Add ( action ) ;
282
315
283
316
var updatedCartDiscount = await client
@@ -295,7 +328,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
295
328
{
296
329
var newSortOrder = TestingUtility . RandomSortOrder ( ) ;
297
330
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
298
- var action = new ChangeSortOrderUpdateAction { SortOrder = newSortOrder } ;
331
+ var action = new ChangeSortOrderUpdateAction { SortOrder = newSortOrder } ;
299
332
updateActions . Add ( action ) ;
300
333
301
334
var updatedCartDiscount = await client
@@ -313,7 +346,8 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
313
346
{
314
347
var newRequiresDiscountCode = ! cartDiscount . RequiresDiscountCode ;
315
348
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
316
- var action = new ChangeRequiresDiscountCodeUpdateAction { RequiresDiscountCode = newRequiresDiscountCode } ;
349
+ var action = new ChangeRequiresDiscountCodeUpdateAction
350
+ { RequiresDiscountCode = newRequiresDiscountCode } ;
317
351
updateActions . Add ( action ) ;
318
352
319
353
var updatedCartDiscount = await client
@@ -331,7 +365,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
331
365
{
332
366
var newValidFrom = cartDiscount . ValidFrom . AddDays ( 1 ) ;
333
367
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
334
- var action = new SetValidFromUpdateAction { ValidFrom = newValidFrom } ;
368
+ var action = new SetValidFromUpdateAction { ValidFrom = newValidFrom } ;
335
369
updateActions . Add ( action ) ;
336
370
337
371
var updatedCartDiscount = await client
@@ -348,7 +382,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
348
382
{
349
383
var newValidUntil = cartDiscount . ValidUntil . AddDays ( 1 ) ;
350
384
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
351
- var action = new SetValidUntilUpdateAction { ValidUntil = newValidUntil } ;
385
+ var action = new SetValidUntilUpdateAction { ValidUntil = newValidUntil } ;
352
386
updateActions . Add ( action ) ;
353
387
354
388
var updatedCartDiscount = await client
@@ -390,7 +424,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
390
424
{
391
425
var newStackingMode = StackingMode . StopAfterThisDiscount ;
392
426
var updateActions = new List < UpdateAction < CartDiscount > > ( ) ;
393
- var action = new ChangeStackingModeUpdateAction { StackingMode = newStackingMode } ;
427
+ var action = new ChangeStackingModeUpdateAction { StackingMode = newStackingMode } ;
394
428
updateActions . Add ( action ) ;
395
429
396
430
var updatedCartDiscount = await client
@@ -419,7 +453,8 @@ await WithUpdateableCartDiscount(client,
419
453
} ;
420
454
updateActions . Add ( setTypeAction ) ;
421
455
422
- var updatedCartDiscount = await client . ExecuteAsync ( new UpdateByIdCommand < CartDiscount > ( cartDiscount , updateActions ) ) ;
456
+ var updatedCartDiscount =
457
+ await client . ExecuteAsync ( new UpdateByIdCommand < CartDiscount > ( cartDiscount , updateActions ) ) ;
423
458
424
459
Assert . Equal ( type . Id , updatedCartDiscount . Custom . Type . Id ) ;
425
460
return updatedCartDiscount ;
@@ -446,7 +481,8 @@ await WithUpdateableCartDiscount(client,
446
481
} ;
447
482
updateActions . Add ( setCustomFieldUpdateAction ) ;
448
483
449
- var updatedCartDiscount = await client . ExecuteAsync ( new UpdateByIdCommand < CartDiscount > ( cartDiscount , updateActions ) ) ;
484
+ var updatedCartDiscount =
485
+ await client . ExecuteAsync ( new UpdateByIdCommand < CartDiscount > ( cartDiscount , updateActions ) ) ;
450
486
451
487
Assert . Equal ( newValue , updatedCartDiscount . Custom . Fields [ "string-field" ] ) ;
452
488
return updatedCartDiscount ;
@@ -456,4 +492,4 @@ await WithUpdateableCartDiscount(client,
456
492
457
493
#endregion
458
494
}
459
- }
495
+ }
0 commit comments