示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }