Ejemplo n.º 1
0
        public void TestCanViewUser()
        {
            var users        = FakeUsers.Get().AsQueryable();
            var visibleUsers = users.CanViewUsers(FakeUsers.GetPublic().AsModel());

            visibleUsers.Should().HaveCount(2);
        }
Ejemplo n.º 2
0
        public void TestCannotViewPrivateUser()
        {
            var users        = FakeUsers.Get().AsQueryable().Where(u => u.ProfileVisibility == Visibility.Hidden);
            var visibleUsers = users.CanViewUsers(FakeUsers.GetPublic().AsModel());

            visibleUsers.Should().HaveCount(0);
        }
Ejemplo n.º 3
0
        public static Mock <IUserService> GetStandardMockUserService(IEnumerable <User> result = null)
        {
            if (result == null)
            {
                result = FakeUsers.Get().Select(u => u.AsModel());
            }

            var mockUserService = new Mock <IUserService>();

            mockUserService.Setup(u => u.GetIdentifyingUser(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId));

            mockUserService.Setup(u => u.GetUserAsync(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId));

            mockUserService.Setup(u => u.GetUserByNameAsync(It.IsAny <string>(), It.IsAny <User>()))
            .ReturnsAsync((string name) => result.FirstOrDefault(u => u.DisplayName == name));

            mockUserService.Setup(u => u.GetUserIdAsync(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId).Id);

            mockUserService.Setup(u => u.GetRandomNameAsync())
            .ReturnsAsync("ElatedScurfpea");

            mockUserService.Setup(u => u.AddUserAsync(It.IsAny <User>()))
            .ReturnsAsync((User user) => user);

            mockUserService.Setup(u => u.UpdateUserAsync(It.IsAny <User>()))
            .ReturnsAsync((User user) => user);

            return(mockUserService);
        }