public void ShouldStoreSiteNotes() { int expectedSiteID = 60; string notes = "Sample site notes, random value = " + DateTime.Now.Ticks + "."; int expectedUserID = 123456789; IDnaDiagnostics mockedDiagnostics = _mocks.DynamicMock<IDnaDiagnostics>(); string connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString; IDnaDataReaderCreator readerCreator = new DnaDataReaderCreator(connectionString, mockedDiagnostics); Site.CreateSiteNotes(expectedSiteID, notes, expectedUserID, readerCreator); using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("")) { string sql = "SELECT TOP 1 * FROM SiteUpdate ORDER BY UpdateID DESC"; reader.ExecuteDEBUGONLY(sql); Assert.IsTrue(reader.HasRows, "Failed to find site note just created"); Assert.IsTrue(reader.Read(), "Failed to read data from database query"); string siteNotes = reader.GetString("notes"); int siteID = reader.GetInt32("siteid"); int userID = reader.GetInt32("userid"); Assert.AreEqual(expectedSiteID, siteID); Assert.AreEqual(expectedUserID, userID); Assert.IsTrue(siteNotes.StartsWith(notes)); } }
private string GetDataBaseUserDetails(string userID) { StringBuilder details = new StringBuilder(); IDnaDataReaderCreator dataReaderCreator = new DnaDataReaderCreator(GetDataBaseConnectionDetails()); try { using (IDnaDataReader reader = dataReaderCreator.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("SELECT * FROM SignInUserIDMapping sim JOIN Users u ON u.UserID = sim.DNAUserID WHERE IdentityUserID = '" + userID + "'"); if (reader.HasRows && reader.Read()) { details.Append("<signInDetails>"); string loginName = reader.GetStringNullAsEmpty("loginname"); details.Append(string.Format("<{0}>{1}</{0}>", "logInName", loginName)); string identityUserID = reader.GetStringNullAsEmpty("IdentityUserID"); details.Append(string.Format("<{0}>{1}</{0}>", "identityUserID", identityUserID)); string displayName = reader.GetStringNullAsEmpty("username"); details.Append(string.Format("<{0}>{1}</{0}>", "displayName", displayName)); details.Append(string.Format("<{0}>{1}</{0}>", "email", reader.GetStringNullAsEmpty("email"))); details.Append(string.Format("<{0}>{1}</{0}>", "cookie", identityUserID.ToString() + "|" + loginName + "|" + displayName + "|0|DEBUG-IDENTITY-COOKIE")); details.Append(string.Format("<{0}>{1}</{0}>", "secureCookie", "HTTPS-DEBUG-IDENTITY-COOKIE")); details.Append(string.Format("<{0}>{1}</{0}>", "lastUpdated", DateTime.Now.AddYears(SyncDetails ? 1 : -1).ToString())); details.Append("</signInDetails>"); } else { LastError = "Failed to find identity user (" + userID.ToString() + ") in the database!"; } } } catch (Exception ex) { LastError = "Failed to find identity user (" + userID.ToString() + ") in the database! " + ex.Message; } return details.ToString(); }