Exemple #1
0
        public void FileIndexCounterIncrementsWhenFileExists()
        {
            const string newDirName = "IndexIncLogDir";

            if (Directory.Exists(newDirName))
            {
                Directory.Delete(newDirName, true);
            }

            var fileLogger        = new FileLogger("testLogger", newDirName);
            var loggerDate        = new DateTime(2001, 1, 1, 0, 0, 0);
            var fixedTimeProvider = new FixedTimeProvider(loggerDate);

            fileLogger.TimeProvider = fixedTimeProvider;
            fileLogger.Open();
            fileLogger.Dispose();
            fileLogger = new FileLogger("testLogger", newDirName);
            fileLogger.TimeProvider = fixedTimeProvider;
            fileLogger.Open();
            fileLogger.Dispose();
            var expectedFilename = string.Format("{0}-1.log.txt", loggerDate.ToString("yyyy-MM-dd HH-mm"));
            var expectedFilePath = Path.Combine(newDirName, expectedFilename);

            AssertFile.Exists(expectedFilePath);
        }
        public static ITimeRangeProvider GetProvider(int startTime, int endTime)
        {
            if (startTime == 0 && endTime == 0)
            {
                return(new SunriseSunset());
            }
            else
            {
                var fixedTimeProvider = new FixedTimeProvider(startTime, endTime);

                if (startTime == 0)
                {
                    return(new CompositeProvider(
                               new SunriseSunset(),
                               fixedTimeProvider));
                }
                else if (endTime == 0)
                {
                    return(new CompositeProvider(
                               fixedTimeProvider,
                               new SunriseSunset()));
                }
                else
                {
                    return(fixedTimeProvider);
                }
            }
        }
Exemple #3
0
 public void MyTestInitialize()
 {
     this.timeProvider    = new FixedTimeProvider();
     TimeProvider.Current = this.timeProvider;
 }
Exemple #4
0
        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>()
            });
        }