예제 #1
0
        public async Task <bool> AddItem(BasketRequest request)
        {
            try
            {
                IAsyncResult result = await bs.AddItem(request, AuthorizationToken);

                return(true);
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
예제 #2
0
        public void AddItem_AddsItemToBasket()
        {
            var expectedItem = new Item {
                code = "Arduino", quantity = 42
            };
            var expectedRequest = new RestRequest()
            {
                Method = Method.PUT
            };
            var dummySettings = new BasketClientSettings()
            {
                BaseUrl = "https://api.co.uk"
            };
            var restClientMock         = new Mock <IRestClient>();
            var restRequestFactoryMock = new Mock <IRestRequestBuilder>();

            restRequestFactoryMock.Setup(x => x.Build()).Returns(expectedRequest);
            var sut = new BasketClient(dummySettings, restClientMock.Object, restRequestFactoryMock.Object);

            sut.AddItem(expectedItem);

            restRequestFactoryMock.Verify(x => x.AddBody(expectedItem));
            restClientMock.Verify(x => x.Execute(expectedRequest));
        }
예제 #3
0
        static void Main(string[] args)
        {
            bool returnStatus = false;

            Console.WriteLine("Program started for client C123");

            BasketClient basketClient = new BasketClient("C123");

            Console.WriteLine("Acquired new Basket ID: " + basketClient.BasketId);

            Console.WriteLine("Add item 1 with discount: ");
            returnStatus = basketClient.AddItem("111", "Car", "BMW", "Series 3", "Very cool", (float)5.50, 1, (float)2.50);
            Console.WriteLine("Return status for item 1: " + returnStatus);

            Console.WriteLine("Add item 2: ");
            returnStatus = basketClient.AddItem("112", "Bike", "Kawasaki", "Series 1", "Very cool", (float)3.50, 1, 0);
            Console.WriteLine("Return status for item 2: " + returnStatus);

            Console.WriteLine("Add item 3: ");
            returnStatus = basketClient.AddItem("113", "Boat", "Mercedes", "Series 2", "Very cool", (float)2.50, 1, 0);
            Console.WriteLine("Return status for item 3: " + returnStatus);

            Console.WriteLine("Retrieve basket after adding 3 items: ");
            string basketObject = basketClient.GetBasket();

            Console.WriteLine("Basket: " + basketObject);

            Console.WriteLine("Update quantity of item 2: ");
            returnStatus = basketClient.UpdateItem("112", 2);
            Console.WriteLine("Return status for item 2: " + returnStatus);

            Console.WriteLine("Retrieve basket after updating item 2: ");
            basketObject = basketClient.GetBasket();
            Console.WriteLine("Basket: " + basketObject);

            Console.WriteLine("Remove item 3: ");
            returnStatus = basketClient.RemoveItem("113");
            Console.WriteLine("Return status for item 3: " + returnStatus);

            Console.WriteLine("Retrieve basket after removing item 3: ");
            basketObject = basketClient.GetBasket();
            Console.WriteLine("Basket: " + basketObject);

            Console.WriteLine("Produce an order: ");
            string orderObject = basketClient.ProduceOrder("CUST123", "Jon Doe", "5th Street Somewhere", "07777777777", (float)20.00, (float)1.50);

            Console.WriteLine("Basket: " + orderObject);

            Console.WriteLine("Clear basket: ");
            returnStatus = basketClient.ClearBasket();
            Console.WriteLine("Return status for clear basket: " + returnStatus);

            Console.WriteLine("Retrieve basket clearing items: ");
            basketObject = basketClient.GetBasket();
            Console.WriteLine("Basket: " + basketObject);

            Console.WriteLine("Delete basket: ");
            returnStatus = basketClient.DeleteBasket();
            Console.WriteLine("Return status for delete basket: " + returnStatus);

            Console.WriteLine("Get basket after delete: ");
            basketObject = basketClient.GetBasket();
            Console.WriteLine("Basket: " + basketObject);

            Console.ReadLine();
        }