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

Commit 578326c

Browse files
author
Morten Turn Pedersen
committed
Fixed unneeded casts in unit tests and removed duplicate test
1 parent ab9d68f commit 578326c

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

NetCoreEntityFramework.Tests/EntityRepositoryTests.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ public async Task AddAddsEntityAndSetsAttributes()
6969
}
7070

7171
[Test]
72-
public async Task AddEntityWithIdKeepsId()
72+
[AutoData]
73+
public async Task AddEntityWithIdKeepsId(Guid idToCreate)
7374
{
74-
Guid id = Guid.NewGuid();
7575
var entity = new TestEntity
7676
{
77-
Id = id
77+
Id = idToCreate
7878
};
7979

8080
await using (_repository)
8181
{
8282
await _repository.Add(entity);
8383
}
8484

85-
Assert.AreEqual(id, entity.Id);
85+
Assert.AreEqual(idToCreate, entity.Id);
8686
}
8787

8888
[Test]
@@ -93,13 +93,6 @@ public void AddThrowsExceptionIfEntityIsNull()
9393
#endregion
9494

9595
#region List
96-
[Test]
97-
public async Task GetListReturnsAllNotDeleted()
98-
{
99-
var entities = await _repository.GetList();
100-
101-
Assert.AreEqual(_listEntities.Count() + 1, entities.Count());
102-
}
10396

10497
[Test]
10598
public async Task GetListReturnsAll()
@@ -211,7 +204,7 @@ private TestEntity GetTestEntity(string property)
211204
[Test]
212205
public async Task GetValidEntityReturnsEntity()
213206
{
214-
var entity = await _repository.Get((Guid)_entity.Id);
207+
var entity = await _repository.Get(_entity.Id);
215208

216209
Assert.AreSame(_entity, entity);
217210
}
@@ -240,7 +233,7 @@ public async Task UpdateUpdatesUpdated(string propertyValue)
240233
await _repository.Update(_entity);
241234
}
242235

243-
var entity = await _repository.Get((Guid)_entity.Id);
236+
var entity = await _repository.Get(_entity.Id);
244237

245238
Assert.AreEqual(propertyValue, entity.Property);
246239
Assert.AreNotEqual(oldUpdated, entity.Updated);
@@ -259,7 +252,7 @@ public void UpdateThrowsExceptionIfNull()
259252
public async Task DeleteDeletesEntity()
260253
{
261254
bool success;
262-
var currentEntityCount = _context.Table.Count();
255+
var expectedEntityCount = _context.Table.Count() - 1;
263256
await using(_repository)
264257
{
265258
success = await _repository.Delete(_entity);
@@ -268,7 +261,7 @@ public async Task DeleteDeletesEntity()
268261
var newlyDeletedEntity = await _repository.Get(_entity.Id);
269262
Assert.IsTrue(success);
270263
Assert.IsNull(newlyDeletedEntity);
271-
Assert.AreEqual(currentEntityCount - 1, _context.Table.Count());
264+
Assert.AreEqual(expectedEntityCount, _context.Table.Count());
272265
}
273266

274267
[Test]

NetCoreEntityFramework.Tests/EntitySoftDeleteRepositoryTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,23 @@ private TestSoftDeleteEntity GetTestEntity(string property)
233233
[Test]
234234
public async Task GetValidEntityReturnsEntity()
235235
{
236-
var entity = await _repository.Get((Guid)_entity.Id);
236+
var entity = await _repository.Get(_entity.Id);
237237

238238
Assert.AreSame(_entity, entity);
239239
}
240240

241241
[Test]
242242
public async Task DontGetDeletedEntityWithoutFlag()
243243
{
244-
var entity = await _repository.Get((Guid)_deletedEntity.Id);
244+
var entity = await _repository.Get(_deletedEntity.Id);
245245

246246
Assert.IsNull(entity);
247247
}
248248

249249
[Test]
250250
public async Task GetDeletedEntityWithFlag()
251251
{
252-
var entity = await _repository.Get((Guid)_deletedEntity.Id, true);
252+
var entity = await _repository.Get(_deletedEntity.Id, true);
253253

254254
Assert.AreSame(_deletedEntity, entity);
255255
}
@@ -269,7 +269,7 @@ public async Task UpdateUpdatesUpdated(string propertyValue)
269269
await _repository.Update(_entity);
270270
}
271271

272-
var entity = await _repository.Get((Guid)_entity.Id);
272+
var entity = await _repository.Get(_entity.Id);
273273

274274
Assert.AreEqual(propertyValue, entity.Property);
275275
Assert.AreNotEqual(oldUpdated, entity.Updated);
@@ -293,7 +293,7 @@ public async Task DeleteSoftDeletesAndSetsDeletedAt()
293293
success = await _repository.Delete(_entity);
294294
}
295295

296-
var newlyDeletedEntity = await _repository.Get((Guid)_entity.Id, true);
296+
var newlyDeletedEntity = await _repository.Get(_entity.Id, true);
297297
Assert.IsTrue(success);
298298
Assert.IsTrue(newlyDeletedEntity.Deleted);
299299
Assert.NotNull(newlyDeletedEntity.DeletedAt);
@@ -309,7 +309,7 @@ public void DeleteThrowsExceptionIfArgumentNull()
309309
public async Task DeleteWithValidIdDeletesAndSetsDeletedAt()
310310
{
311311
bool success;
312-
Guid id = (Guid)_entity.Id;
312+
Guid id = _entity.Id;
313313
await using (_repository)
314314
{
315315
success = await _repository.Delete(id);
@@ -353,7 +353,7 @@ public async Task RestoreSetsDeletedFalse()
353353
success = await _repository.Restore(_deletedEntity);
354354
}
355355

356-
var restoredEntity = await _repository.Get((Guid)_deletedEntity.Id);
356+
var restoredEntity = await _repository.Get(_deletedEntity.Id);
357357
Assert.IsTrue(success);
358358
Assert.IsFalse(restoredEntity.Deleted);
359359
Assert.IsNull(restoredEntity.DeletedAt);
@@ -369,7 +369,7 @@ public void RestoreThrowsExceptionWhenEntityNull()
369369
public async Task RestoreOnIdSetsDeletedFalse()
370370
{
371371
bool success;
372-
Guid id = (Guid)_deletedEntity.Id;
372+
Guid id = _deletedEntity.Id;
373373

374374
await using (_repository)
375375
{

0 commit comments

Comments
 (0)