public static string FormatCustomerAddressNotSet(OrderRequest order)
 {
     return string.Format(
         CultureInfo.InvariantCulture,
         "address of customer {0} not defined in order {1}.",
         order.CustomerAddress,
         order.Id);
 }
 public static string FormatProcessingOrder(OrderRequest order)
 {
     return string.Format(
         CultureInfo.InvariantCulture,
         "processing order {0} for customer {1} living in {2}.",
         order.Id,
         order.CustomerName,
         order.CustomerAddress);
 }
 public static string FormatOrderExceedsLimit(OrderRequest order, decimal amount, int limit)
 {
     return string.Format(
         CultureInfo.InvariantCulture,
         "amout of order {0} exceeds the limit of {1} with {2}.",
         order.Id,
         amount,
         limit);
 }
        public void LogsAsError_WhenCustomerAddressNotSet()
        {
            var orderWithoutCustomerAddress = new OrderRequest(1, "Dagobert Duck", null, new Collection<OrderItem>());

            this.testee.CreateOrder(orderWithoutCustomerAddress);

            A.CallTo(() => this.logger.Error(OrderCreatorLogExtensionMethods.FormatCustomerAddressNotSet(orderWithoutCustomerAddress)))
                .MustHaveHappened();
        }
        public void LogsAsInfo_WhenProcessingOrder()
        {
            var sampleOrder = new OrderRequest(1, "Donald Duck", "Duckburg", new Collection<OrderItem>());

            this.testee.CreateOrder(sampleOrder);

            A.CallTo(() => this.logger.Info(OrderCreatorLogExtensionMethods.FormatProcessingOrder(sampleOrder)))
                .MustHaveHappened();
        }
        public void CreateOrder(OrderRequest order)
        {
            this.logger.LogStartingOrderCreation();

            try
            {
                var command = new OrderCreationCommand(this.logger, order);
                command.Execute();

                this.logger.LogOrderCreationSuccessfull();
            }
            catch (Exception exception)
            {
                this.logger.LogOrderCreationFailed(exception);
            }
        }
 public OrderCreationCommand(ILogger logger, OrderRequest order)
 {
     this.logger = logger;
     this.order = order;
 }
 public static void LogProcessingOrder(this ILogger logger, OrderRequest order)
 {
     logger.Info(FormatProcessingOrder(order));
 }
 public static void LogOrderExceedsLimit(this ILogger logger, OrderRequest order, decimal amount, int limit)
 {
     logger.Warn(FormatOrderExceedsLimit(order, amount, limit));
 }
 public static void LogCustomerAddressNotSet(this ILogger logger, OrderRequest order)
 {
     logger.Error(FormatCustomerAddressNotSet(order));
 }
 public static string FormatCustomerNameNotSet(OrderRequest order)
 {
     return string.Format(CultureInfo.InvariantCulture, "no customer defined in order {0}.", order.Id);
 }
        public void LogsAsWarning_WhenOrderExceedsAmountLimit()
        {
            const int Limit = 150;
            const decimal AmountFirstItem = 20;
            const decimal AmountSecondItem = 300;
            const decimal Amount = AmountFirstItem + AmountSecondItem;

            OrderItem[] orderItems =
            {
                new OrderItem(12, "Pucks", AmountFirstItem),
                new OrderItem(13, "Skates", AmountSecondItem)
            };
            var orderExceedingAmountLimit = new OrderRequest(1, "Mighty Ducks", "Anaheim", orderItems);

            this.testee.CreateOrder(orderExceedingAmountLimit);

            A.CallTo(() => this.logger.Warn(
                OrderCreatorLogExtensionMethods.FormatOrderExceedsLimit(orderExceedingAmountLimit, Amount, Limit))).MustHaveHappened();
        }