public Domain.CoffeeRoastingEvent Map(CoffeeRoastingEvent dbEvent)
 {
     return(new(
                Id <Domain.CoffeeRoastingEvent> .From(dbEvent.Id),
                dbEvent.Contacts.Select(c => c.Id).Select(id => Id <Contact> .From(id)),
                dbEvent.IsActive,
                LocalDate.FromDateTime(dbEvent.Date),
                LocalDate.FromDateTime(dbEvent.OrderByDate),
                Name <Domain.CoffeeRoastingEvent> .Create(dbEvent.Name),
                dbEvent.CoffeeRoastingEventCoffees.ToDictionary(
                    ec => OrderReferenceLabel.Create(ec.Label),
                    ec => new Coffee(
                        Id <Coffee> .From(ec.Coffee.Id),
                        Name <Coffee> .Create(ec.Coffee.Name),
                        Description.Create(ec.Coffee.Description),
                        UsdPrice.Create(ec.Coffee.Price),
                        Ounces.Create(ec.Coffee.OzWeight))),
                dbEvent.Orders.Select(order => new Domain.Order(
                                          Id <Domain.Order> .From(order.Id),
                                          Id <Contact> .From(order.ContactId),
                                          OffsetDateTime.FromDateTimeOffset(order.CreatedTimestamp),
                                          order.OrderCoffees.ToDictionary(
                                              oc => Id <Coffee> .From(oc.CoffeeId),
                                              oc => OrderQuantity.Create(oc.Quantity)),
                                          new Domain.Invoice(
                                              Id <Domain.Invoice> .From(order.Invoice.Id),
                                              UsdInvoiceAmount.Create(order.Invoice.Amount),
                                              order.Invoice.IsPaid,
                                              order.Invoice.PaymentMethod),
                                          order.IsConfirmed))));
 }
Пример #2
0
        public void Parse_HappyPath_WellFormatted_VerifyParsedResult()
        {
            // Arrange
            const string message = "Qty 3 A\r\nQty 1 C\rQty 2 B\nQty 3 D\r\n\r\nQty 14 G\r\n";

            var expectedOrderLines = new Dictionary <OrderReferenceLabel, OrderQuantity>
            {
                { OrderReferenceLabel.Create("A"), OrderQuantity.Create(3) },
                { OrderReferenceLabel.Create("C"), OrderQuantity.Create(1) },
                { OrderReferenceLabel.Create("B"), OrderQuantity.Create(2) },
                { OrderReferenceLabel.Create("D"), OrderQuantity.Create(3) },
                { OrderReferenceLabel.Create("G"), OrderQuantity.Create(14) },
            };
            // Act
            var actual = Sut.Parse(PhoneNumber, SmsMessage.Create(message));

            // Assert
            actual.Should().BeOfType <PlaceOrderCommand>();
            ((PlaceOrderCommand)actual).PhoneNumber.Should().Be(PhoneNumber);

            var orderDetails = ((PlaceOrderCommand)actual).OrderDetails;

            orderDetails.Should().HaveCount(expectedOrderLines.Count);
            orderDetails.Should().BeEquivalentTo(expectedOrderLines);
        }
        public void Customize(IFixture fixture)
        {
            fixture.Register(() =>
            {
                var rand = new Random();
                var ch   = (char)('a' + rand.Next(0, 26));

                return(OrderReferenceLabel.Create(ch.ToString().ToUpperInvariant()));
            });
        }
Пример #4
0
        public IDictionary <OrderReferenceLabel, Coffee> Label(IReadOnlyCollection <Coffee> coffees)
        {
            if (coffees.Count > Alphabet.Length)
            {
                throw new ApplicationException("Sorry, we can't apply a unique label to more than 26 coffees.");
            }

            return(Alphabet
                   .Take(coffees.Count)
                   .Select(ch => OrderReferenceLabel.Create(ch.ToString()))
                   .Zip(coffees)
                   .ToDictionary(x => x.Item1, x => x.Item2));
        }
Пример #5
0
        public void AddCoffee(OrderReferenceLabel label, Coffee coffee)
        {
            if (OfferedCoffees.ContainsKey(label))
            {
                throw new CoffeeLabelAlreadyUsedInRoastingEventException(label);
            }

            if (OfferedCoffees.Values.Contains(coffee))
            {
                throw new CoffeeAlreadyAddedToRoastingEventException(coffee);
            }

            var updatedCoffees = OfferedCoffees.ToDictionary(x => x.Key, x => x.Value);

            updatedCoffees.Add(label, coffee);

            OfferedCoffees = new ReadOnlyDictionary <OrderReferenceLabel, Coffee>(updatedCoffees);
        }
Пример #6
0
 public CoffeeLabelAlreadyUsedInRoastingEventException(OrderReferenceLabel label) => Label = label;