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
static async Task Main(string[] args) | |
{ | |
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) | |
{ | |
await Save(product); | |
// we might update more entities | |
scope.Complete(); | |
} | |
} |
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
[HttpPost("api/workflow/invoke")] | |
public IActionResult Invoke() | |
{ | |
Task.Run(async ()=> await useCase.StartBackgroundWork()); | |
return Accepted(); | |
} |
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
[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( |
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
namespace Domain.Tests.Unit.Stubs | |
{ | |
internal class SubmissionServiceHttpHandlerStub : HttpMessageHandler | |
{ | |
private Dictionary<string, Payload> _requestPayload; | |
protected override async Task<HttpResponseMessage> SendAsync( | |
HttpRequestMessage request, | |
CancellationToken cancellationToken) | |
{ |
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
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(...); |
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
namespace Domain.ProductInformation.EventHandlers | |
{ | |
public class ProductInformationHandler : | |
IHandleEvents<ProductInformation> | |
{ | |
private readonly ReviewUsecase _reviewUseCase; | |
private readonly IStorePurchaseOrders _purchaseOrderStore; | |
private readonly IStoreProducts _productStore; | |
public ProductInformationHandler( |
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
public class ModelBindingFailureFilterSimple : IActionFilter | |
{ | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
if (!context.ModelState.IsValid) | |
{ |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(x => x.Filters.Add(new ModelBindingFailureFilter())); | |
} |
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
public class ModelBindingFailureFilter : IActionFilter | |
{ | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
if (!context.ModelState.IsValid) | |
{ |
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
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); |
NewerOlder