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 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); } }
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); } }
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 void Setup() { _unitOfWork = A.Fake <IUnitOfWork>(); _userRepository = A.Fake <IAsyncRepository <User> >(); _notificationRepository = A.Fake <IAsyncReadonlyRepository <Notification> >(); _notificationSenderServiceFactory = A.Fake <INotificationSenderServiceFactory <Order> >(); _mailSender = A.Fake <INotificationSenderService <Order> >(); A.CallTo(() => _unitOfWork.GetRepository <IAsyncRepository <User> >()) .Returns(_userRepository); A.CallTo(() => _unitOfWork.GetRepository <IAsyncReadonlyRepository <Notification> >()) .Returns(_notificationRepository); A.CallTo(() => _notificationSenderServiceFactory.Create(NotificationMethod.Email)) .Returns(_mailSender); _orderNotificationService = new OrderNotificationService(_unitOfWork, _notificationSenderServiceFactory); }
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); } }