From 613de1793132fa40f33800b241d327173450bd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toygar=20Varl=C4=B1?= Date: Mon, 8 Jul 2024 11:35:45 +0300 Subject: [PATCH] feat:findasync object type param edited (#136) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toygar Varlı <02484578@ksnet.local> --- .../Repositories/AllReadWrite/EFRepository.cs | 10 +++++----- .../EFRepositoryTest.cs | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Carbon.Domain.EntityFrameworkCore.Extensions/Repositories/AllReadWrite/EFRepository.cs b/Carbon.Domain.EntityFrameworkCore.Extensions/Repositories/AllReadWrite/EFRepository.cs index 37c4832c..ea79b2b9 100644 --- a/Carbon.Domain.EntityFrameworkCore.Extensions/Repositories/AllReadWrite/EFRepository.cs +++ b/Carbon.Domain.EntityFrameworkCore.Extensions/Repositories/AllReadWrite/EFRepository.cs @@ -42,7 +42,7 @@ public EFRepository(TContext context) /// A task whose result is the requested object. public virtual async Task GetByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await context.Set().FindAsync(id, cancellationToken); + return await context.Set().FindAsync(new object[] { id }, cancellationToken); } /// @@ -79,7 +79,7 @@ public virtual async Task UpdateAsync(TEntity entity, CancellationToken /// A task whose result is the deleted object. If no matching entry is found, returns null instead. public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default) { - var entity = await context.Set().FindAsync(id,cancellationToken); + var entity = await context.Set().FindAsync(new object[] { id }, cancellationToken); if (entity == null) { return entity; @@ -151,7 +151,7 @@ public virtual async Task> DeleteRangeAsync(IEnumerable e /// The first element that is related to and also satisfies the given in the database. public virtual async Task GetAsync(Expression> predicate, CancellationToken cancellationToken = default) { - return await context.Set().AsQueryable().FirstOrDefaultAsync(predicate,cancellationToken); + return await context.Set().AsQueryable().FirstOrDefaultAsync(predicate, cancellationToken); } /// @@ -182,7 +182,7 @@ public virtual IQueryable QueryAsNoTracking() return context.Set().AsNoTracking(); } - } + } /// /// Saves changes made to the database. @@ -192,7 +192,7 @@ public virtual IQueryable QueryAsNoTracking() public async Task SaveChangesAsync(CancellationToken cancellationToken = default) { return await context.SaveChangesAsync(cancellationToken); - } + } /// /// Retrieves and returns all objects from the database. diff --git a/tests/Carbon.Domain.EntityFrameworkCore.UnitTests/EFRepositoryTest.cs b/tests/Carbon.Domain.EntityFrameworkCore.UnitTests/EFRepositoryTest.cs index 7bb771f7..30487307 100644 --- a/tests/Carbon.Domain.EntityFrameworkCore.UnitTests/EFRepositoryTest.cs +++ b/tests/Carbon.Domain.EntityFrameworkCore.UnitTests/EFRepositoryTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Xunit; @@ -19,15 +20,15 @@ public EFRepositoryTest() : base(EFRepositoryFixture.CreateContext()) { } - + [Theory] [FoundEntityGetByIdAsyncEFRepository] public async Task GetByIdAsync_Successfully_ReturnEntity(Guid Id) { // Arrange EFRepositoryFixture.CreateData(base.context, Id, Guid.NewGuid()); - // Act - var response = await base.GetByIdAsync(Id); + // Act + var response = await base.GetByIdAsync(Id); // Assert Assert.Equal("Name 1", response.Name); @@ -125,11 +126,11 @@ public async Task UpdateRangeAsync_Successfully_ReturnEntity(List