public async Task <IHttpActionResult> Order(int menuItem)
        {
            // this is painful,
            //  but we can swap out concrete implementation
            //  unfortunately, this is not DRY
            var loggingService = new WebApiLoggingService();

            using (var context = new MyPizzaDbContext())
            {
                var queueService        = new StoreQueueService();
                var paymentService      = new PaymentService();
                var notificationService = new OrderNotificationService();

                var service = new PizzaOrderService(
                    context,
                    paymentService,
                    queueService,
                    notificationService,
                    loggingService);

                try
                {
                    var orderId = await service.OrderMenuItemAsync(menuItem);

                    return(Created("http://mypizza.com/orders/" + orderId, orderId));
                }
                catch (Exception ex)
                {
                    loggingService.LogError(ex.Message);

                    return(BadRequest("Oops, no pizza for you."));
                }
            }
        }
        public async Task PizzaOrderServiceOrderFakeTest()
        {
            // mock new Mock<ComplianceDbContext>();

            var loggingService = new FakeLoggingService();

            //db context requires a bit more effort to fake so let's abandon for now
            Assert.Inconclusive();

            using (var context = new MyPizzaDbContext())
            {
                var queueService        = new StoreQueueService();
                var paymentService      = new PaymentService();
                var notificationService = new OrderNotificationService();

                var service = new PizzaOrderService(
                    context,
                    paymentService,
                    queueService,
                    notificationService,
                    loggingService);
                var orderId = await service.OrderMenuItemAsync(1);

                Assert.IsTrue(orderId != 0);
            }
        }
        public async Task PizzaOrderServiceOrderTest()
        {
            // this is still an integration test
            // dependent on credit card service
            // dependent on database
            // dependent on SMTP server
            // dependent on RabbitMQ
            var loggingService = new LoggingService();

            using (var context = new MyPizzaDbContext())
            {
                var queueService        = new StoreQueueService();
                var paymentService      = new PaymentService();
                var notificationService = new OrderNotificationService();

                var service = new PizzaOrderService(
                    context,
                    paymentService,
                    queueService,
                    notificationService,
                    loggingService);
                var orderId = await service.OrderMenuItemAsync(1);

                Assert.IsTrue(orderId != 0);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            AutoMapperConfig.Initialize();

            while (true)
            {
                Console.WriteLine("Press 1 for cheese, 2 for pepperoni. x to exit");
                var result = Console.ReadLine();

                if (result == "x")
                {
                    return;
                }

                try
                {
                    // this is painful,
                    //  but we can swap out concrete implementation
                    var loggingService = new ConsoleLoggingService();

                    using (var context = new MyPizzaDbContext())
                    {
                        var queueService        = new StoreQueueService();
                        var paymentService      = new PaymentService();
                        var notificationService = new OrderNotificationService();

                        var service = new PizzaOrderService(
                            context,
                            paymentService,
                            queueService,
                            notificationService,
                            loggingService);

                        var task = service.OrderMenuItemAsync(int.Parse(result));
                        task.Wait();
                        var orderId = task.Result;
                        Console.WriteLine("Your order number is " + orderId);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
        public async Task PizzaOrderServiceOrderTest()
        {
            var loggingService = new LoggingService();

            using (var context = new MyPizzaDbContext())
            {
                var queueService        = new StoreQueueService();
                var paymentService      = new PaymentService();
                var notificationService = new OrderNotificationService();

                var service = new PizzaOrderService(
                    context,
                    paymentService,
                    queueService,
                    notificationService,
                    loggingService);
                var orderId = await service.OrderMenuItemAsync(1);

                Assert.IsTrue(orderId != 0);
            }
        }