コード例 #1
0
        public void Test_ReturnOk_WhenAddressFound()
        {
            var   _logger = Mock.Of <ILogger <AddressController> >();
            Datas datas   = new Datas();

            _userRepository.Setup(r => r.GetAddressesByUser("vThushy")).Returns(datas.SetListOfAddressForTest);
            _controller = new AddressController(_logger, _userRepository.Object);

            IActionResult result = _controller.GetAllAddressByCustomer("vThushy");

            Assert.IsType <OkObjectResult>(result);
        }
コード例 #2
0
        public void Test_Return0Address_WhenAddressNotFound()
        {
            var            _logger      = Mock.Of <ILogger <AddressController> >();
            List <Address> emptyAddress = new List <Address>();

            _userRepository.Setup(r => r.GetAddressesByUser("vThushy")).Returns(emptyAddress);
            _controller = new AddressController(_logger, _userRepository.Object);

            IActionResult  result         = _controller.GetAllAddressByCustomer("vThushy");
            OkObjectResult okObjectResult = result as OkObjectResult;
            List <Address> resturnResult  = okObjectResult.Value as List <Address>;

            Assert.Empty(resturnResult);
        }
コード例 #3
0
        public void Test_ReturnAddresses_WhenAddressFound()
        {
            var   _logger = Mock.Of <ILogger <AddressController> >();
            Datas datas   = new Datas();

            _userRepository.Setup(r => r.GetAddressesByUser("vThushy")).Returns(datas.SetListOfAddressForTest);
            _controller = new AddressController(_logger, _userRepository.Object);

            IActionResult  result         = _controller.GetAllAddressByCustomer("vThushy");
            OkObjectResult okObjectResult = result as OkObjectResult;
            List <Address> resturnResult  = okObjectResult.Value as List <Address>;

            Assert.Equal(2, resturnResult.Count);
        }