Skip to content

Instantly share code, notes, and snippets.

View explorer14's full-sized avatar

Aman Agrawal explorer14

View GitHub Profile
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env)
{
app.UseHealthChecks("/health/status",
new HealthCheckOptions
{
ResponseWriter = async (httpContext, healthReport) =>
{
var healthReportJson = JsonConvert.SerializeObject(healthReport);
public interface IRepository
{
void Add(T entity);
void Update(Guid id, T updatedEntity);
void Delete(Guid id);
IEnumerable Get(Expression<Func<T, bool>> predicate);
public class PeriodRepository : IPeriodRepository
{
// at this point, I have already created my DbContext which I will
// then use to generate the database by running EF Code First commands
private PeriodContext context;
public PeriodRepository(PeriodContext context)
{
this.context = context;
}
public interface IPeriodRepository : IRepository
{
// any aggregate specific queries and commands can
// be declared here.
}
// type restricted to operate only on IDomainObject reference types
public class GenericRepository : IRepository where T : class, IDomainObject
{
private DbContext context;
public GenericSqlRepository(DbContext context)
{
this.context = context;
}
public interface IRepository
{
Task GetOneAsync(Guid id);
Task<IEnumerable<TDomainObject>> GetListAsync(
Expression<Func<TDomainObject,bool>> predicate);
Task AddAsync(TDomainObject domainObject);
Task UpdateAsync(TDomainObject updatedEntity);
internal class StubPublisher : IPublishProductInformation
{
public Dictionary<int, Product> PublishedProducts = new Dictionary<int, Product>();
public async Task Publish(Product productInformation)
{
PublishedProducts.Add(productInformation.ProductId,
productInformation);
await Task.CompletedTask;
}
public class WhenRunningProductReorderLevelUseCase
{
[Fact]
public async Task Given_Products_With_Values_When_UseCase_Is_Executed_Then_The_Calculated_ReorderLevel_Is_As_Expected()
{
var testProducts = TestData.SampleProductsWithExpectedReorderLevels();
var publisherStub = new StubPublisher();
var activeProductsStub = new StubRetrieveActiveProducts(
testProducts.Select(x => x.OriginalProduct).ToList());
var useCase = new UseCase(publisherStub, activeProductsStub);
namespace Domain
{
public class UseCase
{
private readonly IPublisher _publisher;
private readonly IRetrieveProducts _productsRetriever;
public UseCase(
IPublisher publisher,
IRetrieveProducts productsRetriever)
namespace Domain
{
public class UseCase
{
private readonly IAdditionalDataA _serviceA;
private readonly IProductService _serviceB;
private readonly IAdditionalDataC _serviceC;
private readonly IAdditionalDataD _serviceD;
private readonly IAdditionalDataE _serviceE;
private readonly IAdditionalDataF _serviceF;