public void AddOrUpdateUserWithNullUserTest()
 {
     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);
     target.AddOrUpdateUser(null);
 }
Пример #2
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>() });
        }
        public void Setup()
        {
            int suffix = (new Random()).Next(10000);
            var account = CloudStorageAccount.DevelopmentStorageAccount;

            this.notificationContainer = new AzureBlobContainer<NotificationStatus>(account, ConfigurationConstants.NotificationsContainerName + "test" + suffix, true);
            this.userContainer = new AzureBlobContainer<UserProfile>(account, ConfigurationConstants.UsersContainerName + "test" + suffix, true);
            this.userSessionContainer = new AzureBlobContainer<UserSession>(account, ConfigurationConstants.UserSessionsContainerName + "test" + suffix, true);
            this.friendsContainer = new AzureBlobContainer<Friends>(account, ConfigurationConstants.FriendsContainerName + "test" + suffix, true);

            this.notificationRepository = new NotificationRepository(this.notificationContainer);
            this.userRepository = new UserRepository(this.userContainer, this.userSessionContainer, this.friendsContainer);
            this.userRepository.Initialize();
            this.command = new InviteCommand(this.notificationRepository, this.userRepository);
        }
        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 AddOrUpdateUserSessionTest()
        {
            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);
            IAzureBlobContainer<UserSession> userSessionContainer = (IAzureBlobContainer<UserSession>)
                target.GetType().GetField("userSessionContainer", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(target);

            UserSession userSessionFirstVersion = new UserSession() { UserId = "johnny", ActiveGameQueueId = Guid.NewGuid() };
            target.AddOrUpdateUserSession(userSessionFirstVersion);
            var result = userSessionContainer.Get(userSessionFirstVersion.UserId);
            Assert.AreEqual(userSessionFirstVersion, result);

            UserSession userSessionSecondVersion = new UserSession() { UserId = userSessionFirstVersion.UserId, ActiveGameQueueId = Guid.NewGuid() };
            target.AddOrUpdateUserSession(userSessionSecondVersion);
            result = userSessionContainer.Get(userSessionFirstVersion.UserId);
            Assert.AreEqual(userSessionSecondVersion, result);
            Assert.AreNotEqual(userSessionFirstVersion, result);
        }
        public void FailedAddOrUpdateUserSessionTest()
        {
            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);

            UserSession userSessionFirstVersion = new UserSession() { UserId = null, ActiveGameQueueId = Guid.NewGuid() };
            ExceptionAssert.ShouldThrow<ArgumentException>(() => target.AddOrUpdateUserSession(userSessionFirstVersion));

            UserSession userSessionSecondVersion = new UserSession() { UserId = string.Empty, ActiveGameQueueId = Guid.NewGuid() };
            ExceptionAssert.ShouldThrow<ArgumentException>(() => target.AddOrUpdateUserSession(userSessionSecondVersion));
        }
 public void GetUserWithEmptyIdTest()
 {
     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);
     target.GetUser(string.Empty);
 }
 public void GetUserTest()
 {
     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);
     Assert.IsNull(target.GetUser(Guid.NewGuid().ToString()));
 }
 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 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);
 }
Пример #12
0
        private UserRepository CreateUserRepository()
        {
            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            this.userContainer = new AzureBlobContainer<UserProfile>(account, ConfigurationConstants.UsersContainerName + "test" + this.suffix, true);
            this.userSessionContainer = new AzureBlobContainer<UserSession>(account, ConfigurationConstants.UserSessionsContainerName + "test" + this.suffix, true);
            this.friendContainer = new AzureBlobContainer<Friends>(account, ConfigurationConstants.FriendsContainerName + "test" + this.suffix, true);

            this.userContainer.EnsureExist(true);
            this.userSessionContainer.EnsureExist(true);
            this.friendContainer.EnsureExist(true);

            var repo = new UserRepository(this.userContainer, this.userSessionContainer, this.friendContainer);
            repo.Initialize();

            return repo;
        }