Skip to content

Commit

Permalink
feat:findasync object type param edited (#136)
Browse files Browse the repository at this point in the history
Co-authored-by: Toygar Varlı <[email protected]>
  • Loading branch information
ToygarVarli and Toygar Varlı committed Jul 8, 2024
1 parent 5ab54a2 commit 613de17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public EFRepository(TContext context)
/// <returns> A task whose result is the requested <typeparamref name="TEntity"/> object. </returns>
public virtual async Task<TEntity> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await context.Set<TEntity>().FindAsync(id, cancellationToken);
return await context.Set<TEntity>().FindAsync(new object[] { id }, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -79,7 +79,7 @@ public virtual async Task<TEntity> UpdateAsync(TEntity entity, CancellationToken
/// <returns> A task whose result is the deleted <typeparamref name="TEntity"/> object. If no matching entry is found, returns null instead. </returns>
public virtual async Task<TEntity> DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
var entity = await context.Set<TEntity>().FindAsync(id,cancellationToken);
var entity = await context.Set<TEntity>().FindAsync(new object[] { id }, cancellationToken);
if (entity == null)
{
return entity;
Expand Down Expand Up @@ -151,7 +151,7 @@ public virtual async Task<List<TEntity>> DeleteRangeAsync(IEnumerable<TEntity> e
/// <returns>The first <typeparamref name="TEntity"/> element that is related to <paramref name="tenantId"/> and also satisfies the given <paramref name="predicate"/> in the database.</returns>
public virtual async Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
{
return await context.Set<TEntity>().AsQueryable().FirstOrDefaultAsync(predicate,cancellationToken);
return await context.Set<TEntity>().AsQueryable().FirstOrDefaultAsync(predicate, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -182,7 +182,7 @@ public virtual IQueryable<TEntity> QueryAsNoTracking()
return context.Set<TEntity>().AsNoTracking();

}
}
}

/// <summary>
/// Saves changes made to the database.
Expand All @@ -192,7 +192,7 @@ public virtual IQueryable<TEntity> QueryAsNoTracking()
public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
return await context.SaveChangesAsync(cancellationToken);
}
}

/// <summary>
/// Retrieves and returns all <typeparamref name="TEntity"/> objects from the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -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);
Expand Down Expand Up @@ -125,11 +126,11 @@ public async Task UpdateRangeAsync_Successfully_ReturnEntity(List<CarbonContextT
var response = await base.UpdateRangeAsync(createResponse);

// Assert
for(var a = 0; a < response.Count; a++)
for (var a = 0; a < response.Count; a++)
{
Assert.Equal(createResponse[a].Name, response[a].Name);
}

}

[Theory]
Expand Down

0 comments on commit 613de17

Please sign in to comment.