public ActionResult LogOn() { if (this.Request.IsAuthenticated) { // Ensure user profile var userId = this.GetClaimValue(ClaimTypes.NameIdentifier); var userProfile = this.userRepository.GetUser(userId); if (userProfile == null) { var loginType = this.GetClaimValue(ConfigurationConstants.IdentityProviderClaimType); userProfile = new UserProfile { Id = userId, DisplayName = Thread.CurrentPrincipal.Identity.Name ?? string.Empty, LoginType = loginType, AssociatedUserAccount = loginType.StartsWith("Facebook", StringComparison.OrdinalIgnoreCase) ? this.GetClaimValue(ConfigurationConstants.FacebookAccessTokenClaimType) : string.Empty }; this.userRepository.AddOrUpdateUser(userProfile); } var effectiveReturnUrl = this.GetContextFromRequest(); if (!string.IsNullOrWhiteSpace(effectiveReturnUrl)) { return Redirect(effectiveReturnUrl); } } return Redirect("~/"); }
public void TestJoningAndLeavingGameQueues() { FixedTimeProvider timeProvider = new FixedTimeProvider(); TimeProvider.Current = timeProvider; DateTime startingDateTime = DateTime.Parse("01/01/2001 00:00:00"); timeProvider.CurrentDateTime = startingDateTime; CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount; IGameRepository gameRepository = new GameRepository(null, null, null, null, null, null); UserProfile firstUser = new UserProfile() { Id = Guid.NewGuid().ToString(), DisplayName = "John" }; UserProfile secondUser = new UserProfile() { Id = Guid.NewGuid().ToString(), DisplayName = "Peter" }; var users = new AzureBlobContainer<UserProfile>(CloudStorageAccount.DevelopmentStorageAccount); var sessions = new AzureBlobContainer<UserSession>(CloudStorageAccount.DevelopmentStorageAccount); var friends = new AzureBlobContainer<Friends>(CloudStorageAccount.DevelopmentStorageAccount); var userRepository = new UserRepository(users, sessions, friends); userRepository.AddOrUpdateUser(firstUser); userRepository.AddOrUpdateUser(secondUser); gameRepository.AddUserToSkirmishGameQueue(firstUser); GameQueue gameQueue = null; //// gameQueue = MagicallyGetGameQueues(); Assert.AreEqual(gameQueue, new Game { CreationTime = startingDateTime, Id = gameQueue.Id, Users = new List<GameUser> { new GameUser { UserId = firstUser.Id } } }); Assert.AreEqual(gameQueue.TimeElapsed(), 60); timeProvider.CurrentDateTime = startingDateTime.AddSeconds(10); Assert.AreEqual(gameQueue.TimeElapsed(), 50); gameRepository.AddUserToSkirmishGameQueue(secondUser); //// gameQueue = MagicallyGetGameQueues(); Assert.AreEqual(gameQueue, new Game { CreationTime = startingDateTime, Id = gameQueue.Id, Users = new List<GameUser> { new GameUser { UserId = firstUser.Id }, new GameUser { UserId = secondUser.Id } } }); Assert.AreEqual(gameQueue.TimeElapsed(), 50); timeProvider.CurrentDateTime = startingDateTime.AddSeconds(20); Assert.AreEqual(gameQueue, new Game { CreationTime = startingDateTime, Id = gameQueue.Id, Users = new List<GameUser> { new GameUser { UserId = firstUser.Id }, new GameUser { UserId = secondUser.Id } } }); Assert.AreEqual(gameQueue.TimeElapsed(), 40); // gameRepository.RemoveUserFromGameQueue(firstUser, gameQueue, "Bored"); // gameQueue = MagicallyGetGameQueues(); Assert.AreEqual(gameQueue, new Game { CreationTime = startingDateTime, Id = gameQueue.Id, Users = new List<GameUser> { new GameUser { UserId = secondUser.Id } } }); Assert.AreEqual(gameQueue.TimeElapsed(), 40); timeProvider.CurrentDateTime = startingDateTime.AddSeconds(30); Assert.AreEqual(gameQueue.TimeElapsed(), 30); // gameRepository.RemoveUserFromGameQueue(secondUser, gameQueue, "Also Bored"); // gameQueue = MagicallyGetGameQueues(); Assert.AreEqual(gameQueue, new Game { CreationTime = startingDateTime, Id = gameQueue.Id, Users = new List<GameUser>() }); }
public void AddOrUpdateUser(UserProfile user) { if (user == null) { throw new ArgumentNullException("user"); } if (user.Id == string.Empty) { throw new ArgumentException("User Id cannot be empty"); } this.userContainer.Save(user.Id.ToString(), user); }
public void AddOrUpdateUserTest() { var users = new AzureBlobContainer<UserProfile>(CloudStorageAccount.DevelopmentStorageAccount); var sessions = new AzureBlobContainer<UserSession>(CloudStorageAccount.DevelopmentStorageAccount); var friends = new AzureBlobContainer<Friends>(CloudStorageAccount.DevelopmentStorageAccount); var target = new UserRepository(users, sessions, friends); string userID = Guid.NewGuid().ToString(); UserProfile userFirstVersion = new UserProfile() { Id = userID, DisplayName = "John" }; target.AddOrUpdateUser(userFirstVersion); Assert.AreEqual(userFirstVersion, target.GetUser(userID)); UserProfile otherUser = new UserProfile() { Id = Guid.NewGuid().ToString(), DisplayName = "Peter" }; target.AddOrUpdateUser(otherUser); Assert.AreEqual(otherUser, target.GetUser(otherUser.Id)); UserProfile userSecondVersion = new UserProfile() { Id = userID, DisplayName = "Johny" }; Assert.AreEqual(userSecondVersion, target.GetUser(userID)); }
public void GetUserReferenceTimeOutTest() { var users = new AzureBlobContainer<UserProfile>(CloudStorageAccount.DevelopmentStorageAccount); var sessions = new AzureBlobContainer<UserSession>(CloudStorageAccount.DevelopmentStorageAccount); var friends = new AzureBlobContainer<Friends>(CloudStorageAccount.DevelopmentStorageAccount); var target = new UserRepository(users, sessions, friends); string userID = Guid.NewGuid().ToString(); UserProfile userFirstVersion = new UserProfile() { Id = userID, DisplayName = "John" }; target.AddOrUpdateUser(userFirstVersion); TimeSpan timeSpan = TimeSpan.FromSeconds(1); string address = target.GetUserReference(userID, timeSpan); System.Threading.Thread.Sleep(timeSpan.Add(TimeSpan.FromSeconds(1))); System.Net.WebClient webClient = new System.Net.WebClient(); string data = webClient.DownloadString(address); }
public void GetUserReferenceTest() { var users = new AzureBlobContainer<UserProfile>(CloudStorageAccount.DevelopmentStorageAccount); var sessions = new AzureBlobContainer<UserSession>(CloudStorageAccount.DevelopmentStorageAccount); var friends = new AzureBlobContainer<Friends>(CloudStorageAccount.DevelopmentStorageAccount); var target = new UserRepository(users, sessions, friends); var userID = Guid.NewGuid().ToString(); var userFirstVersion = new UserProfile() { Id = userID, DisplayName = "John" }; target.AddOrUpdateUser(userFirstVersion); string address = target.GetUserReference(userID, TimeSpan.FromSeconds(10)); var webClient = new WebClient(); string data = webClient.DownloadString(address); var serialized = this.Serialized(userFirstVersion, true); Assert.AreEqual("sgusers" + serialized, data); }
public static void AddUserToSkirmishGameQueue(this IGameRepository gameRepository, UserProfile userProfile) { gameRepository.AddUserToGameQueue(userProfile.Id, GameType.Skirmish); }
public void UpdateUserProfileDoesNotChangeIfDisplayNameParameterIsMissing() { var userId = Guid.NewGuid().ToString(); var userName = "******"; var userRepository = this.CreateUserRepository(); var statisticsProvider = this.CreateStatisticsRepository(); var userService = this.CreateUserService(userRepository, statisticsProvider, userId); var user = new UserProfile { Id = userId, DisplayName = userName }; userRepository.AddOrUpdateUser(user); var request = new HttpRequestMessage(); request.Content = new StringContent(string.Empty); request.Content.Headers.ContentType.MediaType = "application/x-www-form-urlencoded"; userService.UpdateProfile(request); user = userRepository.GetUser(userId); Assert.AreEqual(userId, user.Id); Assert.AreEqual(userName, user.DisplayName); }
public void UpdateUserProfileChangeDisplayName() { var userId = Guid.NewGuid().ToString(); var userName = "******"; var newName = "Johnny New Name"; var userRepository = this.CreateUserRepository(); var statisticsProvider = this.CreateStatisticsRepository(); var userService = this.CreateUserService(userRepository, statisticsProvider, userId); var user = new UserProfile { Id = userId, DisplayName = userName }; userRepository.AddOrUpdateUser(user); var parametersTemplate = "displayName={0}"; var parameters = string.Format(CultureInfo.InvariantCulture, parametersTemplate, newName); var request = new HttpRequestMessage(); request.Content = new StringContent(parameters); request.Content.Headers.ContentType.MediaType = "application/x-www-form-urlencoded"; userService.UpdateProfile(request); user = userRepository.GetUser(userId); Assert.AreEqual(userId, user.Id); Assert.AreEqual(newName, user.DisplayName); }
public void LeaveUserFromGameTest() { Game game = this.FrancisGabrielDonAndLukeGame(); var francisUser = new UserProfile { Id = Guid.NewGuid().ToString(), DisplayName = "Francis" }; var users = new AzureBlobContainer<UserProfile>(CloudStorageAccount.DevelopmentStorageAccount); var sessions = new AzureBlobContainer<UserSession>(CloudStorageAccount.DevelopmentStorageAccount); var friends = new AzureBlobContainer<Friends>(CloudStorageAccount.DevelopmentStorageAccount); var userRepository = new UserRepository(users, sessions, friends); userRepository.AddOrUpdateUser(francisUser); this.gameRepository.AddOrUpdateGame(game); this.gameRepository.LeaveUserFromGame(francisUser.Id, game.Id); }
private void CreateUser(IUserRepository userRepository, string userId) { var userProfile = new UserProfile() { Id = userId, DisplayName = userId }; userRepository.AddOrUpdateUser(userProfile); }