@@ -51,6 +51,109 @@ await Assert.ThrowsAsync<NotFoundException>(async () =>
51
51
} ) ;
52
52
} ) ;
53
53
}
54
+
55
+ [ Fact ]
56
+ public async Task HeadNotFoundReturnsDefault ( )
57
+ {
58
+ var configuration = new ConfigurationBuilder ( ) .
59
+ AddJsonFile ( "appsettings.test.Development.json" , true ) .
60
+ AddEnvironmentVariables ( ) .
61
+ AddUserSecrets < ServiceProviderFixture > ( ) .
62
+ AddEnvironmentVariables ( "CTP_" ) .
63
+ Build ( ) ;
64
+
65
+ var s = new ServiceCollection ( ) ;
66
+ s . UseCommercetoolsApi ( configuration , "Client" , options : new ClientOptions ( ) { HeadNotFoundReturnsDefault = true } ) ;
67
+ var p = s . BuildServiceProvider ( ) ;
68
+
69
+ var apiRoot = p . GetService < ProjectApiRoot > ( ) ;
70
+ await WithProduct ( apiRoot , async product =>
71
+ {
72
+ var execProduct = await apiRoot . Products ( ) . WithKey ( product . Key ) . Get ( ) . ExecuteAsync ( ) ;
73
+ Assert . NotNull ( execProduct ) ;
74
+ Assert . Equal ( product . Key , execProduct . Key ) ;
75
+ await Assert . ThrowsAsync < NotFoundException > ( async ( ) =>
76
+ {
77
+ await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Get ( ) . ExecuteAsync ( ) ;
78
+ } ) ;
79
+
80
+ var sendProduct = await apiRoot . Products ( ) . WithKey ( product . Key ) . Get ( ) . SendAsync ( ) ;
81
+ Assert . True ( sendProduct . IsSuccess ( ) ) ;
82
+ Assert . Equal ( HttpStatusCode . OK , sendProduct . StatusCode ) ;
83
+ Assert . Equal ( product . Key , sendProduct . Body . Key ) ;
84
+
85
+ await Assert . ThrowsAsync < NotFoundException > ( async ( ) =>
86
+ {
87
+ await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Get ( ) . SendAsync ( ) ;
88
+ } ) ;
89
+
90
+ var execHead = await apiRoot . Products ( ) . WithKey ( product . Key ) . Head ( ) . ExecuteAsync ( ) ;
91
+ Assert . Equal ( "" , execHead ) ;
92
+ var execUnknownHead = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Head ( ) . ExecuteAsync ( ) ;
93
+ Assert . Equal ( "" , execUnknownHead ) ;
94
+
95
+ var sendHead = await apiRoot . Products ( ) . WithKey ( product . Key ) . Head ( ) . SendAsync ( ) ;
96
+ Assert . True ( sendHead . IsSuccess ( ) ) ;
97
+ Assert . Equal ( HttpStatusCode . OK , sendHead . StatusCode ) ;
98
+ Assert . Equal ( "" , sendHead . Body ) ;
99
+
100
+ var sendUnknownHead = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Head ( ) . SendAsync ( ) ;
101
+ Assert . False ( sendUnknownHead . IsSuccess ( ) ) ;
102
+ Assert . Equal ( HttpStatusCode . NotFound , sendUnknownHead . StatusCode ) ;
103
+ Assert . Equal ( "" , sendUnknownHead . Body ) ;
104
+ } ) ;
105
+ }
106
+
107
+ [ Fact ]
108
+ public async Task NotFoundReturnsDefault ( )
109
+ {
110
+ var configuration = new ConfigurationBuilder ( ) .
111
+ AddJsonFile ( "appsettings.test.Development.json" , true ) .
112
+ AddEnvironmentVariables ( ) .
113
+ AddUserSecrets < ServiceProviderFixture > ( ) .
114
+ AddEnvironmentVariables ( "CTP_" ) .
115
+ Build ( ) ;
116
+
117
+ var s = new ServiceCollection ( ) ;
118
+ s . UseCommercetoolsApi ( configuration , "Client" , options : new ClientOptions ( ) { NotFoundReturnsDefault = true } ) ;
119
+ var p = s . BuildServiceProvider ( ) ;
120
+
121
+ var apiRoot = p . GetService < ProjectApiRoot > ( ) ;
122
+ await WithProduct ( apiRoot , async product =>
123
+ {
124
+ var execProduct = await apiRoot . Products ( ) . WithKey ( product . Key ) . Get ( ) . ExecuteAsync ( ) ;
125
+ Assert . NotNull ( execProduct ) ;
126
+ Assert . Equal ( product . Key , execProduct . Key ) ;
127
+
128
+ var execUnknownProduct = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Get ( ) . ExecuteAsync ( ) ;
129
+ Assert . Null ( execUnknownProduct ) ;
130
+
131
+ var sendProduct = await apiRoot . Products ( ) . WithKey ( product . Key ) . Get ( ) . SendAsync ( ) ;
132
+ Assert . True ( sendProduct . IsSuccess ( ) ) ;
133
+ Assert . Equal ( HttpStatusCode . OK , sendProduct . StatusCode ) ;
134
+ Assert . Equal ( product . Key , sendProduct . Body . Key ) ;
135
+
136
+ var sendUnknownProduct = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Get ( ) . SendAsync ( ) ;
137
+ Assert . False ( sendUnknownProduct . IsSuccess ( ) ) ;
138
+ Assert . Equal ( HttpStatusCode . NotFound , sendUnknownProduct . StatusCode ) ;
139
+ Assert . Null ( sendUnknownProduct . Body ) ;
140
+
141
+ var execHead = await apiRoot . Products ( ) . WithKey ( product . Key ) . Head ( ) . ExecuteAsync ( ) ;
142
+ Assert . Equal ( "" , execHead ) ;
143
+ var execUnknownHead = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Head ( ) . ExecuteAsync ( ) ;
144
+ Assert . Equal ( "" , execUnknownHead ) ;
145
+
146
+ var sendHead = await apiRoot . Products ( ) . WithKey ( product . Key ) . Head ( ) . SendAsync ( ) ;
147
+ Assert . True ( sendHead . IsSuccess ( ) ) ;
148
+ Assert . Equal ( HttpStatusCode . OK , sendHead . StatusCode ) ;
149
+ Assert . Equal ( "" , sendHead . Body ) ;
150
+
151
+ var sendUnknownHead = await apiRoot . Products ( ) . WithKey ( product . Key + "-unknown" ) . Head ( ) . SendAsync ( ) ;
152
+ Assert . False ( sendUnknownHead . IsSuccess ( ) ) ;
153
+ Assert . Equal ( HttpStatusCode . NotFound , sendUnknownHead . StatusCode ) ;
154
+ Assert . Equal ( "" , sendUnknownHead . Body ) ;
155
+ } ) ;
156
+ }
54
157
55
158
[ Fact ]
56
159
public async Task UploadProductImage ( )
0 commit comments