Exemplo n.º 1
0
        public void CreateBasket_CallsApi()
        {
            var expectedBasket  = new Basket();
            var expectedRequest = new RestRequest()
            {
                Method = Method.POST, Resource = "baskets"
            };
            var dummySettings = new BasketClientSettings()
            {
                BaseUrl = "https://api.co.uk"
            };
            var restClientMock = new Mock <IRestClient>();

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

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

            sut.CreateBasket();

            restClientMock.VerifyAll();
        }
Exemplo n.º 2
0
        public void CreateBasket_CreatesBasket()
        {
            var expectedBasket = new Basket()
            {
                Id = Guid.NewGuid()
            };
            var dummyRequest = new RestRequest()
            {
                Method = Method.POST, 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);

            sut.CreateBasket();

            Assert.Equal(expectedBasket.Id, sut.BasketId);
        }