示例#1
0
        public async Task UpdateList_UpdateList_ReturnsOkObjectResultWithList()
        {
            var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser);

            var testList = new ShoppingList()
            {
                Id = "123"
            };

            var listRepoMock = new Mock <IShoppingLists>();

            listRepoMock.Setup(l => l.IsOfUserAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(true));
            listRepoMock.Setup(l => l.UpdateAsync(testList.Id, testList))
            .Returns(Task.FromResult(testList));

            var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null);
            var response   = await controller.UpdateList(testList.Id, testList);

            Assert.IsType <OkObjectResult>(response.Result);

            var result = response.Result as OkObjectResult;
            var list   = result.Value as ShoppingListResult;

            Assert.Equal(testList.Id, list.ResultData[0].Id);
        }
示例#2
0
        public async Task UpdateList_IdsDoNotMatch_ReturnsBadRequestResult()
        {
            var controller = new ShoppingListsController(null, null, null);
            var response   = await controller.UpdateList("123", new ShoppingList()
            {
                Id = "abc"
            });

            Assert.IsType <BadRequestObjectResult>(response.Result);
        }
示例#3
0
        public async Task UpdateList_UpdateThrowsPersistencyException_ReturnsConflictResult()
        {
            var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser);

            var listRepoMock = new Mock <IShoppingLists>();

            listRepoMock.Setup(l => l.IsOfUserAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(true));
            listRepoMock.Setup(l => l.UpdateAsync(It.IsAny <string>(), It.IsAny <ShoppingList>()))
            .Throws(new PersistencyException());

            var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null);
            var response   = await controller.UpdateList("123", new ShoppingList()
            {
                Id = "123"
            });

            Assert.IsType <ConflictObjectResult>(response.Result);
        }