コード例 #1
0
        public void Room_Post_Should_Return_Ok_Response_If()
        {
            var testRoom = new RoomPostViewModel()
            {
                Id               = 7,
                Name             = "testName",
                Number           = "2",
                Coordinates      = "111,222,333",
                FloorId          = 1,
                ApplicationUsers = new List <ApplicationUserViewModel>
                {
                    new ApplicationUserViewModel
                    {
                        Id = "1"
                    }
                }
            };

            var userToReturn = _unitOfWork.GetDbContextAs <MockDbContext>().ApplicationUsers.Find(p => p.Id == "1");

            _userManager.FindByIdAsync("1").Returns(Task.FromResult(userToReturn));

            _roomController.Request = new HttpRequestMessage();
            _roomController.Request.SetConfiguration(new HttpConfiguration());
            _roomController.Validate(testRoom);

            var response = _roomController.Post(testRoom);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #2
0
        private async Task <LoggedInUserInfoViewModel> GetLoggedInUserInfoAsync()
        {
            var userId         = User.Identity.GetUserId();
            var organizationId = User.Identity.GetOrganizationId();
            var claimsIdentity = User.Identity as ClaimsIdentity;

            var user = await _userManager.FindByIdAsync(userId);

            var permissions = await _permissionService.GetUserPermissionsAsync(userId, organizationId);

            var userInfo = new LoggedInUserInfoViewModel
            {
                HasRegistered    = true,
                Roles            = await _userManager.GetRolesAsync(userId),
                UserName         = User.Identity.Name,
                UserId           = userId,
                OrganizationName = claimsIdentity.FindFirstValue(WebApiConstants.ClaimOrganizationName),
                OrganizationId   = claimsIdentity.FindFirstValue(WebApiConstants.ClaimOrganizationId),
                FullName         = claimsIdentity.FindFirstValue(ClaimTypes.GivenName),
                Permissions      = permissions,
                Impersonated     = claimsIdentity?.Claims.Any(c => c.Type == WebApiConstants.ClaimUserImpersonation && c.Value == true.ToString()) ?? false,
                CultureCode      = user.CultureCode,
                TimeZone         = user.TimeZone,
                PictureId        = user.PictureId
            };

            return(userInfo);
        }
コード例 #3
0
ファイル: UserServiceTests.cs プロジェクト: Agnius101/simoona
        public void Should_Delete_User()
        {
            // Arrange
            var users = new List <ApplicationUser>
            {
                new ApplicationUser {
                    OrganizationId = 2, Id = "userToDelete", RemainingKudos = 100, SpentKudos = 100, TotalKudos = 100
                },
                new ApplicationUser {
                    OrganizationId = 2, Id = "otherUser", RemainingKudos = 100, SpentKudos = 100, TotalKudos = 100
                }
            };

            var userWalls = new List <WallMember>
            {
                new WallMember {
                    WallId = 1, UserId = "userToDelete", Wall = new Wall {
                        OrganizationId = 2
                    }
                },
                new WallMember {
                    WallId = 2, UserId = "userToDelete", Wall = new Wall {
                        OrganizationId = 2
                    }
                },
                new WallMember {
                    WallId = 3, UserId = "userToDelete2", Wall = new Wall {
                        OrganizationId = 2
                    }
                }
            };

            var moderators = new List <WallModerator>
            {
                new WallModerator {
                    Id = 1, WallId = 1, UserId = "userToDelete", Wall = new Wall {
                        OrganizationId = 2
                    }
                }
            };

            var taskSource = new TaskCompletionSource <ApplicationUser>();

            taskSource.SetResult(users.First());
            _userManager.FindByIdAsync("userToDelete").Returns(taskSource.Task);
            _usersDbSet.SetDbSetData(users);
            _wallUsersDbSet.SetDbSetData(userWalls);
            _wallModeratorsDbSet.SetDbSetData(moderators);

            var userOrg = new UserAndOrganizationDTO
            {
                UserId         = "admin",
                OrganizationId = 2
            };

            // Act
            _userService.Delete("userToDelete", userOrg);

            var deletedUser = _usersDbSet.First(x => x.Id == "userToDelete");

            // Assert
            Assert.AreEqual(deletedUser.RemainingKudos, 0);
            Assert.AreEqual(deletedUser.SpentKudos, 0);
            Assert.AreEqual(deletedUser.TotalKudos, 0);
            _usersDbSet.Received(1).Remove(Arg.Any <ApplicationUser>());
            _wallModeratorsDbSet.Received(1).Remove(Arg.Is <WallModerator>(m => m.UserId == "userToDelete"));
            _wallUsersDbSet.Received(2).Remove(Arg.Is <WallMember>(m => m.UserId == "userToDelete"));
        }
コード例 #4
0
ファイル: UserService.cs プロジェクト: VismaLietuva/simoona
 public async Task <IList <IdentityUserLogin> > GetUserLoginsAsync(string id)
 {
     return((await _userManager.FindByIdAsync(id)).Logins.ToList());
 }