public void DeleteTheOrders_ForTheIdsPassedIn()
        {
            var mockOrderRepository = MockRepository.GenerateMock<IOrderRepository>();
            var mockViewOrder = MockRepository.GenerateMock<IViewOrder>();
            mockViewOrder.Stub(x => x.ShouldSaveStudent).Return(false);
            var customerService = new CustomerService(mockOrderRepository, mockViewOrder);
            const int orderId1 = 1;
            const int orderId2 = 2;
            const int orderId3 = 3;

            int[] orderIds = {orderId1, orderId2, orderId3};

            var order1 = new Order {ID = orderId1, DatePurchased = new DateTime(2013, 1, 1), ItemDescription = "Chair1"};
            var order2 = new Order { ID = orderId2, DatePurchased = new DateTime(2013, 1, 1), ItemDescription = "Chair2" };
            var order3 = new Order { ID = orderId3, DatePurchased = new DateTime(2013, 1, 1), ItemDescription = "Chair3" };

            mockOrderRepository.Stub(x => x.FindById(orderId1)).Return(order1);
            mockOrderRepository.Stub(x => x.FindById(orderId2)).Return(order2);
            mockOrderRepository.Stub(x => x.FindById(orderId3)).Return(order3);

            customerService.DeleteTheOrder(orderIds);

            mockOrderRepository.AssertWasCalled(x => x.DeleteOrders(Arg<List<Order>>.List.ContainsAll(new List<Order>{order1,order2,order3})));
            mockOrderRepository.AssertWasCalled(x => x.DeleteOrders(Arg<List<Order>>.List.Equal(new List<Order>{order1,order2,order3})));
            mockOrderRepository.AssertWasCalled(x => x.DeleteOrders(new List<Order>{order1,order2,order3}));
            mockOrderRepository.AssertWasCalled(x => x.DeleteOrders(Arg<List<Order>>.List.Count(Rhino.Mocks.Constraints.Is.Equal(3))));
            mockOrderRepository.AssertWasCalled(x => x.DeleteOrders(Arg<List<Order>>.List.IsIn(order3)));
        }
        public void Should_RegisterTheOrderPlaced()
        {
            var customerService = new CustomerServiceDI();
            var order = new Order{DatePurchased = new DateTime(2014,1,1),ID = 1,ItemDescription = "Table"};

            customerService.RegisterNewOrder(order);

            var orderRepository = new OrderRepositoryDi();
            var orderRetreived = orderRepository.FindById(1);

            Assert.That(orderRetreived.ID,Is.EqualTo(order.ID));
        }
 public void RegisterNewOrder(int id, string itemName,DateTime datePurchased)
 {
     var order = new Order{DatePurchased = datePurchased,ID = id,ItemDescription = itemName};
     if (_viewOrder.ShouldSaveStudent)
     {
         _orderRepository.Save(order);
     }
     else
     {
         throw new ArgumentException("Invalid Order");
     }
 }
        public void Save(Order order)
        {
            //var sqlConnection = new SqlConnection(ConfigurationManager.AppSettings["Customer"]);
            var sqlConnection = GetConnectionString();
            using (sqlConnection)
            {
                sqlConnection.Open();
                var commandText = string.Format("Insert into dbo.tblOrder values({0},'{1}','{2}')", order.ID, order.ItemDescription,order.DatePurchased);

                var command = new SqlCommand(commandText) {CommandType = CommandType.Text,Connection= sqlConnection};
                command.ExecuteNonQuery();
            }
        }
        public void Should_PlaceaNewOrder()
        {
            var customerService = new CustomerServiceDI();
            var order = new Order {DatePurchased = new DateTime(2014, 1, 1), ID = 3, ItemDescription = @"bench"};

            customerService.RegisterNewOrder(order);

            //retreive it from database
            var orderRepositoryDi = new OrderRepositoryDi();
            var retreivedOrder = orderRepositoryDi.FindById(order.ID);

            Assert.AreEqual(order.ID, retreivedOrder.ID);
        }
        public Order FindById(int orderId)
        {
            var connectionString = GetConnectionString();
            var order = new Order();
            using (connectionString)
            {
                connectionString.Open();
                var sqlCommand = new SqlCommand(string.Format("select * from  dbo.tblOrder where id = {0} ", orderId))
                {
                    CommandType = CommandType.Text,
                    Connection = connectionString
                };
                var result = sqlCommand.ExecuteReader();

                if (!result.Read()) throw new Exception("Order not found");
                order.ID = (int) result["Id"];
                order.DatePurchased = (DateTime)result["DatePurchased"];
                order.ItemDescription = (string) result["ItemName"];
            }
            return order;
        }
 public bool Validate(Order order)
 {
     throw new NotImplementedException();
 }
 public void Save(Order order)
 {
     throw new System.NotImplementedException();
 }