コード例 #1
0
        public void Get_WhenCalled_ReturnOkResult()
        {
            //Act
            var items = _controller.Get();

            //Assert
            Assert.IsType <OkObjectResult>(items.Result);
        }
コード例 #2
0
        public void Get_WhenCalled_ReturnsOkResult()
        {
            // Act
            var okResult = _controller.Get();

            // Assert
            Assert.That(okResult.Result, Is.TypeOf <OkObjectResult>());
        }
コード例 #3
0
        public void Get_WhenCalled_ReturnsOkResult()
        {
            // Act
            var okResult = _controller.Get();

            // Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }
コード例 #4
0
        public void UnknownGuidPassed_ReturnsNotFoundResult()
        {
            // Act
            var notFoundResult = _controller.Get(Guid.NewGuid());

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
コード例 #5
0
        public void GetSuccess()
        {
            _shoppingCartService.Setup(s => s.GetActiveShoppingCart(It.IsAny <long>())).Returns(It.IsAny <ShoppingCart>());
            var result = _controller.Get(1);

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result.Result);

            var httpObjResult = result.Result as OkObjectResult;

            Assert.NotNull(httpObjResult);
            Assert.True(httpObjResult.StatusCode == 200);
        }
コード例 #6
0
        public void Get_WhenCalled_ReturnsOkResult()
        {
            var cartID          = "9b3df90a-1007-4778-b614-91df990e0c95";
            var mockHttpContext = MockHttpSession.setSessionKey(cartID);

            _controller.ControllerContext.HttpContext = mockHttpContext.Object;

            // Act
            var okResult = _controller.Get();


            // Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }
コード例 #7
0
        public async Task AddExistingItemWithAttributes()
        {
            await _cartStorage.Store(new List <ShoppingCartItem>
            {
                new ShoppingCartItem(2, "foo"),
                new ShoppingCartItem(3, "foo", _attrSet1Parsed),
                new ShoppingCartItem(4, "foo", _attrSet2Parsed),
                new ShoppingCartItem(5, "foo", _attrSet3Parsed),
                new ShoppingCartItem(6, "bar", _attrSet3Parsed)
            });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 7, ProductSku = "foo" });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 8, ProductSku = "foo", Attributes = _attrSet1 });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 9, ProductSku = "foo", Attributes = _attrSet2 });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 10, ProductSku = "foo", Attributes = _attrSet3 });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 11, ProductSku = "bar", Attributes = _attrSet3 });

            await _controller.AddItem(new ShoppingCartLineUpdateModel { Quantity = 13, ProductSku = "baz", Attributes = _attrSet3 });

            var cart = await _controller.Get();

            Assert.Equal(new List <ShoppingCartItem>
            {
                new ShoppingCartItem(9, "foo"),
                new ShoppingCartItem(11, "foo", _attrSet1Parsed),
                new ShoppingCartItem(13, "foo", _attrSet2Parsed),
                new ShoppingCartItem(15, "foo", _attrSet3Parsed),
                new ShoppingCartItem(17, "bar", _attrSet3Parsed),
                new ShoppingCartItem(13, "baz", _attrSet3Parsed)
            }, cart);
        }
コード例 #8
0
        public void GetTest()
        {
            var shoppingCartRepository = new Mock <IShoppingCartRepository>();

            shoppingCartRepository.Setup(s => s.GetCurrentShoppingCart()).Returns(new ShoppingCart()
            {
                ShoppingCartDevelopers = new System.Collections.Generic.List <ShoppingCartDeveloper>()
            });

            ShoppingCartController controller = CreateController(shoppingCartRepository);

            var restult = controller.Get();

            Assert.IsNotNull(restult);
            Assert.IsInstanceOfType(restult, typeof(ShoppingCart));
        }
コード例 #9
0
        public void GetReturnsCorretctStatusCode()
        {
            //Fixture Setup
            var shoppingCart = new Mock <IShoppingCart>();
            var sut          = new ShoppingCartController(shoppingCart.Object)
            {
                Request = new HttpRequestMessage()
            };

            sut.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            //Exercise system
            var actual = sut.Get();

            //Verify Outcome
            Assert.True(actual.IsSuccessStatusCode);
            //Teardown
        }
        public void Get_GetsShoppingCartForUser()
        {
            var shoppingCart = new ShoppingCart(new ObservableCollection <ShoppingCartItem>())
            {
                FullPrice = 200, TotalDiscount = 100
            };
            var shoppingCartRepository = new MockShoppingCartRepository();

            shoppingCartRepository.GetByIdDelegate = (userId) =>
            {
                return(shoppingCart);
            };

            var target = new ShoppingCartController(shoppingCartRepository, new MockProductRepository());
            var result = target.Get("JohnDoe");

            Assert.AreEqual(result, shoppingCart);
        }
コード例 #11
0
        public async Task GetCartTest()
        {
            var shoppingCart = new ShoppingCart(124, Array.Empty<ShoppingCartItem>());
            _shoppingCartStore.Setup(t => t.Get(124)).Returns(Task.FromResult(shoppingCart));

            var request = new Mock<HttpRequest>();
            // request.Setup(x => x.Scheme).Returns("http");
            // request.Setup(x => x.Host).Returns(HostString.FromUriComponent("http://localhost:8080"));
            // request.Setup(x => x.PathBase).Returns(PathString.FromUriComponent("/api"));
            var httpContext = Mock.Of<HttpContext>(_ => _.Request == request.Object);
            var controllerContext = new ControllerContext { HttpContext = httpContext };
            var controller = new ShoppingCartController(_logger.Object, _shoppingCartStore.Object, _productCatalog.Object, _eventStore.Object)
            {
                ControllerContext = controllerContext,
            };

            var result = await controller.Get(124);
            Assert.AreSame(shoppingCart, result.Value);
        }
コード例 #12
0
        public void Get_WhenCalled_returnsOk()
        {
            var okResult = _controller.Get();

            Assert.IsType <OkObjectResult>(okResult.Result);
        }