Skip to content

Instantly share code, notes, and snippets.

@avegaraju
Created February 28, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avegaraju/90378aac89406d5d6023a60635916969 to your computer and use it in GitHub Desktop.
Save avegaraju/90378aac89406d5d6023a60635916969 to your computer and use it in GitHub Desktop.
public class ProductsImposter : IImposter
{
public Imposter Build()
{
return new ImposterDefinition("ProductsMock")
.DeclareResource("/api/Products", HttpMethod.Post)
.When(r => r.Content.Contains("Name:Test product"))
.Then(new ProductResponseCreator())
.Build();
}
}
public class ProductResponseCreator: IResponseCreator
{
public Response CreateResponse()
{
var productCreatedResponse = new ProductCreatedResponse
{
Message = "Product created.",
ProductId = (uint)new Random().Next(int.MaxValue)
};
return new ResponseBuilder().WithContent(productCreatedResponse, new JsonContentSerializer())
.WithStatusCode(HttpStatusCode.Created)
.Build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment