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

PruebaP #80

Open
wants to merge 47 commits into
base: upgrading-nuget-packages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2b3cf83
Updating NuGet Packages.
lelong37 Nov 16, 2018
0c5c3d2
Update readme.md
lelong37 May 30, 2019
f6e039e
CancellationToken is now set to default (#56)
Domitnator Aug 11, 2019
7e6fdad
Repository fire and forget (#57)
Domitnator Aug 11, 2019
d9bbd54
Add global.json file. (#59)
Aug 11, 2019
4615460
Fix test: QueryableSql_Should_Allow_Composition.
Aug 11, 2019
2a6a8f1
Update SDK in travis.yml.
Aug 11, 2019
bcc249a
Update to EF Core 2.2.
Aug 11, 2019
7929e4b
Create v2.2.0 Nuget packages.
Aug 11, 2019
cd901a0
Update readme.md
lelong37 Sep 20, 2019
d1f93bd
Update readme.md
lelong37 Sep 20, 2019
025df4d
Update readme.md
lelong37 Sep 20, 2019
8db8804
Update to EF Core 3.0-preview7.
Aug 12, 2019
0184565
Update to EF Core 3.0.
Oct 14, 2019
0b35619
Update to EF Core 3.1.
Mar 10, 2020
b16378c
Fix Where Clause LINQ expression Queryable could not be translated.
ozturkfatih Feb 25, 2020
3b1f5fe
Add support for MongoDb.
Mar 14, 2020
74a1c8c
Add Queryable and Pagination tests.
Mar 14, 2020
1640003
Update Delete in Mongo library to return deleted count.
Mar 14, 2020
7fc287b
Update ReadMe with Mongo, samples info.
Mar 14, 2020
b4fa79c
Merge branches 'master' and 'master' of https://github.com/urfnet/URF…
Mar 14, 2020
e42816b
Add IQueryable extension methods to hide IMongoQueryable.
Mar 15, 2020
a70c49c
#58 FirstOrDefaultAsnyc()
ozturkfatih Mar 15, 2020
7104cfd
refactor the unit test
ozturkfatih Mar 15, 2020
89b0a4c
Update Abstractions, EF projects to 3.1.2.
Mar 15, 2020
c9292fd
Add NuGet packages
tonysneed Nov 24, 2020
84c5a3b
Update to .NET 5, EF Core 5
tonysneed Nov 24, 2020
69f8464
Merge pull request #78 from urfnet/update-5-0-0
tonysneed Nov 24, 2020
2c87b64
Update to .NET 6; rename IEnumerbale.cs to IEnumerable.cs.
tonysneed Feb 7, 2022
b0e616c
Merge pull request #84 from urfnet/update-net-6
tonysneed Feb 7, 2022
118b74a
Remove IEnumerable to avoid collision with .NET type.
tonysneed Feb 8, 2022
7e1ab01
Update package version to 6.0.1.
tonysneed Feb 8, 2022
b2b4baf
Merge pull request #86 from urfnet/remove-ienumerable
tonysneed Feb 8, 2022
74390f3
Clean up ReSharper warnings.
Aug 4, 2022
e7e4fdb
Add IDocumentUnitOfWork, DocumentUnitOfWork.cs.
Aug 4, 2022
eb3b659
Merge pull request #92 from urfnet/add-mongo-uow
tonysneed Aug 4, 2022
492b6f8
Refactor DocumentUnitOfWork.
Aug 8, 2022
37d6eb7
Update to EF7.
tonysneed Feb 19, 2023
283fb4c
Merge branch 'master' into update-ef7
tonysneed Feb 19, 2023
007372f
Merge pull request #96 from urfnet/update-ef7
tonysneed Feb 19, 2023
72b220f
Update package versions
tonysneed Feb 19, 2023
80d2dcd
Merge pull request #97 from urfnet/update-package-versions
tonysneed Feb 19, 2023
d1f5be0
Skip ExecuteSqlCommandAsync_Should_Execute_Sql
tonysneed Feb 19, 2023
ebd10bd
Upgrade to .NET 8
tonysneed Sep 7, 2024
6487b0a
Merge pull request #102 from urfnet/update-net-8
tonysneed Sep 7, 2024
91c5e82
Update to Strongly Named MongoDB Driver Version 2.28
tonysneed Sep 18, 2024
56eb74e
Merge pull request #104 from urfnet/update-mongo
tonysneed Sep 18, 2024
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
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
dist: xenial
addons:
snaps:
- name: dotnet-sdk
classic: true
channel: latest/beta
sudo: required
language: csharp
mono: none
dotnet: 2.1.300
script:
- sudo snap alias dotnet-sdk.dotnet dotnet
- dotnet --version
- dotnet build
- dotnet test URF.Core.EF.Tests --no-build --no-restore
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.1.0</Version>
<Version>8.0.0</Version>
<Authors>Long Le, Tony Sneed</Authors>
<PackageLicenseUrl>https://github.com/urfnet/URF.Core/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/urfnet/URF.Core</PackageProjectUrl>
<PackageIconUrl>https://user-images.githubusercontent.com/2836367/36162252-7ec8dd8a-10ab-11e8-936c-11bbb77ef574.png</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
<Title>URF - Unit of Work and Repositories Framework for .NET Standard and .NET Core (Official): Abstractions.Services</Title>
<Description>This official URF framework minimizes the surface area of your ORM technlogy from disseminating in your application. Framework provides an elegant way to implement a reusable and extensible Unit of Work and Repository pattern.</Description>
<PackageTags>repository unitofwork patterns</PackageTags>
<PackageReleaseNotes>https://github.com/urfnet/URF.Core/releases/tag/v8.0.0</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\URF.Core.Abstractions.Trackable\URF.Core.Abstractions.Trackable.csproj" />
<ProjectReference Include="..\URF.Core.Abstractions\URF.Core.Abstractions.csproj" />
Expand Down
Binary file added URF.Core.Abstractions.Services/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.1.0</Version>
<Version>8.0.0</Version>
<Authors>Long Le, Tony Sneed</Authors>
<PackageLicenseUrl>https://github.com/urfnet/URF.Core/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/urfnet/URF.Core</PackageProjectUrl>
<PackageIconUrl>https://user-images.githubusercontent.com/2836367/36162252-7ec8dd8a-10ab-11e8-936c-11bbb77ef574.png</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
<Title>URF - Unit of Work and Repositories Framework for .NET Standard and .NET Core (Official): Abstractions.Trackable</Title>
<Description>This official URF framework minimizes the surface area of your ORM technlogy from disseminating in your application. Framework provides an elegant way to implement a reusable and extensible Unit of Work and Repository pattern.</Description>
<PackageTags>repository unitofwork patterns</PackageTags>
<PackageReleaseNotes>https://github.com/urfnet/URF.Core/releases/tag/v8.0.0</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TrackableEntities.Common.Core" Version="1.1.0" />
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TrackableEntities.Common.Core" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file added URF.Core.Abstractions.Trackable/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions URF.Core.Abstractions/IDocumentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

namespace URF.Core.Abstractions
{
public interface IDocumentRepository<TEntity> where TEntity : class
{
Task<List<TEntity>> FindManyAsync(CancellationToken cancellationToken = default);

Task<List<TEntity>> FindManyAsync(Expression<Func<TEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<TEntity> FindOneAsync(Expression<Func<TEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<TEntity> FindOneAndReplaceAsync(Expression<Func<TEntity, bool>> filter, TEntity item, CancellationToken cancellationToken = default);

Task<TEntity> InsertOneAsync(TEntity item, CancellationToken cancellationToken = default);

Task<List<TEntity>> InsertManyAsync(IEnumerable<TEntity> items, CancellationToken cancellationToken = default);

Task<int> DeleteOneAsync(Expression<Func<TEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<int> DeleteManyAsync(Expression<Func<TEntity, bool>> filter, CancellationToken cancellationToken = default);

IQueryable<TEntity> Queryable();
}
}
10 changes: 10 additions & 0 deletions URF.Core.Abstractions/IDocumentUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;

namespace URF.Core.Abstractions;

public interface IDocumentUnitOfWork
{
Task StartTransactionAsync();
Task CommitAsync();
Task AbortAsync();
}
12 changes: 8 additions & 4 deletions URF.Core.Abstractions/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ public interface IQuery<TEntity> where TEntity : class
IQuery<TEntity> ThenBy(Expression<Func<TEntity, object>> thenBy);
IQuery<TEntity> ThenByDescending(Expression<Func<TEntity, object>> thenByDescending);
Task<int> CountAsync(CancellationToken cancellationToken = default);
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken);
Task<TEntity> SingleOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken);
Task<TEntity> FirstOrDefaultAsync(CancellationToken cancellationToken = default);
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
Task<TEntity> SingleOrDefaultAsync(CancellationToken cancellationToken = default);
Task<TEntity> SingleOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
Task<IEnumerable<TEntity>> SelectSqlAsync(string sql, object[] parameters, CancellationToken cancellationToken = default);
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken);
Task<bool> AnyAsync(CancellationToken cancellationToken);
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
Task<bool> AnyAsync(CancellationToken cancellationToken = default);
Task<bool> AllAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

}
}
13 changes: 9 additions & 4 deletions URF.Core.Abstractions/URF.Core.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.1.0</Version>
<Version>8.0.0</Version>
<Authors>Long Le, Tony Sneed</Authors>
<PackageLicenseUrl>https://github.com/urfnet/URF.Core/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/urfnet/URF.Core</PackageProjectUrl>
<PackageIconUrl>https://user-images.githubusercontent.com/2836367/36162252-7ec8dd8a-10ab-11e8-936c-11bbb77ef574.png</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
<Title>URF - Unit of Work and Repositories Framework for .NET Standard and .NET Core (Official): Abstractions</Title>
<Description>This official URF framework minimizes the surface area of your ORM technlogy from disseminating in your application. Framework provides an elegant way to implement a reusable and extensible Unit of Work and Repository pattern.</Description>
<PackageTags>repository unitofwork service patterns</PackageTags>
<PackageReleaseNotes>https://github.com/urfnet/URF.Core/releases/tag/v8.0.0</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/urfnet/URF.Core</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

</Project>
Binary file added URF.Core.Abstractions/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions URF.Core.EF.Tests/Contexts/NorthwindDbContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public static void SeedDataSql(this NorthwindDbContext context,
{
context.Database.OpenConnection();
context.Categories.AddRange(categories);
context.Database.ExecuteSqlCommand("DELETE Categories");
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Categories ON");
context.Database.ExecuteSqlRaw("DELETE Categories");
context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Categories ON");
context.SaveChanges();
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Categories OFF");
context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Categories OFF");

context.Products.AddRange(products);
context.Database.ExecuteSqlCommand("DELETE Products");
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Products ON");
context.Database.ExecuteSqlRaw("DELETE Products");
context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Products ON");
context.SaveChanges();
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Products OFF");
context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Products OFF");
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion URF.Core.EF.Tests/Models/MyProductComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace URF.Core.EF.Tests.Models
internal class MyProductComparer : IEqualityComparer<MyProduct>
{
public bool Equals(MyProduct x, MyProduct y)
=> x.Id == y.Id && (string.Compare(x.Name, y.Name, StringComparison.InvariantCulture) == 0) && x.Price == y.Price && x.Category == y.Category;
=> x!.Id == y!.Id && (string.Compare(x.Name, y.Name, StringComparison.InvariantCulture) == 0) && x.Price == y.Price && x.Category == y.Category;

public int GetHashCode(MyProduct x)
=> x.Id.GetHashCode()
Expand Down
4 changes: 2 additions & 2 deletions URF.Core.EF.Tests/QueryIncludeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ private void EnsureEntities<TEntity>(NorthwindDbContext context, IEnumerable<TEn
var insertOn = $"SET IDENTITY_INSERT dbo.{tableName} ON";
var insertOff = $"SET IDENTITY_INSERT dbo.{tableName} OFF";
if (typeof(TEntity) != typeof(Customer) && typeof(TEntity) != typeof(OrderDetail))
context.Database.ExecuteSqlCommand(insertOn);
context.Database.ExecuteSqlRaw(insertOn);
context.SaveChanges();
if (typeof(TEntity) != typeof(Customer) && typeof(TEntity) != typeof(OrderDetail))
context.Database.ExecuteSqlCommand(insertOff);
context.Database.ExecuteSqlRaw(insertOff);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions URF.Core.EF.Tests/RepositorySqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public async Task QueryableSql_Should_Allow_Composition()
var comparer = new MyProductComparer();
var expected1 = new MyProduct { Id = 1, Name = "Chai", Price = 18m, Category = "Beverages" };
var expected2 = new MyProduct { Id = 2, Name = "Chang", Price = 19m, Category = "Beverages" };
var expected3 = new MyProduct { Id = 24, Name = "Guarana Fantastica", Price = 4.5m, Category = "Beverages" };
var expected3 = new MyProduct { Id = 35, Name = "Steeleye Stout", Price = 18m, Category = "Beverages" };
var repository = new Repository<Product>(_fixture.Context);

// Act
var query = repository.QueryableSql("SELECT * FROM Products");
var products = await query
.Include(p => p.Category)
.Where(p => p.UnitPrice > 15)
.Where(p => (new[] { 1, 2, 35 }).Contains(p.ProductId))
.Select(p => new MyProduct
{
Id = p.ProductId,
Expand Down
60 changes: 59 additions & 1 deletion URF.Core.EF.Tests/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task Queryable_Should_Allow_Composition()
var products = await query
.Take(2)
.Include(p => p.Category)
.Where(p => p.UnitPrice > 15)
.Where(p => p.UnitPrice.CompareTo(15.00m) > 0 )
.Select(p => new MyProduct
{
Id = p.ProductId,
Expand Down Expand Up @@ -315,6 +315,64 @@ public async Task SelectAsync_Should_Return_Entities()
Assert.Equal(77, enumerable.Length);
}

[Fact]
public async Task Queries_should_be_fired_and_forgotten()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);

// Act
var products = await repository.Query().Where(p => p.ProductId == 1).SelectAsync();

// Assert
Assert.NotNull(products);

// Act
var product = await repository.Query().SingleOrDefaultAsync(s => s.ProductId == 2);

// Assert
Assert.NotNull(product);
}

[Fact]
public async Task FirstOrDefaultAsync_Should_Return_Entity()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);

// Act
var product = await repository.Query().Where(p => p.CategoryId == 1).FirstOrDefaultAsync();

// Assert
Assert.NotNull(product);
}

[Fact]
public async Task FirstOrDefaultAsync_Should_Return_Null()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);

// Act
var product = await repository.Query().Where(p => p.CategoryId == -1).FirstOrDefaultAsync();

// Assert
Assert.Null(product);
}

[Fact]
public async Task FirstOrDefaultAsync_With_Predicate_Should_Return_Entity()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);

// Act
var product = await repository.Query().FirstOrDefaultAsync(s => s.ProductId == 1);

// Assert
Assert.NotNull(product);
}

[Fact]
public void Update_Should_Set_Entity_State_Modified()
{
Expand Down
31 changes: 12 additions & 19 deletions URF.Core.EF.Tests/ServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using URF.Core.Abstractions;
using URF.Core.Abstractions.Trackable;
Expand All @@ -13,30 +12,24 @@ namespace URF.Core.EF.Tests
[Collection(nameof(NorthwindDbContext))]
public class ServiceTest
{
private readonly List<Order> _orders;
private readonly List<Product> _products;
private readonly List<Category> _categories;
private readonly List<Customer> _customers;
private readonly List<OrderDetail> _ordersDetails;

private readonly NorthwindDbContextFixture _fixture;

public ServiceTest(NorthwindDbContextFixture fixture)
{
_orders = Factory.Orders();
_products = Factory.Products();
_categories = Factory.Categories();
_customers = Factory.Customers();
_ordersDetails = Factory.OrderDetails();
var orders = Factory.Orders();
var products = Factory.Products();
var categories = Factory.Categories();
var customers = Factory.Customers();
var ordersDetails = Factory.OrderDetails();

_fixture = fixture;
_fixture.Initialize(true, () =>
{
_fixture.Context.Categories.AddRange(_categories);
_fixture.Context.Products.AddRange(_products);
_fixture.Context.Customers.AddRange(_customers);
_fixture.Context.Orders.AddRange(_orders);
_fixture.Context.OrderDetails.AddRange(_ordersDetails);
_fixture.Context.Categories.AddRange(categories);
_fixture.Context.Products.AddRange(products);
_fixture.Context.Customers.AddRange(customers);
_fixture.Context.Orders.AddRange(orders);
_fixture.Context.OrderDetails.AddRange(ordersDetails);
_fixture.Context.SaveChanges();
});
}
Expand Down Expand Up @@ -107,8 +100,8 @@ public async Task Service_Insert_Should_Insert_Into_Database()
var newCustomer = await customerRepository.FindAsync(customerId);

// Assert
Assert.Equal(newCustomer.CustomerId, customerId);
Assert.Equal(newCustomer.CompanyName, companyName);
Assert.Equal(customerId, newCustomer.CustomerId);
Assert.Equal(companyName, newCustomer.CompanyName);
}
}
}
6 changes: 4 additions & 2 deletions URF.Core.EF.Tests/Services/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public async Task<IEnumerable<Customer>> CustomersByCompany(string companyName)

public async Task<decimal> CustomerOrderTotalByYear(string customerId, int year)
{
return await Repository
var customers = await Repository
.Queryable()
.Where(c => c.CustomerId == customerId)
.ToListAsync();
return customers
.SelectMany(c => c.Orders.Where(o => o.OrderDate != null && o.OrderDate.Value.Year == year))
.SelectMany(c => c.OrderDetails)
.Select(c => c.Quantity * c.UnitPrice)
.SumAsync();
.Sum();
}

public async Task<IEnumerable<CustomerOrder>> GetCustomerOrder(string country)
Expand Down
Loading