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 InitializeGameRepository() { this.cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount; this.skirmishGameMessageQueue = new AzureQueue<SkirmishGameQueueMessage>(this.cloudStorageAccount, skirmishGameMessageQueueName); this.leaveGameMessageQueue = new AzureQueue<LeaveGameMessage>(this.cloudStorageAccount, leaveGameMessageQueueName); this.gameContainer = new AzureBlobContainer<Game>(this.cloudStorageAccount, gameContainerName, true); this.gameQueueContainer = new AzureBlobContainer<GameQueue>(this.cloudStorageAccount, gameQueueContainerName, true); this.userContainer = new AzureBlobContainer<UserProfile>(this.cloudStorageAccount, userContainerName, true); this.inviteQueue = new AzureQueue<InviteMessage>(this.cloudStorageAccount, inviteQueueName); this.gameRepository = new GameRepository(this.gameContainer, this.gameQueueContainer, this.skirmishGameMessageQueue, this.leaveGameMessageQueue, this.userContainer, this.inviteQueue); this.gameRepository.Initialize(); this.skirmishGameMessageQueue.Clear(); this.leaveGameMessageQueue.Clear(); }
private GameRepository CreateGameRepository() { CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); this.gameContainer = new AzureBlobContainer<Game>(account, ConfigurationConstants.GamesContainerName + "test" + this.suffix, true); this.gameQueueContainer = new AzureBlobContainer<GameQueue>(account, ConfigurationConstants.GamesQueuesContainerName + "test" + this.suffix, true); this.skirmishGameMessageQueue = new AzureQueue<SkirmishGameQueueMessage>(account, ConfigurationConstants.SkirmishGameQueue + this.suffix); this.leaveGameMessageQueue = new AzureQueue<LeaveGameMessage>(account, ConfigurationConstants.LeaveGameQueue + "test" + this.suffix); this.inviteMessageQueue = new AzureQueue<InviteMessage>(account, ConfigurationConstants.InvitesQueue + "test" + this.suffix); this.gameContainer.EnsureExist(true); this.gameQueueContainer.EnsureExist(true); var repo = new GameRepository(this.gameContainer, this.gameQueueContainer, this.skirmishGameMessageQueue, this.leaveGameMessageQueue, this.userContainer, this.inviteMessageQueue); repo.Initialize(); return repo; }