-
Notifications
You must be signed in to change notification settings - Fork 3
/
Waiter.cs
37 lines (31 loc) · 1.06 KB
/
Waiter.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
using System;
using System.Collections.Generic;
namespace ClassLibrary4
{
public class Waiter
{
private readonly string name;
private readonly IPublishEvents next;
private readonly Random random = new Random();
public Waiter(string name, IPublishEvents next)
{
this.name = name;
this.next = next;
}
public void PlaceOrder(int orderNumber, int table, params Order.Item[] items)
{
var tookOrderOn = DateTime.UtcNow;
var order = new Order(orderNumber) {Table = table, Waiter = name, TookOrderOn = tookOrderOn};
items.ForEach(order.Add);
var customerWalksOutAt = tookOrderOn.AddSeconds(30);
if (random.NextDouble() > 0.75)
{
next.Publish(new Messages.OrderPlaced(order, customerWalksOutAt));
}
else
{
next.Publish(new Messages.SuspectOrderPlaced(order, customerWalksOutAt));
}
}
}
}