public async Task GetList_UserIsNotAdminInList_ReturnsList() { var testListName = "TestList"; var testListId = "abc-de"; var testList = new ShoppingList { Id = testListId, Name = testListName }; var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.TestUser); var listRepoMock = new Mock <IShoppingLists>(); listRepoMock.Setup(l => l.GetAsync(testListId)) .Returns(Task.FromResult(testList)); listRepoMock.Setup(l => l.IsOfUserAsync(testList.Id, UserMocks.TestUser.Id)) .Returns(Task.FromResult(true)); var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null); var response = await controller.GetList(testListId); var resultObject = response.Result as OkObjectResult; var list = resultObject.Value as ShoppingListResult; Assert.Equal(testListName, list.ResultData[0].Name); }
public async Task GetList_UserIsNotAdminAndNotUserOfList_ReturnsUnauthorizedResult() { var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.TestUser); var listRepoMock = new Mock <IShoppingLists>(); listRepoMock.Setup(l => l.GetAsync(It.IsAny <string>())).Returns(Task.FromResult(new ShoppingList())); var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null); var response = await controller.GetList(""); Assert.IsType <UnauthorizedObjectResult>(response.Result); }
public async Task GetList_SearchForNonExistingList_ReturnsNotFoundResult() { var testListId = "abc-def"; var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser); var listRepoMock = new Mock <IShoppingLists>(); listRepoMock.Setup(l => l.GetAsync(testListId)) .Throws(new ItemNotFoundException()); var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null); var response = await controller.GetList(testListId); Assert.IsType <NotFoundObjectResult>(response.Result); }
public async Task GetList_UserIsAdminNotInList_ReturnsList() { var testListName = "TestList"; var userRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser); var listRepoMock = new Mock <IShoppingLists>(); listRepoMock.Setup(l => l.GetAsync(It.IsAny <string>())) .Returns(Task.FromResult(new ShoppingList() { Name = testListName })); var controller = new ShoppingListsController(listRepoMock.Object, userRepoMock, null); var response = await controller.GetList(""); var resultObject = response.Result as OkObjectResult; var list = resultObject.Value as ShoppingListResult; Assert.Equal(testListName, list.ResultData[0].Name); }