public async Task GetLists_ResponseType_IsOkObjectResult() { var adminList = new ShoppingList(); adminList.Owner = UserMocks.AdminUser; var userList = new ShoppingList(); userList.Owner = UserMocks.TestUser; var shoppingLists = new List <ShoppingList> { adminList, userList }; var shoppingListRepoMock = new Mock <IShoppingLists>(); shoppingListRepoMock.Setup(l => l.GetAllAsync()) .Returns(Task.FromResult(shoppingLists)); var currentUserRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser); var controller = new ShoppingListsController(shoppingListRepoMock.Object, currentUserRepoMock, null); var response = await controller.GetLists(); Assert.IsType <OkObjectResult>(response.Result); }
public async Task GetLists_UserIsAdmin_ReturnsAllLists() { var adminList = new ShoppingList(); adminList.Owner = UserMocks.AdminUser; var userList = new ShoppingList(); userList.Owner = UserMocks.TestUser; var shoppingLists = new List <ShoppingList> { adminList, userList }; var shoppingListRepoMock = new Mock <IShoppingLists>(); shoppingListRepoMock.Setup(l => l.GetAllAsync()) .Returns(Task.FromResult(shoppingLists)); var currentUserRepoMock = UserMocks.GetMockUserProvider(UserMocks.AdminUser); var controller = new ShoppingListsController(shoppingListRepoMock.Object, currentUserRepoMock, null); var response = await controller.GetLists(); var result = response.Result as OkObjectResult; var resultValue = result.Value as ShoppingListResult; Assert.Equal(2, resultValue.ResultData.Count); }
public async Task GetLists_UserIsNotAdmin_ReturnsListsBelongingToUser() { string userListName = "UserList"; var adminList = new ShoppingList(); adminList.Owner = UserMocks.AdminUser; adminList.Name = "AdminList"; var userList = new ShoppingList(); userList.Owner = UserMocks.TestUser; userList.Name = userListName; var shoppingLists = new List <ShoppingList> { adminList, userList }; var shoppingListRepoMock = new Mock <IShoppingLists>(); shoppingListRepoMock.Setup(l => l.GetAllAsync()) .Returns(Task.FromResult(shoppingLists)); shoppingListRepoMock.Setup(l => l.GetAllOfUserAsync(UserMocks.TestUser.Id)) .Returns(Task.FromResult(new List <ShoppingList> { userList })); var currentUserRepoMock = UserMocks.GetMockUserProvider(UserMocks.TestUser); var controller = new ShoppingListsController(shoppingListRepoMock.Object, currentUserRepoMock, null); var response = await controller.GetLists(); var result = response.Result as OkObjectResult; var resultValue = result.Value as ShoppingListResult; Assert.Single(resultValue.ResultData); Assert.Equal(userListName, resultValue.ResultData.First().Name); }