コード例 #1
0
        public async void ShouldReturnAnOkResultWhenTheUpdateIsSuccessful()
        {
            var updatedShoppingList = new ShoppingList
            {
                ShoppingListId = 1,
                Name           = "Test",
                CreatedAt      = DateTime.Now,
                LastUpdated    = DateTime.Now
            };

            var mockRepository = new Mock <IRepository <ShoppingList> >();

            _service    = new ShoppingListService(mockRepository.Object);
            _controller = new ShoppingListController(_service);


            IActionResult result = await _controller.UpdateShoppingList(updatedShoppingList);


            result.Should().BeOfType <ObjectResult>()
            .Which.Value.Should().BeAssignableTo <IApiResponse>()
            .Which.Should().Match <IApiResponse>(response =>
                                                 response.StatusCode == HttpStatusCode.OK &&
                                                 response.Message == null &&
                                                 response.Result == null);
        }
コード例 #2
0
        public async void ShouldReturnABadRequestWhenTheUpdatedShoppingListIsNull()
        {
            _service    = Mock.Of <IShoppingListService <IApiResponse> >();
            _controller = new ShoppingListController(_service);


            IActionResult result = await _controller.UpdateShoppingList(null);


            result.Should().BeOfType <ObjectResult>()
            .Which.Value.Should().BeAssignableTo <IApiResponse>()
            .Which.Should().Match <IApiResponse>(response =>
                                                 response.StatusCode == HttpStatusCode.BadRequest &&
                                                 response.Result == null &&
                                                 response.Message.Equals("Cannot update an invalid shopping list."));
        }
コード例 #3
0
        public async void ShouldCallTheRepositoryOnceWhenUpdatingAShoppingList()
        {
            var updatedShoppingList = new ShoppingList
            {
                ShoppingListId = 1,
                Name           = "Test",
                CreatedAt      = DateTime.Now,
                LastUpdated    = DateTime.Now
            };

            var mockRepository = new Mock <IRepository <ShoppingList> >();

            _service    = new ShoppingListService(mockRepository.Object);
            _controller = new ShoppingListController(_service);


            await _controller.UpdateShoppingList(updatedShoppingList);


            mockRepository.Verify(mock => mock.UpdateAsync(updatedShoppingList), Times.Once);
        }