Skip to content

Commit e82bc52

Browse files
committed
Merge pull request #6 from Ar3sDevelopment/dev
updates
2 parents 0336515 + 76d2b21 commit e82bc52

5 files changed

Lines changed: 27 additions & 41 deletions

File tree

UnitOfWork.NET.EntityFramework.NUnit/Test.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Diagnostics;
3-
using System.Linq;
43
using NUnit.Framework;
54
using UnitOfWork.NET.EntityFramework.Classes;
6-
using UnitOfWork.NET.EntityFramework.Interfaces;
75
using UnitOfWork.NET.EntityFramework.NUnit.Classes;
86
using UnitOfWork.NET.EntityFramework.NUnit.Data.Models;
97
using UnitOfWork.NET.EntityFramework.NUnit.DTO;
@@ -51,17 +49,17 @@ public void TestEntityRepository()
5149
Password = "test"
5250
};
5351

54-
entity = uow.EntityRepository<User>().Insert(entity);
52+
entity = uow.Repository<User>().Insert(entity);
5553
uow.SaveChanges();
5654
Assert.AreNotEqual(entity.Id, 0);
5755
Console.WriteLine(entity.Id);
5856
entity.Password = "test2";
59-
uow.EntityRepository<User>().Update(entity, entity.Id);
57+
uow.Repository<User>().Update(entity, entity.Id);
6058
uow.SaveChanges();
61-
Assert.AreEqual(entity.Password, uow.EntityRepository<User>().Entity(entity.Id).Password);
62-
uow.EntityRepository<User>().Delete(entity.Id);
59+
Assert.AreEqual(entity.Password, uow.Repository<User>().Entity(entity.Id).Password);
60+
uow.Repository<User>().Delete(entity.Id);
6361
uow.SaveChanges();
64-
Assert.IsNull(uow.EntityRepository<User>().Entity(entity.Id));
62+
Assert.IsNull(uow.Repository<User>().Entity(entity.Id));
6563
}
6664
}
6765

@@ -72,7 +70,7 @@ public void TestDTORepository()
7270

7371
using (var uow = new EntityUnitOfWork<TestDbContext>())
7472
{
75-
var users = uow.EntityRepository<User, UserDTO>().List();
73+
var users = uow.Repository<User, UserDTO>().List();
7674
stopwatch.Stop();
7775
Console.WriteLine(stopwatch.ElapsedMilliseconds);
7876

@@ -85,20 +83,20 @@ public void TestDTORepository()
8583
Password = "test"
8684
};
8785

88-
dto = uow.EntityRepository<User, UserDTO>().Insert(dto);
86+
dto = uow.Repository<User, UserDTO>().Insert(dto);
8987
uow.SaveChanges();
9088
var login = dto.Login;
91-
dto = uow.EntityRepository<User, UserDTO>().DTO(d => d.Login == login);
89+
dto = uow.Repository<User, UserDTO>().DTO(d => d.Login == login);
9290
Assert.IsNotNull(dto);
9391
Assert.AreNotEqual(dto.Id, 0);
9492
Console.WriteLine(dto.Id);
9593
dto.Password = "test2";
96-
uow.EntityRepository<User, UserDTO>().Update(dto, dto.Id);
94+
uow.Repository<User, UserDTO>().Update(dto, dto.Id);
9795
uow.SaveChanges();
98-
Assert.AreEqual(dto.Password, uow.EntityRepository<User, UserDTO>().DTO(dto.Id).Password);
99-
uow.EntityRepository<User, UserDTO>().Delete(dto.Id);
96+
Assert.AreEqual(dto.Password, uow.Repository<User, UserDTO>().DTO(dto.Id).Password);
97+
uow.Repository<User, UserDTO>().Delete(dto.Id);
10098
uow.SaveChanges();
101-
Assert.IsNull(uow.EntityRepository<User, UserDTO>().DTO(dto.Id));
99+
Assert.IsNull(uow.Repository<User, UserDTO>().DTO(dto.Id));
102100
}
103101
}
104102

@@ -178,13 +176,9 @@ public void TestReflection()
178176
{
179177
Console.WriteLine(uow.UserRolesRegistered);
180178

181-
Assert.IsNotNull(uow.Repository<User, UserDTO>(), "uow.Users != null by reflection base");
182-
Assert.IsNotNull(uow.Repository<Role, RoleDTO>(), "uow.Roles != null by reflection base");
183-
Assert.IsNotNull(uow.Repository<UserRole, UserRoleDTO>(), "uow.UserRoles != null by reflection base");
184-
185-
Assert.IsNotNull(uow.EntityRepository<User, UserDTO>(), "uow.Users != null by reflection");
186-
Assert.IsNotNull(uow.EntityRepository<Role, RoleDTO>(), "uow.Roles != null by reflection");
187-
Assert.IsNotNull(uow.EntityRepository<UserRole, UserRoleDTO>(), "uow.UserRoles != null by reflection");
179+
Assert.IsNotNull(uow.Repository<User, UserDTO>(), "uow.Users != null by reflection");
180+
Assert.IsNotNull(uow.Repository<Role, RoleDTO>(), "uow.Roles != null by reflection");
181+
Assert.IsNotNull(uow.Repository<UserRole, UserRoleDTO>(), "uow.UserRoles != null by reflection");
188182

189183
Assert.IsNotNull(uow.Users, "uow.Users != null");
190184
Assert.IsNotNull(uow.Roles, "uow.Roles != null");

UnitOfWork.NET.EntityFramework/Classes/EntityRepository.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,12 @@ public void Update(TDTO dto, params object[] ids)
116116
Update(entity, ids);
117117
}
118118

119-
/*
120-
member this.InsertAsync(dto : 'TDTO) = async { return this.Insert(dto) } |> Async.StartAsTask
121-
member this.UpdateAsync(dto : 'TDTO, ids) = async { this.Update(dto, ids) } |> Async.StartAsTask
122-
member this.DeleteAsync(dto : 'TDTO, [<ParamArray>] ids) = async { this.Delete(dto, ids) } |> Async.StartAsTask
123-
member this.ListAsync(whereExpr : Expression<Func<'TEntity, bool>>) = async { return this.List(whereExpr) } |> Async.StartAsTask
124-
member this.ListAsync() = async { return this.List() } |> Async.StartAsTask
125-
member this.DataSourceAsync(take : int, skip : int, sort : ICollection<Sort>, filter : Filter, whereFunc : Expression<Func<'TEntity, bool>>) = async { return this.DataSource(take, skip, sort, filter, whereFunc) } |> Async.StartAsTask
126-
member this.SingleDTOAsync([<ParamArray>] id : obj []) = async { return this.DTO(id) } |> Async.StartAsTask
127-
member this.SingleDTOAsync(expr : Expression<Func<'TEntity, bool>>) = async { return this.DTO(expr) } |> Async.StartAsTask
128-
*/
119+
public async Task<TDTO> InsertAsync(TDTO dto) => await new TaskFactory().StartNew(() => Insert(dto));
120+
public async Task UpdateAsync(TDTO dto, params object[] ids) => await new TaskFactory().StartNew(() => Update(dto, ids));
121+
public async Task<IEnumerable<TDTO>> ListAsync(Expression<Func<TEntity, bool>> expr) => await new TaskFactory().StartNew(() => List(expr));
122+
public async Task<IEnumerable<TDTO>> ListAsync() => await new TaskFactory().StartNew(List);
123+
public async Task<DataSourceResult<TDTO>> DataSourceAsync(int take, int skip, ICollection<Sort> sort, Filter filter, Expression<Func<TEntity, bool>> expr) => await new TaskFactory().StartNew(() => DataSource(take, skip, sort, filter, expr));
124+
public async Task<TDTO> DTOAsync(Expression<Func<TEntity, bool>> expr) => await new TaskFactory().StartNew(() => DTO(expr));
125+
public async Task<TDTO> DTOAsync(params object[] ids) => await new TaskFactory().StartNew(() => DTO(ids));
129126
}
130127
}

UnitOfWork.NET.EntityFramework/Classes/EntityUnitOfWork.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ public bool TransactionSaveChanges(Action<IEntityUnitOfWork> body)
130130

131131
public DbSet<TEntity> Set<TEntity>() where TEntity : class => _dbContext.Set<TEntity>();
132132

133-
public IEntityRepository<TEntity> EntityRepository<TEntity>() where TEntity : class => Repository<TEntity>() as IEntityRepository<TEntity>;
134-
135-
public IEntityRepository<TEntity, TDTO> EntityRepository<TEntity, TDTO>() where TEntity : class where TDTO : class => Repository<TEntity, TDTO>() as IEntityRepository<TEntity, TDTO>;
133+
public new IEntityRepository<TEntity> Repository<TEntity>() where TEntity : class => base.Repository<TEntity>() as IEntityRepository<TEntity>;
134+
public new IEntityRepository<TEntity, TDTO> Repository<TEntity, TDTO>() where TEntity : class where TDTO : class => base.Repository<TEntity, TDTO>() as IEntityRepository<TEntity, TDTO>;
136135

137136
private void CallOnSaveChanges<TEntity>(Dictionary<EntityState, IEnumerable<object>> entitiesObj) where TEntity : class
138137
{
139138
var entities = entitiesObj.ToDictionary(t => t.Key, t => t.Value.Cast<TEntity>());
140139

141-
EntityRepository<TEntity>().OnSaveChanges(entities);
140+
Repository<TEntity>().OnSaveChanges(entities);
142141
}
143142

144143
public async Task<int> SaveChangesAsync() => await new TaskFactory().StartNew(SaveChanges);

UnitOfWork.NET.EntityFramework/Extenders/AutofacExtender.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62
using Autofac.Builder;
73
using UnitOfWork.NET.EntityFramework.Interfaces;
84
using UnitOfWork.NET.Interfaces;

UnitOfWork.NET.EntityFramework/Interfaces/IEntityUnitOfWork.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public interface IEntityUnitOfWork : IUnitOfWork
4444
/// <summary>
4545
///
4646
/// </summary>
47-
IEntityRepository<TEntity> EntityRepository<TEntity>() where TEntity : class;
47+
IEntityRepository<TEntity> Repository<TEntity>() where TEntity : class;
4848

4949
/// <summary>
5050
///
5151
/// </summary>
52-
IEntityRepository<TEntity, TDTO> EntityRepository<TEntity, TDTO>() where TEntity : class where TDTO : class;
52+
IEntityRepository<TEntity, TDTO> Repository<TEntity, TDTO>() where TEntity : class where TDTO : class;
5353
}
5454
}

0 commit comments

Comments
 (0)