Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:findasync object type param edited #136

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading