@@ -71,9 +71,34 @@ public override Task<Resource> DeleteAsync(IResourceIdentifier resourceIdentifie
7171 this . storage . Users . Remove ( identifier ) ;
7272 return Task . FromResult ( ( Resource ) user ) ;
7373 }
74+
7475 throw new CustomHttpResponseException ( HttpStatusCode . NotFound ) ;
7576 }
7677
78+ public override async Task < QueryResponseBase > PaginateQueryAsync ( IRequest < IQueryParameters > request )
79+ {
80+ if ( null == request )
81+ {
82+ throw new ArgumentNullException ( nameof ( request ) ) ;
83+ }
84+
85+ IReadOnlyCollection < Resource > resources = await this . QueryAsync ( request ) . ConfigureAwait ( false ) ;
86+ int totalCount = resources . Count ;
87+ if ( request . Payload . PaginationParameters != null )
88+ {
89+ int count = request . Payload . PaginationParameters ? . Count ?? 0 ;
90+ resources = ( IReadOnlyCollection < Resource > ) resources . Take ( count ) ;
91+ }
92+
93+
94+ QueryResponseBase result = new QueryResponse ( resources ) ;
95+ result . TotalResults = totalCount ;
96+ result . ItemsPerPage = resources . Count ;
97+
98+ result . StartIndex = resources . Any ( ) ? 1 : null ;
99+ return result ;
100+ }
101+
77102 public override Task < Resource [ ] > QueryAsync ( IQueryParameters parameters , string correlationIdentifier )
78103 {
79104 if ( parameters == null )
@@ -110,7 +135,6 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
110135 }
111136 else
112137 {
113-
114138 foreach ( IFilter queryFilter in parameters . AlternateFilters )
115139 {
116140 predicateAnd = PredicateBuilder . True < Core2EnterpriseUser > ( ) ;
@@ -121,16 +145,19 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
121145 {
122146 if ( string . IsNullOrWhiteSpace ( andFilter . AttributePath ) )
123147 {
124- throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
148+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources
149+ . ExceptionInvalidParameters ) ;
125150 }
126151
127152 else if ( string . IsNullOrWhiteSpace ( andFilter . ComparisonValue ) )
128153 {
129- throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
154+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources
155+ . ExceptionInvalidParameters ) ;
130156 }
131157
132158 // ID filter
133- else if ( andFilter . AttributePath . Equals ( AttributeNames . Identifier , StringComparison . OrdinalIgnoreCase ) )
159+ else if ( andFilter . AttributePath . Equals ( AttributeNames . Identifier ,
160+ StringComparison . OrdinalIgnoreCase ) )
134161 {
135162 if ( andFilter . FilterOperator != ComparisonOperator . Equals )
136163 {
@@ -141,18 +168,21 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
141168 }
142169
143170 var id = andFilter . ComparisonValue ;
144- predicateAnd = predicateAnd . And ( p => string . Equals ( p . Identifier , id , StringComparison . OrdinalIgnoreCase ) ) ;
171+ predicateAnd = predicateAnd . And ( p =>
172+ string . Equals ( p . Identifier , id , StringComparison . OrdinalIgnoreCase ) ) ;
145173 }
146174
147175 // UserName filter
148- else if ( andFilter . AttributePath . Equals ( AttributeNames . UserName , StringComparison . OrdinalIgnoreCase ) )
176+ else if ( andFilter . AttributePath . Equals ( AttributeNames . UserName ,
177+ StringComparison . OrdinalIgnoreCase ) )
149178 {
150179 if ( andFilter . FilterOperator != ComparisonOperator . Equals )
151180 {
152181 throw new ScimTypeException ( ErrorType . invalidFilter ,
153182 string . Format (
154183 SystemForCrossDomainIdentityManagementServiceResources
155- . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
184+ . ExceptionFilterOperatorNotSupportedTemplate ,
185+ andFilter . FilterOperator ) ) ;
156186 }
157187
158188 string userName = andFilter . ComparisonValue ;
@@ -173,13 +203,13 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
173203 }
174204
175205 string externalIdentifier = andFilter . ComparisonValue ;
176- predicateAnd = predicateAnd . And ( p => string . Equals ( p . ExternalIdentifier , externalIdentifier , StringComparison . OrdinalIgnoreCase ) ) ;
177-
178-
206+ predicateAnd = predicateAnd . And ( p => string . Equals ( p . ExternalIdentifier , externalIdentifier ,
207+ StringComparison . OrdinalIgnoreCase ) ) ;
179208 }
180209
181210 //Active Filter
182- else if ( andFilter . AttributePath . Equals ( AttributeNames . Active , StringComparison . OrdinalIgnoreCase ) )
211+ else if ( andFilter . AttributePath . Equals ( AttributeNames . Active ,
212+ StringComparison . OrdinalIgnoreCase ) )
183213 {
184214 if ( andFilter . FilterOperator != ComparisonOperator . Equals )
185215 {
@@ -194,7 +224,8 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
194224 }
195225
196226 // DisplayName Filter
197- else if ( andFilter . AttributePath . Equals ( AttributeNames . DisplayName , StringComparison . OrdinalIgnoreCase ) )
227+ else if ( andFilter . AttributePath . Equals ( AttributeNames . DisplayName ,
228+ StringComparison . OrdinalIgnoreCase ) )
198229 {
199230 if ( andFilter . FilterOperator != ComparisonOperator . Equals )
200231 {
@@ -245,15 +276,7 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
245276 results = this . storage . Users . Values . Where ( predicate . Compile ( ) ) ;
246277 }
247278
248- if ( parameters . PaginationParameters != null )
249- {
250- int count = parameters . PaginationParameters . Count . HasValue
251- ? parameters . PaginationParameters . Count . Value
252- : 0 ;
253- return Task . FromResult ( results . Take ( count ) . ToArray ( ) ) ;
254- }
255- else
256- return Task . FromResult ( results . ToArray ( ) ) ;
279+ return Task . FromResult ( results . ToArray ( ) ) ;
257280 }
258281
259282 public override Task < Resource > ReplaceAsync ( Resource resource , string correlationIdentifier )
@@ -278,7 +301,9 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
278301 ! string . Equals ( exisitingUser . Identifier , user . Identifier , StringComparison . OrdinalIgnoreCase ) )
279302 )
280303 {
281- throw new CustomHttpResponseException ( HttpStatusCode . Conflict ) ;
304+ throw new ScimTypeException ( ErrorType . uniqueness , string . Format (
305+ SystemForCrossDomainIdentityManagementServiceResources
306+ . ExceptionResourceConflict ) ) ;
282307 }
283308
284309 Core2EnterpriseUser exisitingUser = this . storage . Users . Values
@@ -339,17 +364,20 @@ public override Task<Resource> UpdateAsync(IPatch patch, string correlationIdent
339364
340365 if ( null == patch . ResourceIdentifier )
341366 {
342- throw new ArgumentException ( string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ) ;
367+ throw new ArgumentException ( string . Format ( SystemForCrossDomainIdentityManagementServiceResources
368+ . ExceptionInvalidOperation ) ) ;
343369 }
344370
345371 if ( string . IsNullOrWhiteSpace ( patch . ResourceIdentifier . Identifier ) )
346372 {
347- throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ;
373+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources
374+ . ExceptionInvalidOperation ) ;
348375 }
349376
350377 if ( null == patch . PatchRequest )
351378 {
352- throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ;
379+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources
380+ . ExceptionInvalidOperation ) ;
353381 }
354382
355383 PatchRequest2 patchRequest =
0 commit comments