コード例 #1
0
        public async void GetWidgetWillReturnNotFoundWhenNull()
        {
            _mockedRepository.Setup(x => x.GetAllAsync()).ReturnsAsync(() => null);
            var myController = new WidgetsController(_mockedRepository.Object);
            var actionResult = await myController.GetWidgets();

            Assert.NotNull(actionResult);
            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
コード例 #2
0
        public void GetWidgets_CorrectResponse()
        {
            var result = controller.GetWidgets() as ObjectResult;

            Assert.NotNull(result);

            var widgets = result.Value as Widget[];

            Assert.NotNull(widgets);
            Assert.Equal(3, widgets.Length);
        }
コード例 #3
0
        public async void GetWidgetsWillReturnOkResult()
        {
            _mockedRepository.Setup(repo => repo.GetAllAsync()).ReturnsAsync(_widgets);
            var actionResult = await _widgetsController.GetWidgets();

            var result = actionResult.Result as OkObjectResult;

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(_widgets, result.Value);
        }