Example #1
0
        public async Task Auth_Should_Not_Add_The_User_To_The_CurrentlyLoggedInUsersSingleton_If_Grant_Type_Is_refresh_token()
        {
            this.tokenServiceMock = new Mock <ITokenService>();
            this.tokenServiceMock.Setup(m => m.ReplaceUserRefreshToken(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new Token()
            {
                UserId = "user-id", Value = "token-value"
            }));

            this.Arrange_Configuration();

            this.configurationMock = new Mock <IConfiguration>();
            this.tokenController   = new TokenController(this.tokenServiceMock.Object, this.configuration);

            var model = this.CreateTokenRequestModelWithPasswordGrantType();

            model.grant_type = "refresh_token";

            IActionResult result = await this.tokenController.Auth(model);

            int keysCount = CurrentlyLoggedInUsersSingleton.GetAllUsernames().Count();

            this.Annihilate();

            Assert.Equal(0, keysCount);
        }
        public async Task <IActionResult> GetUsers()
        {
            var currentUser = await this.authManager.GetUserAsync(HttpContext.User);

            var allUsers = CurrentlyLoggedInUsersSingleton.GetAllUsernames()
                           .Where(v => string.Equals(v, currentUser.UserName, StringComparison.OrdinalIgnoreCase) == false)
                           .ToList();

            return(Json(allUsers, jsonSettings));
        }
Example #3
0
        private void Annihilate()
        {
            this.tokenServiceMock  = null;
            this.configurationMock = null;
            this.configuration     = null;
            this.tokenServiceMock  = null;

            var allUsernames = CurrentlyLoggedInUsersSingleton.GetAllUsernames();

            foreach (var username in allUsernames)
            {
                CurrentlyLoggedInUsersSingleton.RemoveEntryByKey(username);
            }
        }