示例#1
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private void Initialize()
        {
            var sender     = CreateUser("TestMessageSender", "porkmuffins", "*****@*****.**", 10);
            var firstUser  = CreateUser("One", "1", "*****@*****.**", 20);
            var secondUser = CreateUser("Two", "2", "*****@*****.**", 30);
            var thirdUser  = CreateUser("Three", "3", "*****@*****.**", 40);
            var fourthUser = CreateUser("Four", "4", "*****@*****.**", 50);

            using (var db = new CSSDataContext())
            {
                Group.CreateGroup(db, "GroupA", false, "@GA");
                Group.CreateGroup(db, "GroupB", false, "@GB");

                var role = new GroupRole()
                {
                    Name  = "Member",
                    Token = null
                };

                db.GroupRoles.InsertOnSubmit(role);
                db.SubmitChanges();

                Group.AddAlias(db, "GroupA", "One");
                Group.AddAlias(db, "GroupA", "Two");
                Group.AddAlias(db, "GroupB", "Three");
                Group.AddAlias(db, "GroupB", "Four");
                db.SubmitChanges();

                GroupMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR GROUP A WHICH CONSISTS OF \"One\" AND \"Two\"",
                                        "GroupA", DateTime.Now, sender.Aliases.FirstOrDefault());
                GroupMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR GROUP A WHICH CONSISTS OF \"Three\" AND \"Four\"",
                                        "GroupB", DateTime.Now, sender.Aliases.FirstOrDefault());

                GroupMessage.NewMessage(db, "Global Message", "This message should go to all users.", null, DateTime.Now, sender.Aliases.FirstOrDefault());

                db.SubmitChanges();

                PersonalMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR \"One\"",
                                           firstUser.Aliases.First(), Login.FindLoginByUsernameOrCallsign(db, "One"), DateTime.Now);

                db.SubmitChanges();

                PersonalMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR \"Two\"",
                                           firstUser.Aliases.First(), Login.FindLoginByUsernameOrCallsign(db, "Two"), DateTime.Now);
                PersonalMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR \"Three\"",
                                           firstUser.Aliases.First(), Login.FindLoginByUsernameOrCallsign(db, "Three"), DateTime.Now);
                PersonalMessage.NewMessage(db, "SUBJECT", "THIS MESSAGE IS FOR \"Four\"",
                                           firstUser.Aliases.First(), Login.FindLoginByUsernameOrCallsign(db, "Four"), DateTime.Now);

                db.SubmitChanges();
            }
        }
示例#2
0
        public static bool Write(CSSDataContext db, LogType type, string message, bool submit)
        {
            try
            {
                db.Logs.InsertOnSubmit(new Log()
                {
                    DateOccurred = DateTime.Now,
                    Message      = message,
                    Type         = (byte)type
                });

                if (submit)
                {
                    db.SubmitChanges();
                }

                Console.WriteLine(String.Format("{0}: {1} {2}", DateTime.Now, type.ToString(), message));

                return(true);
            }
            catch (Exception error)
            {
                var errorMessage = new StringBuilder()
                                   .AppendLine("Failed to write data to log:")
                                   .Append("Type: ").AppendLine(type.ToString())
                                   .Append("Message: ").AppendLine(message);

                Debug.WriteLine(errorMessage);

                Error.Write(db, new Exception(errorMessage.ToString(), error), submit);
                return(false);
            }
        }
        private void LoadTestMachineExclusions()
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                db.MachineRecordExclusions.InsertOnSubmit(new MachineRecordExclusion()
                {
                    Id             = 1,
                    IdentifierMask = "Volume0",
                    RecordTypeId   = 2
                });

                db.MachineRecordExclusions.InsertOnSubmit(new MachineRecordExclusion()
                {
                    Id             = 2,
                    IdentifierMask = "%Volume1",
                    RecordTypeId   = 2
                });

                db.MachineRecordExclusions.InsertOnSubmit(new MachineRecordExclusion()
                {
                    Id             = 3,
                    IdentifierMask = "Volume2%",
                    RecordTypeId   = 2
                });

                db.MachineRecordExclusions.InsertOnSubmit(new MachineRecordExclusion()
                {
                    Id             = 4,
                    IdentifierMask = "%Volume3%",
                    RecordTypeId   = 2
                });

                db.SubmitChanges();
            }
        }
示例#4
0
        public ProcessOnValidateResponse ProcessOnValidate(ProcessOnValidateRequest request)
        {
            EnsureValidRequest(request);

            var response = new ProcessOnValidateResponse();

            using (var db = new CSSDataContext())
            {
                var login = Login.FindLoginByUsernameOrCallsign(db, request.auth);
                if (login == null)
                {
                    login = db.Logins.FirstOrDefault(p => p.Email == request.auth);
                }

                if (login == null)
                {
                    response.completed = 1;
                    response.response  = "FAILED";
                }
                else
                {
                    // TODO: If we ever need to support email validation, set the flag in ACSS here.
                    // Example: login.EmailValidated = true;

                    response.completed = 1;
                    response.response  = "SUCCESS";
                }

                db.SubmitChanges();
            }

            return(response);
        }
示例#5
0
        public ProcessOnUsernameChangeResponse ProcessOnUsernameChange(ProcessOnUsernameChangeRequest request)
        {
            File.AppendAllText(@"c:\php_requests.log", "ipConverge.onUsernameChange " + request.auth + ", " + request.new_username + "\r\n");

            EnsureValidRequest(request);

            var response = new ProcessOnUsernameChangeResponse();

            using (var db = new CSSDataContext())
            {
                var login = Login.FindLoginByUsernameOrCallsign(db, request.auth);
                if (login == null)
                {
                    login = db.Logins.FirstOrDefault(p => p.Email == request.auth);
                }

                if (login == null)
                {
                    response.completed = 1;
                    response.response  = "FAILED";
                }
                else
                {
                    login.Username     = request.new_username;
                    response.completed = 1;
                    response.response  = "SUCCESS";
                }

                db.SubmitChanges();
            }

            return(response);
        }
        public void ClearDatabase()
        {
            if (_initialized)
            {
                return;
            }

            using (var db = new CSSDataContext())
            {
                //Clear data
                try
                {
                    db.DeleteDatabase();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }

                db.CreateDatabase();

                //Create any other functions which weren't created
                SetupFunctions(db);

                //Insert any test data
                InsertTestData(db);

                //Submit changes
                db.SubmitChanges();

                _initialized = true;
            }
        }
示例#7
0
        public void TestUnlinking()
        {
            TestMerging();

            using (DataAccess.CSSDataContext db = new CSSDataContext())
            {
                Identity principal     = Alias.GetAliasByCallsign(db, "User1").Login.Identity;
                Login    loginToUnlink = Alias.GetAliasByCallsign(db, "User2").Login;

                Identity.UnlinkLogin(db, principal, loginToUnlink);

                loginToUnlink = Alias.GetAliasByCallsign(db, "User3").Login;
                Identity.UnlinkLogin(db, principal, loginToUnlink);

                db.SubmitChanges();

                var user3 = Alias.GetAliasByCallsign(db, "User3").Login;
                Assert.AreEqual(2, user3.Identity.MachineRecords.Count());
                Assert.AreEqual(1, user3.Identity.PollVotes.Count());
                Assert.AreEqual(0, user3.Identity.Bans.Count());

                var user2 = Alias.GetAliasByCallsign(db, "User2").Login;
                Assert.AreEqual(0, user2.Identity.MachineRecords.Count());
                Assert.AreEqual(0, user2.Identity.PollVotes.Count());
                Assert.AreEqual(2, user2.Identity.Bans.Count());

                var user1 = Alias.GetAliasByCallsign(db, "User1").Login;
                Assert.AreEqual(0, user1.Identity.MachineRecords.Count());
                Assert.AreEqual(0, user1.Identity.PollVotes.Count());
                Assert.AreEqual(0, user1.Identity.Bans.Count());
            }
        }
示例#8
0
        private void ClearDataForCallsign(string callsign)
        {
            using (var db = new CSSDataContext())
            {
                var login = Login.FindLoginByUsernameOrCallsign(db, callsign);

                if (login != null)
                {
                    foreach (var associatedLogin in login.Identity.Logins)
                    {
                        db.Alias.DeleteAllOnSubmit(associatedLogin.Aliases);
                        db.Login_UnlinkedLogins.DeleteAllOnSubmit(associatedLogin.Login_UnlinkedLogins);
                        db.Bans.DeleteAllOnSubmit(associatedLogin.Bans);
                        db.Bans.DeleteAllOnSubmit(associatedLogin.IssuedBans);
                        db.PollVotes.DeleteAllOnSubmit(associatedLogin.PollVotes);
                        db.MachineRecords.DeleteAllOnSubmit(associatedLogin.MachineRecords);
                        db.Logins.DeleteOnSubmit(associatedLogin);
                    }

                    db.PollVotes.DeleteAllOnSubmit(login.PollVotes);
                    db.Bans.DeleteAllOnSubmit(login.Bans);
                    db.Bans.DeleteAllOnSubmit(login.IssuedBans);
                    db.MachineRecords.DeleteAllOnSubmit(login.MachineRecords);
                    db.Logins.DeleteAllOnSubmit(db.Logins.Where(p => p.Id == login.Id));
                    db.Identities.DeleteOnSubmit(login.Identity);
                    db.LogIPs.DeleteAllOnSubmit(login.Identity.LogIPs);

                    db.SubmitChanges();
                }
            }
        }
示例#9
0
        public static void Delete(CSSDataContext db, Identity identity)
        {
            db.Bans.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Bans));
            db.Bans.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.IssuedBans));
            db.Group_Alias_GroupRoles.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases.SelectMany(r => r.Group_Alias_GroupRoles)));
            db.GroupMessages.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases.SelectMany(r => r.GroupMessages)));
            db.GroupMessage_Alias.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases.SelectMany(r => r.GroupMessage_Alias)));
            db.GroupRequests.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases.SelectMany(r => r.GroupRequests)));
            db.Lobby_Logins.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Lobby_Logins));
            db.Login_Roles.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Login_Roles));
            db.Login_UnlinkedLogins.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Login_UnlinkedLogins));
            db.Login_UnlinkedLogins.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Login_UnlinkedLogins1));
            db.MachineRecords.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.MachineRecords));
            db.PersonalMessages.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.PersonalMessages));
            db.PersonalMessages.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases.SelectMany(r => r.PersonalMessages)));
            db.PollVotes.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.PollVotes));
            db.Sessions.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Sessions));
            db.UsedKeys.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.UsedKeys));

            db.Alias.DeleteAllOnSubmit(identity.Logins.SelectMany(p => p.Aliases));
            db.Logins.DeleteAllOnSubmit(identity.Logins);
            db.Identities.DeleteOnSubmit(identity);

            db.SubmitChanges();
        }
示例#10
0
        static public List <IMessage> GetGroupMessages(CSSDataContext db, string callsign)
        {
            var messages = new List <IMessage>();
            var aliases  = Alias.ListAliases(db, callsign);

            foreach (var alias in aliases)
            {
                messages.AddRange(
                    alias.GroupMessage_Alias.Where(p => p.DateViewed == null).Select(p => (IMessage)p.GroupMessage).ToList()
                    );

                //messages.AddRange(alias.GroupMessages
                //    .Where(
                //        p => p.DateExpires <=  DateTime.Now
                //        &&	p.DateToSend >= DateTime.Now
                //        && p.GroupMessage_Alias
                //            .FirstOrDefault(r => r.Alias == alias && r.DateViewed == null) != null)
                //    .Select(q => (IMessage)q).ToList());

                foreach (var gma in alias.GroupMessage_Alias.Where(p => p.DateViewed == null && messages.Select(q => q.Id).Contains(p.GroupMessageId)))
                {
                    //if (messages.FirstOrDefault(p => p.Id == gma.GroupMessageId) != null)
                    gma.DateViewed = DateTime.Now;
                }

                db.SubmitChanges();
            }

            return(messages);
        }
示例#11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                // If the page loaded, then don't worry about the date at this point, they'll get a free ride if
                // they camped on the page for a while. The date is just to keep the enemy from getting a hold
                // of an old email and coming back in with it.
                var logins = db.Logins.Where(p => p.PasswordResetGuid == new Guid(Request.Params["resetGuid"]));

                foreach (var login in logins)
                {
                    CssMembershipProvider cssMembershipProvider = new CssMembershipProvider();

                    string tempPassword = cssMembershipProvider.ResetPassword(login.Username, null);

                    cssMembershipProvider.ChangePassword(login.Username, tempPassword, txtPassword.Text);
                }

                db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, logins);

                foreach (var login in logins)
                {
                    // Keep anyone from reusing an old password reset mail.
                    login.PasswordResetGuid = Guid.Empty;
                }

                db.SubmitChanges();
            }

            divResetPassword.Visible = false;
            divResetSuccess.Visible  = true;
        }
        private void LoadTestVirtualMachineMarkers()
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                db.VirtualMachineMarkers.InsertOnSubmit(new VirtualMachineMarker()
                {
                    IdentifierMask = "%|Virtual HD|%",
                    RecordTypeId   = 2
                });

                db.VirtualMachineMarkers.InsertOnSubmit(new VirtualMachineMarker()
                {
                    IdentifierMask = "%|VirtualBox %",
                    RecordTypeId   = 1
                });

                db.VirtualMachineMarkers.InsertOnSubmit(new VirtualMachineMarker()
                {
                    IdentifierMask = "%|VMware %",
                    RecordTypeId   = 1
                });

                db.VirtualMachineMarkers.InsertOnSubmit(new VirtualMachineMarker()
                {
                    IdentifierMask = "%|QEMU HARDDISK|%",
                    RecordTypeId   = 2
                });

                db.SubmitChanges();
            }
        }
        protected void btnSaveNewGroup_Click(object sender, EventArgs e)
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                if (db.Groups.FirstOrDefault(p => p.Name == txtName.Text.Trim()) != null)
                {
                    lblErrorText.Text = "The group or squad name you specified: " + txtName.Text + " already exists.";
                    return;
                }

                if (db.Groups.FirstOrDefault(p => p.Tag == txtTag.Text.Trim()) != null)
                {
                    lblErrorText.Text = "The tag name you specified: " + txtTag.Text + " already exists.";
                    return;
                }

                db.Groups.InsertOnSubmit(new Group()
                {
                    Name        = txtName.Text.Trim(),
                    DateCreated = DateTime.Now,
                    IsSquad     = chkIsSquad.Checked,
                    Tag         = txtTag.Text
                });

                db.SubmitChanges();

                this.DataBind();
            }
        }
示例#14
0
 public static void Clean()
 {
     using (var db = new CSSDataContext())
     {
         db.Errors.DeleteAllOnSubmit(db.Errors.Where(p => p.DateOccurred < DateTime.Now.AddDays(-30)));
         db.SubmitChanges();
     }
 }
示例#15
0
        public void MarkRead(CSSDataContext db, int aliasId)
        {
            var ga = db.GroupMessage_Alias.FirstOrDefault(gma => gma.GroupMessageId == Id && gma.AliasId == aliasId);

            ga.DateViewed = DateTime.Now;

            db.SubmitChanges();
        }
 public static void Clean()
 {
     using (var db = new CSSDataContext())
     {
         db.LogIPs.DeleteAllOnSubmit(db.LogIPs.Where(p => p.LastAccessed < DateTime.Now.AddDays(-180)));
         db.SubmitChanges();
     }
 }
        private BanType Initialize()
        {
            DataAccess.BanType banType;
            using (var db = new CSSDataContext())
            {
                banType = db.BanTypes.FirstOrDefault(p => p.RocNumber == 1);

                if (_initialized)
                {
                    return(banType);
                }

                if (db.Logins.FirstOrDefault(p => p.Username == "Admin") == null)
                {
                    //Create new user
                    CreateUser("Admin", "Test", "NA", 10);

                    var admin = Login.FindLoginByUsernameOrCallsign(db, "Admin");
                    admin.Login_Roles.Add(new Login_Role()
                    {
                        RoleId = (int)RoleType.Administrator
                    });
                    admin.Login_Roles.Add(new Login_Role()
                    {
                        RoleId = (int)RoleType.SuperAdministrator
                    });
                }

                db.Bans.DeleteAllOnSubmit(db.Bans);

                var banClass = new BanClass()
                {
                    Id   = 1,
                    Name = "Minor"
                };

                db.BanClasses.DeleteAllOnSubmit(db.BanClasses);
                db.BanClasses.InsertOnSubmit(banClass);

                banType = new BanType()
                {
                    BanClassId        = 1,
                    BaseTimeInMinutes = 30,
                    Description       = "Harassment / Threats",
                    IsIncremental     = true,
                    RocNumber         = 1
                };

                db.BanTypes.DeleteAllOnSubmit(db.BanTypes);
                db.BanTypes.InsertOnSubmit(banType);

                db.SubmitChanges();
            }

            _initialized = true;

            return(banType);
        }
示例#18
0
        internal static ActiveKey GenerateBlackbox(CSSDataContext db, bool debugMode)
        {
            var key = Compiler.Build(debugMode);

            db.ActiveKeys.InsertOnSubmit(key);
            db.SubmitChanges();

            return(key);
        }
示例#19
0
        public static void MergeLogin(CSSDataContext db, Login principalLogin, Login loginToMerge)
        {
            foreach (var item in loginToMerge.Aliases)
            {
                item.LoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.Bans)
            {
                item.LoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.IssuedBans)
            {
                item.BannedByLoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.Login_UnlinkedLogins.Where(p => p.LoginId1 == loginToMerge.Id))
            {
                item.LoginId1 = principalLogin.Id;
            }

            foreach (var item in loginToMerge.Login_UnlinkedLogins.Where(p => p.LoginId2 == loginToMerge.Id))
            {
                item.LoginId2 = principalLogin.Id;
            }

            foreach (var item in loginToMerge.MachineRecords)
            {
                item.LoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.PersonalMessages)
            {
                item.LoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.PollVotes)
            {
                item.LoginId = principalLogin.Id;
            }

            foreach (var item in loginToMerge.Sessions)
            {
                item.LoginId = principalLogin.Id;
            }

            Log.Write(LogType.ManagementWeb, "User " + loginToMerge.Username + " was merged to login " + principalLogin.Username);

            db.Login_Roles.DeleteAllOnSubmit(loginToMerge.Login_Roles);
            db.UsedKeys.DeleteAllOnSubmit(loginToMerge.UsedKeys);
            db.Lobby_Logins.DeleteAllOnSubmit(loginToMerge.Lobby_Logins);
            db.Logins.DeleteOnSubmit(loginToMerge);

            db.SubmitChanges();
        }
示例#20
0
 public static void RemoveExpiredCaptchas()
 {
     using (CSSDataContext db = new CSSDataContext())
     {
         var timeout     = DateTime.Now.AddSeconds(-CaptchaExpirationTimeInSeconds);
         var oldCaptchas = db.Captchas.Where(p => p.DateCreated < timeout);
         db.Captchas.DeleteAllOnSubmit(oldCaptchas);
         db.SubmitChanges();
     }
 }
示例#21
0
        public void TestUnlinkedLoginMerge()
        {
            Login login1;
            Login login2;
            Login login3;

            CreateTestData(out login1, out login2, out login3);

            using (var db = new CSSDataContext())
            {
                db.Login_UnlinkedLogins.InsertOnSubmit(new Login_UnlinkedLogin()
                {
                    LoginId1 = login1.Id,
                    LoginId2 = login2.Id
                });

                db.SubmitChanges();

                var identities = db.Identities.Where(p =>
                                                     p.Id == login1.Identity.Id ||
                                                     p.Id == login2.Identity.Id ||
                                                     p.Id == login3.Identity.Id);

                DataAccess.Identity.MergeIdentities(db, (IEnumerable <DataAccess.Identity>)identities.ToList());

                db.SubmitChanges();

                // Get the updated login.
                var mergedLogin = DataAccess.Login.FindLoginByUsernameOrCallsign(db, login1.Aliases.First().Callsign);

                Assert.AreEqual(1, db.Identities.Count(p => p.Id == login2.Identity.Id));
                Assert.AreEqual(0, db.Identities.Count(p => p.Id == login3.Identity.Id));

                Assert.AreEqual(2, mergedLogin.Identity.Logins.Count());
                Assert.AreEqual(0, mergedLogin.Identity.Bans.Count());
                Assert.AreEqual(2, mergedLogin.Identity.MachineRecords.Count());
                Assert.AreEqual(1, mergedLogin.Identity.PollVotes.Count());

                // User 1 has IPs 10, 11, 12, 13, 14 and User 3 has IPs 13, 14, 15, 16, 17.
                // If the accounts are merged, then the resule should be User 1 + User 3's IPs in the log table assiged to the merged identity.
                Assert.AreEqual(8, mergedLogin.Identity.LogIPs.Count());
            }
        }
示例#22
0
        private void DeletePollOption(int pollOptionID)
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                db.PollOptions.DeleteOnSubmit(db.PollOptions.FirstOrDefault(p => p.Id == pollOptionID));
                db.SubmitChanges();
            }

            Response.Redirect("EditPoll.aspx?pollID=" + PollID);
        }
示例#23
0
        public void TestPollRecalculation()
        {
            Initialize();

            using (var db = new CSSDataContext())
            {
                var userOne   = db.Logins.FirstOrDefault(p => p.Username == "One");
                var userTwo   = db.Logins.FirstOrDefault(p => p.Username == "Two");
                var userThree = db.Logins.FirstOrDefault(p => p.Username == "Three");
                var userFour  = db.Logins.FirstOrDefault(p => p.Username == "Four");

                // Link two logins.
                userTwo.Identity = userOne.Identity;

                var poll        = db.Polls.FirstOrDefault(p => p.Question == "Test Poll");
                var pollOption1 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option1");
                var pollOption2 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option2");
                var pollOption3 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option3");

                // User two's vote shouldn't count because it's linked to user one.
                pollOption1.PollVotes.Add(new PollVote()
                {
                    Login = userOne
                });
                pollOption2.PollVotes.Add(new PollVote()
                {
                    Login = userTwo
                });
                pollOption3.PollVotes.Add(new PollVote()
                {
                    Login = userThree
                });
                pollOption3.PollVotes.Add(new PollVote()
                {
                    Login = userFour
                });

                db.SubmitChanges();
            }

            Poll.RecalculateAllPolls();

            using (var db = new CSSDataContext())
            {
                var poll        = db.Polls.FirstOrDefault(p => p.Question == "Test Poll");
                var pollOption1 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option1");
                var pollOption2 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option2");
                var pollOption3 = poll.PollOptions.FirstOrDefault(p => p.Option == "Option3");

                Assert.AreEqual(1, pollOption1.VoteCount);
                Assert.AreEqual(0, pollOption2.VoteCount, "User two's vote shouldn't count because it's linked to user one.");
                Assert.AreEqual(2, pollOption3.VoteCount);
            }
        }
示例#24
0
        protected void btnRecalculatePoll_Click(object sender, EventArgs e)
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                var poll = db.Polls.FirstOrDefault(p => p.Id == PollID);
                poll.Recalculate();

                db.SubmitChanges();
            }

            BindData();
        }
示例#25
0
        public void TestMatching_DuplicateHardDriveRecords()
        {
            LoadTestMachineRecords();

            MachineInformation machineInformation = new MachineInformation();

            machineInformation.MachineValues = new List <DeviceInfo>();

            using (CSSDataContext db = new CSSDataContext())
            {
                // Get all machine records for login 12.
                var machineRecords = db.MachineRecords.Where(p => p.LoginId == 12);
                foreach (var machineRecord in machineRecords)
                {
                    machineInformation.MachineValues.Add(new DeviceInfo()
                    {
                        Name  = machineRecord.MachineRecordType.Name,
                        Type  = (DeviceType)machineRecord.MachineRecordType.Id,
                        Value = machineRecord.Identifier
                    });
                }

                machineInformation.MachineValues.Add(new DeviceInfo()
                {
                    Name  = DeviceType.HardDisk.ToString(),
                    Type  = DeviceType.HardDisk,
                    Value = "This is a test harddisk!"
                });

                var login12 = db.Logins.FirstOrDefault(p => p.Id == 12);
                var login13 = db.Logins.FirstOrDefault(p => p.Id == 13);

                Identity identity;
                bool     wasMerged;
                Identity.MatchIdentity(db, login12, machineInformation, out identity, out wasMerged);

                db.SubmitChanges();

                Assert.IsTrue(login12.Identity == identity);

                // Should be linked to account 13.
                Assert.AreEqual(2, db.Logins.FirstOrDefault(p => p.Id == 12).Identity.Logins.Count);

                Assert.AreEqual(1, login12.Identity.Logins.Where(p => p.Id != login12.Id).Count());
                Assert.AreEqual(1, login12.Identity.MachineRecords.Where(p => p.LoginId != login12.Id).Count());
                Assert.AreEqual(0, login12.Identity.PollVotes.Where(p => p.LoginId != login12.Id).Count());
                Assert.AreEqual(0, login12.Identity.Bans.Where(p => p.LoginId != login12.Id).Count());

                Assert.IsTrue(Identity.IsLinkedToAnOlderAccount(db, login13.Username));

                Assert.AreEqual(login12.Username, Identity.GetOldestLinkedAcccountUsername(db, login13.Username));
            }
        }
        public static void RecalculateAllPolls()
        {
            using (CSSDataContext db = new CSSDataContext())
            {
                foreach (var poll in db.Polls)
                {
                    poll.Recalculate();
                }

                db.SubmitChanges();
            }
        }
示例#27
0
        private static void CleanupPolls()
        {
            try
            {
                using (var db = new CSSDataContext())
                {
                    //var duplicates = db.PollVotes.GroupBy(p => p.Login.Identity).Where(p => p.Count() > 1);
                    var duplicates = db.PollVotes.GroupBy(p => new { p.Login.Identity, p.PollOption.Poll }).Where(p => p.Count() > 1);

                    foreach (var duplicate in duplicates)
                    {
                        var votesToDelete = duplicate.OrderBy(p => p.Login.DateCreated).Skip(1);
                        db.PollVotes.DeleteAllOnSubmit(votesToDelete);
                    }

                    ////Retrieve duplicate all votes per poll
                    //var polls = from v in db.DuplicateVotes
                    //            group v by v.PollId into p
                    //            select p;

                    //foreach (var poll in polls)
                    //{
                    //    //Retrieve all unique identities per poll
                    //    var idents = from v in poll
                    //                 group v by v.IdentityId into i
                    //                 select i;

                    //    foreach (var ident in idents)
                    //    {
                    //        //If the user has voted more than once on a single
                    //        //poll, delete all polls after the first vote
                    //        if (ident.Count() > 1)
                    //        {
                    //            var toDelete = ident.Skip(1);

                    //            foreach (var duplicate in toDelete)
                    //            {
                    //                var vote = db.PollVotes.Single(p => p.Id == duplicate.PollVoteId);
                    //                db.PollVotes.DeleteOnSubmit(vote);
                    //            }
                    //        }
                    //    }
                    //}

                    db.SubmitChanges();
                }
            }
            catch (Exception error)
            {
                Error.Write(error);
            }
        }
示例#28
0
        public static void AddAlias(CSSDataContext db, string groupName, string alias)
        {
            var add = new Group_Alias_GroupRole()
            {
                AliasId     = db.Alias.FirstOrDefault(a => a.Callsign == alias).Id,
                GroupId     = db.Groups.FirstOrDefault(g => g.Name == groupName).Id,
                GroupRoleId = db.GroupRoles.FirstOrDefault(gr => gr.Name == "Member").Id //default to member
            };

            //TODO: Check for condition where alias is already in group
            db.Group_Alias_GroupRoles.InsertOnSubmit(add);
            db.SubmitChanges();
        }
示例#29
0
        public static void CreateGroup(CSSDataContext db, string name, bool isSquad, string tag)
        {
            var g = new Group()
            {
                DateCreated = DateTime.Now,
                Name        = name,
                IsSquad     = isSquad,
                Tag         = tag
            };

            db.Groups.InsertOnSubmit(g);
            db.SubmitChanges();
        }
示例#30
0
 /// <summary>
 /// Destroy all sessions associated with this login.
 /// </summary>
 public static void EndSession(string username, string password)
 {
     using (var db = new CSSDataContext())
     {
         Login       login;
         LoginStatus loginStatus;
         if (Login.TryGetAuthenticatedLogin(db, username, password, out login, out loginStatus) == true)
         {
             db.Sessions.DeleteAllOnSubmit(login.Sessions);
             db.SubmitChanges();
         }
     }
 }