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 MyTestInitialize() { this.timeProvider = new FixedTimeProvider(); TimeProvider.Current = this.timeProvider; }