-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFaker.cs
48 lines (43 loc) · 1.9 KB
/
Faker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using AutoBogus;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Faker360
{
public static class Faker
{
[FunctionName("Faker")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]HttpRequestMessage req, ILogger log)
{
var faker = AutoFaker.Create();
var shipTo = new AutoFaker<ShipTo>()
.RuleFor(f => f.name, f => f.Name.FirstName())
.RuleFor(f => f.address, f => f.Address.FullAddress())
.RuleFor(f => f.city, f => f.Address.City())
.RuleFor(f => f.state, f => f.Address.State())
.RuleFor(f => f.zip, f => f.Address.ZipCode());
var billTo = new AutoFaker<BillTo>()
.RuleFor(f => f.name, f => f.Name.FirstName())
.RuleFor(f => f.address, f => f.Address.FullAddress())
.RuleFor(f => f.city, f => f.Address.City())
.RuleFor(f => f.state, f => f.Address.State())
.RuleFor(f => f.zip, f => f.Address.ZipCode());
var order = new AutoFaker<PoOrder>()
.RuleFor(f => f.ponumber, f => f.Random.Int(0))
.RuleFor(f => f.name, f => f.Name.FullName())
.RuleFor(f => f.sku, f => f.Finance.BitcoinAddress())
.RuleFor(f => f.quantity, f => f.Random.Int(0, 20))
.RuleFor(f => f.messagetype, f => f.Finance.TransactionType())
.RuleFor(f => f.shipTo, () => shipTo)
.RuleFor(f => f.billTo, () => billTo);
var result = JsonConvert.DeserializeObject<PoOrder>(JsonConvert.SerializeObject(order.Generate()));
return req.CreateResponse(HttpStatusCode.Accepted, result);
}
}
}