Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0-alpha'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel127 committed Apr 18, 2020
2 parents e01cc09 + 2718118 commit 95e924d
Show file tree
Hide file tree
Showing 27 changed files with 2,004 additions and 36 deletions.
29 changes: 24 additions & 5 deletions .azure/workflows/azure-ci-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ steps:
scannerMode: 'MSBuild'
projectKey: 'ef-unit-of-work'
projectName: 'EF-Unit-Of-Work'
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/coverage/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
# Build solution
- task: DotNetCoreCLI@2
Expand All @@ -51,15 +55,30 @@ steps:
- task: DotNetCoreCLI@2
displayName: 'Execute tests'
inputs:
command: 'test'
projects: '**/*.csproj'
publishTestResults: true
arguments: '--collect "Code Coverage"'
command: test
nobuild: true
arguments: --logger trx -c $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover%2ccobertura /p:CoverletOutput=$(Agent.TempDirectory)/coverage/ --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true

- task: DotNetCoreCLI@2
displayName: 'Install ReportGenerator tool'
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool

- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura"
displayName: 'Create reports'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml

# SonarCloud analyze and publish results
- task: SonarCloudAnalyze@1
displayName: 'Run SonarCloud analysis'
- task: SonarCloudPublish@1
displayName: 'Publish results on build summary'
displayName: 'Publish results on SonarCloud'
inputs:
pollingTimeoutSec: '300'
34 changes: 27 additions & 7 deletions .azure/workflows/azure-ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ variables:

steps:

- task: Bash@3
- task: ShellScript@2
displayName: 'Configure variables'
inputs:
filePath: '.azure/workflows/configure-variables-release.sh'
failOnStderr: true
scriptPath: '.azure/workflows/configure-variables-release.sh'
failOnStandardError: true

# Install .NET Core SDK
- task: UseDotNet@2
Expand All @@ -36,12 +36,17 @@ steps:

# SonarCloud Prepare Analysis
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis configuration'
inputs:
SonarCloud: 'SonarCloud Daniel127'
organization: 'daniel127'
scannerMode: 'MSBuild'
projectKey: 'ef-unit-of-work'
projectName: 'EF-Unit-Of-Work'
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/coverage/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
# Build solution
- task: DotNetCoreCLI@2
Expand All @@ -54,10 +59,25 @@ steps:
- task: DotNetCoreCLI@2
displayName: 'Execute tests'
inputs:
command: 'test'
projects: '**/*.csproj'
publishTestResults: true
arguments: '--collect "Code Coverage"'
command: test
nobuild: true
arguments: --logger trx -c $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover%2ccobertura /p:CoverletOutput=$(Agent.TempDirectory)/coverage/ --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true

- task: DotNetCoreCLI@2
displayName: 'Install ReportGenerator tool'
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool

- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura"
displayName: 'Create reports'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml

# SonarCloud analyze and publish results
- task: SonarCloudAnalyze@1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,5 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb
.vscode/
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Daniel Quiñones

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions QD.EntityFrameworkCore.UnitOfWork.Abstractions/IDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace QD.EntityFrameworkCore.UnitOfWork.Abstractions
{
/// <summary>
/// Use this together with Microsoft.EntityFrameworkCore.DbContext in the Application DbContext, it's necessary for generic implementation
/// </summary>
public interface IDbContext
{
}
}
195 changes: 193 additions & 2 deletions QD.EntityFrameworkCore.UnitOfWork.Abstractions/IRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,197 @@
namespace QD.EntityFrameworkCore.UnitOfWork.Abstractions
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

namespace QD.EntityFrameworkCore.UnitOfWork.Abstractions
{
public interface IRepository
/// <summary>
/// Defines the interfaces for generic repository.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
public interface IRepository<TEntity> where TEntity : class
{
#region Create
/// <summary>
/// Inserts a new entity synchronously.
/// </summary>
/// <param name="entity">The entity to insert.</param>
void Insert([NotNull] TEntity entity);

/// <summary>
/// Inserts a range of entities synchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
void Insert([NotNull] IEnumerable<TEntity> entities);

/// <summary>
/// Inserts a new entity asynchronously.
/// </summary>
/// <param name="entity">The entity to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
ValueTask<TEntity> InsertAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default);

/// <summary>
/// Inserts a range of entities asynchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
Task InsertAsync([NotNull] IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
#endregion

#region Read
/// <summary>
/// Gets all entities.
/// </summary>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="disableTracking"><c>True</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <returns>The <see cref="IQueryable"/>.</returns>
/// <exception cref="InvalidOperationException">If <see cref="TEntity"/> DbSet does not exist in DbContext</exception>
IQueryable<TEntity> GetAll(Expression<Func<TEntity, bool>>? predicate = null, Expression<Func<TEntity, IOrderedQueryable<TEntity>>>? orderBy = null, bool disableTracking = true);

/// <summary>
/// Gets the first or default entity based on a predicate, order by delegate and include delegate. This method defaults to a read-only, no-tracking query.
/// </summary>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <remarks>This method defaults to a read-only, no-tracking query.</remarks>
TEntity GetFirstOrDefault(Expression<Func<TEntity, bool>>? predicate = null, Expression<Func<TEntity, IOrderedQueryable<TEntity>>>? orderBy = null, bool disableTracking = true);

/// <summary>
/// Gets the first or default entity based on a predicate, order by delegate and include delegate. This method defaults to a read-only, no-tracking query.
/// </summary>
/// <param name="selector">The selector for projection.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <remarks>This method defaults to a read-only, no-tracking query.</remarks>
TResult GetFirstOrDefault<TResult>(Expression<Func<TEntity, TResult>> selector, Expression<Func<TEntity, bool>>? predicate = null, Expression<Func<TResult, IOrderedQueryable<TResult>>>? orderBy = null, bool disableTracking = true) where TResult : class;

/// <summary>
/// Gets the first or default entity based on a predicate, order by delegate and include delegate. This method defaults to a read-only, no-tracking query.
/// </summary>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query. </remarks>
Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>>? predicate = null, Expression<Func<TEntity, IOrderedQueryable<TEntity>>>? orderBy = null, bool disableTracking = true);

/// <summary>
/// Gets the first or default entity based on a predicate, order by delegate and include delegate. This method defaults to a read-only, no-tracking query.
/// </summary>
/// <param name="selector">The selector for projection.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query.</remarks>
Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<TEntity, TResult>> selector, Expression<Func<TEntity, bool>>? predicate = null, Expression<Func<TResult, IOrderedQueryable<TEntity>>>? orderBy = null, bool disableTracking = true) where TResult : class;

/// <summary>
/// Uses raw SQL queries to fetch the specified <typeparamref name="TEntity" /> data.
/// </summary>
/// <param name="sql">The raw SQL.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>An <see cref="IQueryable{TEntity}" /> that contains elements that satisfy the condition specified by raw SQL.</returns>
IQueryable<TEntity> FromSqlRaw(string sql, params object[] parameters);

/// <summary>
/// Uses interpolated SQL queries to fetch the specified <typeparamref name="TEntity" /> data.
/// </summary>
/// <param name="sql">The interpolated SQL.</param>
/// <returns></returns>
IQueryable<TEntity> FromSqlInterpolated(FormattableString sql);

/// <summary>
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
/// </summary>
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
/// <returns>The found entity or null.</returns>
TEntity Find([MaybeNull] params object[] keyValues);

/// <summary>
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
/// </summary>
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
/// <returns>A <see cref="Task{TEntity}"/> that represents the asynchronous find operation. The task result contains the found entity or null.</returns>
ValueTask<TEntity> FindAsync([MaybeNull] params object[] keyValues);

/// <summary>
/// Finds an entity with the given primary key values. If found, is attached to the context and returned. If no entity is found, then null is returned.
/// </summary>
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task{TEntity}"/> that represents the asynchronous find operation. The task result contains the found entity or null.</returns>
ValueTask<TEntity> FindAsync([MaybeNull] object[] keyValues, CancellationToken cancellationToken);
#endregion

#region Update
/// <summary>
/// Updates the specified entity.
/// </summary>
/// <param name="entity">The entity.</param>
void Update([NotNull] TEntity entity);

/// <summary>
/// Updates the specified entities.
/// </summary>
/// <param name="entities">The entities.</param>
void Update([NotNull] params TEntity[] entities);

/// <summary>
/// Updates the specified entities.
/// </summary>
/// <param name="entities">The entities.</param>
void Update([NotNull] IEnumerable<TEntity> entities);
#endregion

#region Delete
/// <summary>
/// Deletes the entity by the specified primary key.
/// </summary>
/// <param name="keyValues">The primary key value.</param>
void Delete([MaybeNull] params object[] keyValues);

/// <summary>
/// Deletes the specified entity.
/// </summary>
/// <param name="entity">The entity to delete.</param>
void Delete([NotNull] TEntity entity);

/// <summary>
/// Deletes the specified entities.
/// </summary>
/// <param name="entities">The entities.</param>
void Delete([NotNull] IEnumerable<TEntity> entities);
#endregion

#region Other
/// <summary>
/// Gets the count based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
int Count(Expression<Func<TEntity, bool>>? predicate = null);

/// <summary>
/// Gets the count based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns></returns>
Task<int> CountAsync(Expression<Func<TEntity, bool>>? predicate = null, CancellationToken cancellationToken = default);

/// <summary>
/// Checked exists record by predicate
/// </summary>
/// <param name="predicate"></param>
bool Any(Expression<Func<TEntity, bool>>? predicate = null);
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace QD.EntityFrameworkCore.UnitOfWork.Abstractions
{
/// <summary>
/// Defines the interfaces for <see cref="IRepository{TEntity}"/> interfaces.
/// </summary>
public interface IRepositoryFactory
{
/// <summary>
/// Gets the specified repository for the <typeparamref name="TEntity"/>.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <returns>An instance of type inherited from <see cref="IRepository{TEntity}"/> interface.</returns>
IRepository<TEntity> GetRepository<TEntity>() where TEntity : class;
}
}
Loading

0 comments on commit 95e924d

Please sign in to comment.