-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle open generic type passed as parameter to ImplementInterface
- Loading branch information
Showing
32 changed files
with
399 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
samples/NetArchTest.SampleTests/SampleApp_ModuleOmega_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Reflection; | ||
using MediatR; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using NetArchTest.Rules; | ||
using SampleApp.ModuleOmega; | ||
|
||
|
||
namespace NetArchTest.SampleTests | ||
{ | ||
[TestClass] | ||
public class SampleApp_ModuleOmega_Tests | ||
{ | ||
static readonly Assembly AssemblyUnderTest = typeof(TestUtils).Assembly; | ||
|
||
[TestMethod] | ||
public void RequestHandlersShouldBeSealed() | ||
{ | ||
var result = Types.InAssembly(AssemblyUnderTest) | ||
.That() | ||
.ImplementInterface(typeof(IRequestHandler<,>)) | ||
.Should() | ||
.BeSealed() | ||
.GetResult(); | ||
|
||
Assert.IsTrue(result.IsSuccessful); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
samples/SampleApp.BuildingBlocks/Persistence/GenericRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SampleApp.BuildingBlocks.Persistence | ||
{ | ||
public abstract class GenericRepository<TEntity, TContext> where TEntity : class | ||
where TContext : DbContext | ||
{ | ||
protected readonly TContext context; | ||
|
||
|
||
public GenericRepository(TContext context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
|
||
public void Add(TEntity entity) | ||
{ | ||
context.Set<TEntity>().Add(entity); | ||
} | ||
public TEntity GetById(long id) | ||
{ | ||
return context.Set<TEntity>().Find(id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
samples/SampleApp.ModuleOmega/App/RequestHandlers/Questions/QuestionOnListDTO.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions | ||
{ | ||
internal class QuestionOnListDTO | ||
{ | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
samples/SampleApp.ModuleOmega/App/RequestHandlers/Questions/ReadQuestionsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using SampleApp.ModuleOmega.Persistence; | ||
|
||
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions | ||
{ | ||
internal sealed class ReadQuestionsHandler : IRequestHandler<ReadQuestionsQuery, List<QuestionOnListDTO>> | ||
{ | ||
private readonly ReadOnlyTestCreationDbContext context; | ||
|
||
public ReadQuestionsHandler(ReadOnlyTestCreationDbContext context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
|
||
public async Task<List<QuestionOnListDTO>> Handle(ReadQuestionsQuery query, CancellationToken cancellationToken) | ||
{ | ||
|
||
|
||
return null; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/SampleApp.ModuleOmega/App/RequestHandlers/Questions/ReadQuestionsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
|
||
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions | ||
{ | ||
internal class ReadQuestionsQuery : IRequest<List<QuestionOnListDTO>> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using SampleApp.ModuleOmega.Domain.Questions; | ||
|
||
namespace SampleApp.ModuleOmega.Domain | ||
{ | ||
internal interface ITestCreationUoW | ||
{ | ||
IQuestionRepository Questions { get; } | ||
|
||
Task Save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SampleApp.ModuleOmega.Domain.Questions | ||
{ | ||
internal sealed class Answer | ||
{ | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/SampleApp.ModuleOmega/Domain/Questions/IQuestionRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SampleApp.ModuleOmega.Domain.Questions | ||
{ | ||
internal interface IQuestionRepository | ||
{ | ||
Question GetByIdWithAnswers(long id); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/SampleApp.ModuleOmega/Domain/Questions/Question.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SampleApp.ModuleOmega.Domain.Questions | ||
{ | ||
internal sealed class Question | ||
{ | ||
private readonly List<Answer> _answers = new List<Answer>(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/SampleApp.ModuleOmega/Persistence/Questions/QuestionRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using SampleApp.BuildingBlocks.Persistence; | ||
using SampleApp.ModuleOmega.Domain.Questions; | ||
|
||
namespace SampleApp.ModuleOmega.Persistence.Questions | ||
{ | ||
internal sealed class QuestionRepository : GenericRepository<Question, TestCreationDbContext>, IQuestionRepository | ||
{ | ||
public QuestionRepository(TestCreationDbContext context) : base(context) | ||
{ | ||
|
||
} | ||
|
||
|
||
public Question GetByIdWithAnswers(long id) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
samples/SampleApp.ModuleOmega/Persistence/ReadOnlyTestCreationDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SampleApp.ModuleOmega.Persistence | ||
{ | ||
internal sealed class ReadOnlyTestCreationDbContext : TestCreationDbContext | ||
{ | ||
|
||
|
||
public ReadOnlyTestCreationDbContext(DbContextOptions options) : base(options) | ||
{ | ||
ChangeTracker.LazyLoadingEnabled = false; | ||
ChangeTracker.AutoDetectChangesEnabled = false; | ||
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
samples/SampleApp.ModuleOmega/Persistence/TestCreationDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
using SampleApp.ModuleOmega.Domain.Questions; | ||
|
||
namespace SampleApp.ModuleOmega.Persistence | ||
{ | ||
internal class TestCreationDbContext : DbContext | ||
{ | ||
public DbSet<Question> Questions { get; protected set; } | ||
|
||
|
||
public TestCreationDbContext(DbContextOptions options) : base(options) | ||
{ | ||
ChangeTracker.DeleteOrphansTiming = CascadeTiming.OnSaveChanges; | ||
} | ||
} | ||
} |
Oops, something went wrong.