1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4+ using Newtonsoft . Json ;
5+ using Newtonsoft . Json . Linq ;
6+
7+ namespace FlurlGraphQL . Querying . Tests
8+ {
9+ [ TestClass ]
10+ public class FlurlGraphQLMutationTests : BaseFlurlGraphQLTest
11+ {
12+
13+ [ TestMethod ]
14+ public async Task TestMutationWithQueryResultsAsync ( )
15+ {
16+ var inputPayload = JArray . Parse ( @"
17+ [{
18+ ""eventId"": 23,
19+ ""eventUUID"": ""c5cd1cca-fe4d-490d-a948-985023c6185c"",
20+ ""name"": ""RÜFÜS DU SOL"",
21+ ""eventType"": ""ONE_OFF"",
22+ ""status"": ""APPROVED"",
23+ ""eventDate"": ""2018-11-01T07:00:00"",
24+ ""announceDate"": null,
25+ ""onSaleDate"": null,
26+ ""doorTime"": null,
27+ ""newElvisVenueId"": 10811,
28+ ""internalBudget"": 15000.00000000,
29+ ""externalBudget"": 15000.00000000,
30+ ""budgetCurrencyCode"": ""USD"",
31+ ""budgetExchangeRate"": 1.000000,
32+ ""bookerDescription"": null,
33+ ""companyMasterId"": 1,
34+ ""subledger"": ""H6367996"",
35+ ""genreDescription"": ""Dance / Electronic / DJ / Techno / House / Trance"",
36+ ""notes"": null,
37+ ""headlinerArtists"": [{
38+ ""artistMasterId"": 0,
39+ ""artistOrdinalSortId"": 1
40+ }
41+ ],
42+ ""supportingArtists"": [{
43+ ""artistMasterId"": 0,
44+ ""artistOrdinalSortId"": 1
45+ }
46+ ],
47+ ""eventContacts"": null,
48+ ""shows"": [{
49+ ""showId"": 101,
50+ ""showName"": ""Show #3"",
51+ ""showOrdinalSortId"": 3,
52+ ""showDate"": ""2018-11-03T07:00:00"",
53+ ""announceDate"": null,
54+ ""onSaleDate"": null,
55+ ""doorTime"": null
56+ }, {
57+ ""showId"": 102,
58+ ""showName"": ""Show #2"",
59+ ""showOrdinalSortId"": 2,
60+ ""showDate"": ""2018-11-02T07:00:00"",
61+ ""announceDate"": null,
62+ ""onSaleDate"": null,
63+ ""doorTime"": null
64+ }, {
65+ ""showId"": 103,
66+ ""showName"": ""Show #1"",
67+ ""showOrdinalSortId"": 1,
68+ ""showDate"": ""2018-11-01T07:00:00"",
69+ ""announceDate"": null,
70+ ""onSaleDate"": null,
71+ ""doorTime"": null
72+ }
73+ ],
74+ ""createdDate"": ""2018-11-02T21:13:34"",
75+ ""lastUpdatedDate"": ""2020-06-11T10:00:12""
76+ }]
77+ " ) ;
78+
79+ var mutationResult = await "http://localhost:7072/api/v1/graphql?code=Tsk4dixKihdUyRlvlcDu1dHETHYIiCPpLawk%2F27apOsRTr1LbhF7vw%3D%3D"
80+ . WithGraphQLQuery ( @"
81+ mutation ($eventInputArray: [EventCreateOrUpdateInput]) {
82+ eventsCreateOrUpdate(input: $eventInputArray) {
83+ eventResults {
84+ eventUUID
85+ eventId
86+ }
87+ errors {
88+ ... on Error {
89+ errorCode
90+ message
91+ }
92+ }
93+ }
94+ }
95+ " )
96+ . SetGraphQLVariables ( new { eventInputArray = inputPayload } )
97+ . PostGraphQLQueryAsync ( )
98+ . ReceiveGraphQLMutationResult < EventsCreateOrUpdateResult > ( )
99+ . ConfigureAwait ( false ) ;
100+
101+
102+ Assert . IsNotNull ( mutationResult ) ;
103+ Assert . IsTrue ( mutationResult . EventResults . Length > 0 ) ;
104+
105+ var jsonText = JsonConvert . SerializeObject ( mutationResult , Formatting . Indented ) ;
106+ TestContext . WriteLine ( jsonText ) ;
107+ }
108+ }
109+
110+ public class EventsCreateOrUpdateResult
111+ {
112+ public EventResult [ ] EventResults { get ; set ; }
113+ }
114+
115+ public class EventResult
116+ {
117+ public Guid ? EventUUID { get ; set ; }
118+ public int ? EventId { get ; set ; }
119+ }
120+ }
0 commit comments