Skip to content

Instantly share code, notes, and snippets.

Aman Agrawal explorer14

Block or report user

Report or block explorer14

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View BackgroundProcessViaHttp.cs
[HttpPost("api/workflow/invoke")]
public IActionResult Invoke()
{
Task.Run(async ()=> await useCase.StartBackgroundWork());
return Accepted();
}
View SubmissionTest.cs
[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(
View SubmissionServiceHttpHandlerStub.cs
namespace Domain.Tests.Unit.Stubs
{
internal class SubmissionServiceHttpHandlerStub : HttpMessageHandler
{
private Dictionary<string, Payload> _requestPayload;
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
View ProductInformationHandler.Tests.cs
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(...);
View ProductEventHandler.cs
namespace Domain.ProductInformation.EventHandlers
{
public class ProductInformationHandler :
IHandleEvents<ProductInformation>
{
private readonly ReviewUsecase _reviewUseCase;
private readonly IStorePurchaseOrders _purchaseOrderStore;
private readonly IStoreProducts _productStore;
public ProductInformationHandler(
View SimplerActionFilter.cs
public class ModelBindingFailureFilterSimple : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
View Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(x => x.Filters.Add(new ModelBindingFailureFilter()));
}
View ModelValidationFilter.cs
public class ModelBindingFailureFilter : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
View ExceptionExtensions.cs
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);
View ValidationProblemDetails.cs
public class ValidationProblemDetails : ProblemDetails
{
public ValidationProblemDetails() : base()
{
}
public ValidationProblemDetails(
ModelStateDictionary modelStateDictionary)
: base()
{
You can’t perform that action at this time.