This repository was archived by the owner on Apr 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
NetCoreEntityFramework.Tests Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -152,5 +152,64 @@ public void UpdateThrowsExceptionIfNull()
152152 Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _repository . Update ( null ) ) ;
153153 }
154154 #endregion
155+
156+ #region Delete
157+ [ Test ]
158+ public async Task DeleteSoftDeletesAndSetsDeletedAt ( )
159+ {
160+ bool success ;
161+ using ( _repository )
162+ {
163+ success = await _repository . Delete ( _entity ) ;
164+ }
165+
166+ var newlyDeletedEntity = await _repository . Get ( ( Guid ) _entity . Id , true ) ;
167+ Assert . IsTrue ( success ) ;
168+ Assert . IsTrue ( newlyDeletedEntity . Deleted ) ;
169+ Assert . NotNull ( newlyDeletedEntity . DeletedAt ) ;
170+ }
171+
172+ [ Test ]
173+ public void DeleteThrowsExceptionIfArgumentNull ( )
174+ {
175+ Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _repository . Delete ( null ) ) ;
176+ }
177+
178+ [ Test ]
179+ public async Task DeleteWithValidIdDeletesAndSetsDeletedAt ( )
180+ {
181+ bool success ;
182+ Guid id = ( Guid ) _entity . Id ;
183+ using ( _repository )
184+ {
185+ success = await _repository . Delete ( id ) ;
186+ }
187+
188+ var newlyDeletedEntity = await _repository . Get ( id , true ) ;
189+ Assert . IsTrue ( success ) ;
190+ Assert . IsTrue ( newlyDeletedEntity . Deleted ) ;
191+ Assert . NotNull ( newlyDeletedEntity . DeletedAt ) ;
192+ }
193+
194+ [ Test ]
195+ [ AutoData ]
196+ public async Task DeleteWithInvalidIdReturnsFalse ( Guid randomId )
197+ {
198+ bool success ;
199+
200+ using ( _repository )
201+ {
202+ success = await _repository . Delete ( randomId ) ;
203+ }
204+
205+ Assert . IsFalse ( success ) ;
206+ }
207+
208+ [ Test ]
209+ public void DeleteWithEmptyGuidThrowsException ( )
210+ {
211+ Assert . ThrowsAsync < ArgumentException > ( ( ) => _repository . Delete ( Guid . Empty ) ) ;
212+ }
213+ #endregion
155214 }
156215}
You can’t perform that action at this time.
0 commit comments