public async Task Check_DeleteNotExistRelationThrowsException(int firstId, int secondId) { //Arrange var cls = new InMemoryAppDbContext(); using (var context = cls.GetContextWithData()) { IItemRelationRepository repo = new ItemRelationRepository(context); ItemRelation startRelation = context.ItemsRelations.Find(firstId, secondId); startRelation.FirstItemId -= 100; await Assert.ThrowsAsync <InvalidOperationException>(() => repo.DeleteRecordAsync(startRelation)); context.Database.EnsureDeleted(); } }
public async Task Check_GetNotExistRecordReturnsNull(int firstId, int secondId) { //Arrange var cls = new InMemoryAppDbContext(); using (var context = cls.GetContextWithData()) { IItemRelationRepository repo = new ItemRelationRepository(context); ItemRelation expectedRelation = context.ItemsRelations.Find(firstId, secondId); ItemRelation actualRelation = await repo.GetRecordAsync(firstId, secondId); Assert.Null(actualRelation); Assert.Equal(expectedRelation, actualRelation); context.Database.EnsureDeleted(); } }
public async Task Check_GetRelatedItemsReturnEmptyCollection(int itemId) { //Arrange var cls = new InMemoryAppDbContext(); using (var context = cls.GetContextWithData()) { IItemRelationRepository repo = new ItemRelationRepository(context); var expected = await context.ItemsRelations .Where(r => r.FirstItemId == itemId || r.SecondItemId == itemId) .ToListAsync(); var actual = await repo.GetRelatedItems(itemId); Assert.Empty(actual); Assert.Equal(expected, actual); context.Database.EnsureDeleted(); } }
public async Task Check_DeleteRelationWorkingRight(int firstId, int secondId) { //Arrange var cls = new InMemoryAppDbContext(); using (var context = cls.GetContextWithData()) { IItemRelationRepository repo = new ItemRelationRepository(context); ItemRelation startRelation = context.ItemsRelations.Find(firstId, secondId); await repo.DeleteRecordAsync(startRelation); var actualRelation = context.ItemsRelations.Find(firstId, secondId); Assert.NotNull(startRelation); Assert.Null(actualRelation); context.Database.EnsureDeleted(); } }