Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 84f8847

Browse files
author
Morten Turn Pedersen
committed
Implemented unit tests for restore
1 parent 0e3aa50 commit 84f8847

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

NetCoreEntityFramework.Tests/EntityRepositoryTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,64 @@ public void DeleteWithEmptyGuidThrowsException()
211211
Assert.ThrowsAsync<ArgumentException>(() => _repository.Delete(Guid.Empty));
212212
}
213213
#endregion
214+
215+
#region Restore
216+
[Test]
217+
public async Task RestoreSetsDeletedFalse()
218+
{
219+
bool success;
220+
221+
using(_repository)
222+
{
223+
success = await _repository.Restore(_deletedEntity);
224+
}
225+
226+
var restoredEntity = await _repository.Get((Guid)_deletedEntity.Id);
227+
Assert.IsTrue(success);
228+
Assert.IsFalse(restoredEntity?.Deleted);
229+
}
230+
231+
[Test]
232+
public void RestoreThrowsExceptionWhenEntityNull()
233+
{
234+
Assert.ThrowsAsync<ArgumentNullException>(() => _repository.Restore(null));
235+
}
236+
237+
[Test]
238+
public async Task RestoreOnIdSetsDeletedFalse()
239+
{
240+
bool success;
241+
Guid id = (Guid)_deletedEntity.Id;
242+
243+
using (_repository)
244+
{
245+
success = await _repository.Restore(id);
246+
}
247+
248+
var restoredEntity = await _repository.Get(id);
249+
Assert.IsTrue(success);
250+
Assert.IsFalse(restoredEntity?.Deleted);
251+
}
252+
253+
[Test]
254+
[AutoData]
255+
public async Task RestoreOnInvalidIdReturnsFalse(Guid randomId)
256+
{
257+
bool success;
258+
259+
using(_repository)
260+
{
261+
success = await _repository.Restore(randomId);
262+
}
263+
264+
Assert.IsFalse(success);
265+
}
266+
267+
[Test]
268+
public void RestoreOnEmptyGuidThrowsException()
269+
{
270+
Assert.ThrowsAsync<ArgumentException>(() => _repository.Restore(Guid.Empty));
271+
}
272+
#endregion
214273
}
215274
}

0 commit comments

Comments
 (0)