Ejemplo n.º 1
0
        public void GetBasket_ReturnsBasket()
        {
            var expectedBasket = new Basket()
            {
                Id = Guid.NewGuid()
            };
            var dummyRequest = new RestRequest()
            {
                Method = Method.GET, Resource = "baskets"
            };
            var dummySettings = new BasketClientSettings()
            {
                BaseUrl = "https://api.co.uk"
            };
            var restClientMock = new Mock <IRestClient>();

            restClientMock.Setup(
                x => x.Execute <Basket>(dummyRequest))
            .Returns(new RestResponse <Basket> {
                Data = expectedBasket
            });
            var restRequestFactoryMock = new Mock <IRestRequestBuilder>();

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

            var actual = sut.GetBasket();

            Assert.Equal(expectedBasket.Id, actual.Id);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the basket.
        /// </summary>
        /// <param name="clientId">The client identifier.</param>
        /// <returns>Task&lt;List&lt;BasketResponse&gt;&gt;.</returns>
        public async Task <List <BasketRequest> > GetBasket(string clientId)
        {
            try
            {
                return(await bs.GetBasket(clientId, AuthorizationToken));
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Ejemplo n.º 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();
        }