@@ -77,8 +77,10 @@ await Assert.ThrowsAsync<ArgumentNullException>(() =>
7777 false ) ) ;
7878 }
7979
80- [ Fact ]
81- public async Task DeletesExistingDeprecationsIfStatusNotDeprecated ( )
80+ [ Theory ]
81+ [ InlineData ( false ) ]
82+ [ InlineData ( true ) ]
83+ public async Task DeletesExistingDeprecationsIfStatusNotDeprecated ( bool shouldUnlist )
8284 {
8385 // Arrange
8486 var packageWithDeprecation1 = new Package
@@ -114,6 +116,20 @@ public async Task DeletesExistingDeprecationsIfStatusNotDeprecated()
114116 . Completes ( )
115117 . Verifiable ( ) ;
116118
119+ var packageService = GetMock < IPackageService > ( ) ;
120+ var indexingService = GetMock < IIndexingService > ( ) ;
121+ foreach ( var package in packages )
122+ {
123+ // When deleting deprecations, packages should not be unlisted because the option is hidden in the UI.
124+ packageService
125+ . Setup ( x => x . MarkPackageUnlistedAsync ( package , false ) )
126+ . Throws < InvalidOperationException > ( ) ;
127+
128+ indexingService
129+ . Setup ( x => x . UpdatePackage ( package ) )
130+ . Verifiable ( ) ;
131+ }
132+
117133 var service = Get < PackageDeprecationService > ( ) ;
118134
119135 // Act
@@ -126,10 +142,11 @@ await service.UpdateDeprecation(
126142 null ,
127143 null ,
128144 null ,
129- false ) ;
145+ shouldUnlist ) ;
130146
131147 // Assert
132148 deprecationRepository . Verify ( ) ;
149+ indexingService . Verify ( ) ;
133150
134151 foreach ( var package in packages )
135152 {
@@ -143,22 +160,27 @@ await service.UpdateDeprecation(
143160 public async Task ReplacesExistingDeprecations ( bool shouldUnlist )
144161 {
145162 // Arrange
146- var unlistedPackageWithoutDeprecation = new Package ( ) ;
163+ var lastEdited = new DateTime ( 2019 , 3 , 4 ) ;
164+
165+ var unlistedPackageWithoutDeprecation = new Package
166+ {
167+ LastEdited = lastEdited
168+ } ;
147169
148170 var packageWithDeprecation1 = new Package
149171 {
150- Listed = true ,
151- Deprecations = new List < PackageDeprecation > { new PackageDeprecation ( ) }
172+ Deprecations = new List < PackageDeprecation > { new PackageDeprecation ( ) } ,
173+ LastEdited = lastEdited
152174 } ;
153175
154176 var packageWithoutDeprecation1 = new Package
155177 {
156- Listed = true ,
178+ LastEdited = lastEdited
157179 } ;
158180
159181 var packageWithDeprecation2 = new Package
160182 {
161- Listed = true ,
183+ LastEdited = lastEdited ,
162184 Deprecations = new List < PackageDeprecation >
163185 {
164186 new PackageDeprecation
@@ -176,12 +198,12 @@ public async Task ReplacesExistingDeprecations(bool shouldUnlist)
176198
177199 var packageWithoutDeprecation2 = new Package
178200 {
179- Listed = true ,
201+ LastEdited = lastEdited
180202 } ;
181203
182204 var packageWithDeprecation3 = new Package
183205 {
184- Listed = true ,
206+ LastEdited = lastEdited ,
185207 Deprecations = new List < PackageDeprecation >
186208 {
187209 new PackageDeprecation
@@ -221,6 +243,30 @@ public async Task ReplacesExistingDeprecations(bool shouldUnlist)
221243 . Completes ( )
222244 . Verifiable ( ) ;
223245
246+ var packageService = GetMock < IPackageService > ( ) ;
247+ var indexingService = GetMock < IIndexingService > ( ) ;
248+ foreach ( var package in packages )
249+ {
250+ var unlistPackageSetup = packageService
251+ . Setup ( x => x . MarkPackageUnlistedAsync ( package , false ) ) ;
252+
253+ if ( shouldUnlist )
254+ {
255+ unlistPackageSetup
256+ . Completes ( )
257+ . Verifiable ( ) ;
258+ }
259+ else
260+ {
261+ unlistPackageSetup
262+ . Throws < InvalidOperationException > ( ) ;
263+ }
264+
265+ indexingService
266+ . Setup ( x => x . UpdatePackage ( package ) )
267+ . Verifiable ( ) ;
268+ }
269+
224270 var service = Get < PackageDeprecationService > ( ) ;
225271
226272 var status = ( PackageDeprecationStatus ) 99 ;
@@ -272,6 +318,8 @@ await service.UpdateDeprecation(
272318
273319 // Assert
274320 deprecationRepository . Verify ( ) ;
321+ packageService . Verify ( ) ;
322+ indexingService . Verify ( ) ;
275323
276324 foreach ( var package in packages )
277325 {
@@ -283,15 +331,6 @@ await service.UpdateDeprecation(
283331 Assert . Equal ( alternatePackageRegistration , deprecation . AlternatePackageRegistration ) ;
284332 Assert . Equal ( alternatePackage , deprecation . AlternatePackage ) ;
285333 Assert . Equal ( customMessage , deprecation . CustomMessage ) ;
286-
287- if ( shouldUnlist )
288- {
289- Assert . False ( package . Listed ) ;
290- }
291- else if ( package != unlistedPackageWithoutDeprecation )
292- {
293- Assert . True ( package . Listed ) ;
294- }
295334 }
296335 }
297336 }
0 commit comments