public void TestListAliases()
        {
            Initialize();

            var adminService = new Administration();
            var results = adminService.ListAliases(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Admin");
            Assert.AreEqual(1, results.Count);

            // Try to log in with a non-existant alias.
            var clientService = new ClientService();
            var loginResult = clientService.Login(new LoginData()
            {
                Username = "******",
                Password = "******",
                Alias    = "Jerky",
                LobbyId  = 1
            });
            Assert.AreEqual(LoginStatus.Authenticated, loginResult.Status);
            Assert.AreEqual("Admin", loginResult.AcceptedAlias, "Logging in with an invalid alias reverts back to the oldest available alias.");

            results = adminService.ListAliases(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Admin");
            Assert.AreEqual(1, results.Count);
        }
        public void TestBan()
        {
            DataAccess.BanType banType = Initialize();

            //Test Set, ListBans, Remove, ensure user has requisite permissions.
            var adminService = new Administration();
            var result = adminService.SetBan(new BanData()
            {
                BanMode				= BanMode.Auto,
                BanTypeId			= banType.Id,
                Username            = "******",
                Password            = "******",
                Reason              = "#1 Orion is being a general dick.",
                Alias               = "Orion",
            });

            Assert.IsTrue(result);

            //Ensure banned user can no longer log in
            var clientService = new ClientService();
            var loginResult = clientService.Login(new LoginData()
            {
                Username    = "******",
                Password    = "******",
                Alias       = "Orion"
            });
            Assert.AreEqual(LoginStatus.AccountLocked, loginResult.Status);

            //List bans
            var bans = adminService.ListBans(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Orion");

            //Remove all bans
            var ban = bans.FirstOrDefault();
            adminService.RemoveBan(new BanData()
            {
                Username    = "******",
                Password    = "******",
                BanId       = ban.Id
            });

            bans = adminService.ListBans(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Orion");

            Assert.AreEqual(0, bans.Where(p => p.InEffect == true).Count());

            //Ensure user can log in.
            clientService = new ClientService();
            loginResult = clientService.Login(new LoginData()
            {
                Username    = "******",
                Password    = "******",
                Alias       = "Orion",
                LobbyId     = 1
            });
            Assert.AreEqual(LoginStatus.Authenticated, loginResult.Status);

            //Set two sequential bans.
            result = adminService.SetBan(new BanData()
            {
                BanMode             = BanMode.Auto,
                Username            = "******",
                Password            = "******",
                BanTypeId			= banType.Id,
                Reason              = "#2 Orion is being a general dick.",
                Alias               = "Orion",
            });
            Assert.IsTrue(result);

            result = adminService.SetBan(new BanData()
            {
                BanMode             = BanMode.Auto,
                Username            = "******",
                Password            = "******",
                BanTypeId			= banType.Id,
                Reason              = "#3 Orion is /STILL/ being a general dick.",
                Alias               = "Orion",
            });
            Assert.IsTrue(result);

            //Retrieve ban
            bans = adminService.ListBans(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Orion");

            Assert.AreEqual(2, bans.Where(p => p.InEffect == true).Count());

            var firstBan	= bans.Where(p => p.InEffect == true).OrderBy(p => p.DateCreated).First();
            var lastBan		= bans.Where(p => p.InEffect == true).OrderBy(p => p.DateCreated).Last();

            var firstDuration   = (firstBan.DateExpires.Value - firstBan.DateCreated).TotalMinutes;
            var lastDuration    = (lastBan.DateExpires.Value - lastBan.DateCreated).TotalMinutes;

            Assert.IsTrue(lastDuration > firstDuration);

            //Reset ban length
            adminService.SetBan(new BanData()
            {
                Username    = "******",
                Password    = "******",
                BanId       = firstBan.Id,
                BanMode     = BanMode.Custom,
                Duration    = TimeSpan.MinValue,
                Alias		= "Orion"
            });

            adminService.SetBan(new BanData()
            {
                Username    = "******",
                Password    = "******",
                BanId       = lastBan.Id,
                BanMode     = BanMode.Custom,
                Duration    = TimeSpan.MinValue,
                Alias		= "Orion"
            });

            bans = adminService.ListBans(new AuthenticatedData()
            {
                Username = "******",
                Password = "******"
            }, "Orion");

            Assert.AreEqual(2, bans.Where(p => p.InEffect == true).Count());

            Assert.AreEqual(0, bans.Where(p => p.InEffect == true && p.DateExpires > DateTime.Now).Count());
        }
        public void TestLogin()
        {
            var clientService = new ClientService();

            var result = clientService.Login(new LoginData()
            {
                Username    = username,
                Password    = password,
                Alias       = username,
                LobbyId     = 1 //Production
            });
            Assert.AreEqual(LoginStatus.Authenticated, result.Status);

            result = clientService.Login(new LoginData()
            {
                Username    = "******",
                Password    = "******",
                Alias       = "BogusAlias"
            });
            Assert.AreEqual(LoginStatus.InvalidCredentials, result.Status);

            result = clientService.Login(new LoginData()
            {
                Username    = username,
                Password    = password,
                Alias       = "NewAlias",
                LobbyId     = 1
            });
            Assert.AreEqual(LoginStatus.Authenticated, result.Status);

            result = clientService.Login(new LoginData()
            {
                Username    = username,
                Password    = password,
                Alias       = "Invalid Alias",
                LobbyId     = 1
            });
            Assert.AreEqual(LoginStatus.Authenticated, result.Status);
            Assert.AreEqual(username, result.AcceptedAlias, "Logging in with an invalid alias but a valid account will revert back to the oldest alias for that account.");
        }