Exemple #1
0
        public List <Product> GetProducts(int customerId, int orderId)
        {
            OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteria
            {
                OrderId = customerId // THIS IS THE PROBLEM WE ARE GOING TO SEARCH FOR

                                     // Set some other search criteria...
            };

            Order retrievedOrder = m_orderRepository.GetOrder(orderSearchCriteria);

            // Do something else
            return(retrievedOrder.Products);
        }
        public void GetProducts_Creates_OrderSearchCriteria_Correctly()
        {
            const int customerId = 56789;
            const int orderId    = 12345;

            OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteria
            {
                OrderId = orderId
            };

            Mock <IOrderRepository> orderRepositoryMock = new Mock <IOrderRepository>();

            orderRepositoryMock
            .Setup(m => m.GetOrder(orderSearchCriteria))
            .Returns(new Order());

            ProductService sut = new ProductService(orderRepositoryMock.Object);

            List <Product> result = sut.GetProducts(customerId, orderId);
        }
        public void GetProducts_Creates_OrderSearchCriteria_Correctly_2_Lamda()
        {
            const int customerId = 56789;
            const int orderId    = 12345;

            OrderSearchCriteria recievedOrderSearchCriteria = null;

            Mock <IOrderRepository> orderRepositoryMock = new Mock <IOrderRepository>();

            orderRepositoryMock
            .Setup(m => m.GetOrder(It.IsAny <OrderSearchCriteria>()))
            .Returns(new Order())
            .Callback((OrderSearchCriteria o) => recievedOrderSearchCriteria = o);

            ProductService sut = new ProductService(orderRepositoryMock.Object);

            List <Product> result = sut.GetProducts(customerId, orderId);

            Assert.IsNotNull(recievedOrderSearchCriteria);
            Assert.AreEqual(orderId, recievedOrderSearchCriteria.OrderId);
        }