Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View explorer14's full-sized avatar

Aman Agrawal explorer14

View GitHub Profile
static async Task Main(string[] args)
{
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await Save(product);
// we might update more entities
scope.Complete();
}
}
[HttpPost("api/workflow/invoke")]
public IActionResult Invoke()
{
Task.Run(async ()=> await useCase.StartBackgroundWork());
return Accepted();
}
public class GivenThereArePurchaseOrdersForTheProduct
{
[Fact]
public async Task ShouldCreateValidSuggestion()
{
var productId = {use a dummy id};
// set up the stub to already have a purchase order stored
var poStore = new PurchaseOrderStoreStub()
.WithPurchaseOrder(...);
[Fact]
public async Task ShouldSubmitCorrectPayload()
{
// ... Do all the set up required i.e. stubs, domain objects
// with pre-cooked data neccesary to execute the behaviour.
// Build the service/adapter object with this mock HttpMessageHandler
var loopbackHttpHandler = new SubmissionServiceHttpHandlerStub();
var submitter = new SubmissionService(
namespace Domain.Tests.Unit.Stubs
{
internal class SubmissionServiceHttpHandlerStub : HttpMessageHandler
{
private Dictionary<string, Payload> _requestPayload;
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
namespace Domain.ProductInformation.EventHandlers
{
public class ProductInformationHandler :
IHandleEvents<ProductInformation>
{
private readonly ReviewUsecase _reviewUseCase;
private readonly IStorePurchaseOrders _purchaseOrderStore;
private readonly IStoreProducts _productStore;
public ProductInformationHandler(
public class ModelBindingFailureFilterSimple : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(x => x.Filters.Add(new ModelBindingFailureFilter()));
}
public class ModelBindingFailureFilter : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
public static class ExceptionExtensions
{
public static string Details(this Exception exception)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(exception.Message);
while (exception.InnerException != null)
{
builder.AppendLine(exception.InnerException.Message);