Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed a test fixture that was no longer needed

  • Loading branch information...
commit cdc8c71067d7bea78efe947682bb4ce4bb0354d2 1 parent ae32921
@Sedward Sedward authored
Showing with 0 additions and 253 deletions.
  1. +0 −253 SessionStoreTest/SessionOpsTest.cs
View
253 SessionStoreTest/SessionOpsTest.cs
@@ -1,253 +0,0 @@
-using System;
-using System.IO;
-using System.Configuration;
-using System.Collections.Generic;
-using System.Web;
-using System.Web.Configuration;
-using System.Configuration;
-using System.Configuration.Provider;
-using System.Web.SessionState;
-using System.Text;
-using NUnit.Framework;
-using MongoDB.Driver;
-using MongoDB.Driver.Serialization;
-using MongoDB.Driver.Connections;
-using MongoDB.Driver.Configuration;
-
-namespace SessionStoreTest
-{
- [TestFixture]
- public class SessionOpsTest
- {
- Connection conn;
- MongoDatabase db;
- IMongoCollection sessions;
- string ApplicationName = "TestApp";
- SessionStateStoreData item;
- string sessionID;
-
- [SetUp]
- public void SetUp()
- {
- MongoConfiguration config = (MongoConfiguration)System.Configuration.ConfigurationManager.GetSection("Mongo");
- conn = ConnectionFactory.GetConnection(config.Connections["mongoserver"].ConnectionString);
-
- db = new MongoDatabase(SerializationFactory.Default, conn, "SessionTest");
- sessions = db.GetCollection("sessions");
-
- SessionStateItemCollection sessionItems = new SessionStateItemCollection();
- HttpStaticObjectsCollection staticObjects = new HttpStaticObjectsCollection();
- item = new SessionStateStoreData(sessionItems, staticObjects, 1);
- }
-
- [Test]
- public void TearDown()
- {
- conn.Open();
- db["$cmd"].FindOne(new Document().Append("drop", "sessions"));
- conn.Close();
- }
-
- [Test]
- public void InsertNewSession()
- {
- byte[] sessionItems = Serialize((SessionStateItemCollection)item.Items);
- OidGenerator oGen = new OidGenerator();
- sessionID = oGen.Generate().ToString();
- Document newSession = new Document() { { "SessionId",sessionID }, {"ApplicationName",ApplicationName},{"Created",DateTime.Now},
- {"Expires",DateTime.Now.AddMinutes((Double)item.Timeout)},{"LockDate",DateTime.Now},{"LockId",0},{"Timeout",item.Timeout},{"Locked",false},
- {"SessionItems",sessionItems},{"SessionItemsCount",item.Items.Count},{"Flags",0}};
-
- conn.Open();
- sessions.Insert(newSession);
- Document storedSession = sessions.FindOne(new Document() { { "SessionId", sessionID } });
- conn.Close();
-
- Assert.AreEqual(newSession["SessionItems"], storedSession["SessionItems"]);
- }
-
- [Test]
- public void LockSession()
- {
- conn.Open();
- byte[] sessionItems = Serialize((SessionStateItemCollection)item.Items);
- OidGenerator oGen = new OidGenerator();
- sessionID = oGen.Generate().ToString();
- Document newSession = new Document() { { "SessionId",sessionID }, {"ApplicationName",ApplicationName},{"Created",DateTime.Now},
- {"Expires",DateTime.Now.AddMinutes((Double)item.Timeout)},{"LockDate",DateTime.Now},{"LockId",0},{"Timeout",item.Timeout},{"Locked",false},
- {"SessionItems",sessionItems},{"SessionItemsCount",item.Items.Count},{"Flags",0}};
-
- sessions.Insert(newSession);
- Document storedSession = sessions.FindOne(new Document() { { "SessionId", sessionID } });
- Document selector = new Document() { { "SessionId", sessionID }, { "ApplicationName", ApplicationName }, { "Expires", new Document() { { "$gt", DateTime.Now } } } };
- Document session = new Document() { { "$set", new Document(){{ "LockDate", DateTime.Now }, { "LockId",1 }, { "Locked", true } }}};
- sessions.Update(session, selector, 0, false);
-
- Document lockedSession = sessions.FindOne(selector);
- Assert.IsTrue((bool)lockedSession["Locked"]);
-
- conn.Close();
-
- }
-
- [Test]
- public void UpdateOrInsertSession()
- {
- conn.Open();
- Document existingSession = sessions.FindOne(new Document(){{"Expires", new Document(){{"$gt", DateTime.Now}}}});
- if (existingSession != null)
- {
- sessionID = (string)existingSession["SessionId"];
- }
- else
- {
- OidGenerator oGen = new OidGenerator();
- sessionID = oGen.Generate().ToString();
- }
-
- object lockId = 0;
- item.Items["ItemOne"] = "test one value updated";
- item.Items["ItemTwo"] = 3;
- item.Items["ItemThree"] = false;
-
- byte[] sessionItems = Serialize((SessionStateItemCollection)item.Items);
- Document session = new Document() { { "SessionId",sessionID }, {"ApplicationName",ApplicationName},{"Created",DateTime.Now},
- {"Expires",DateTime.Now.AddMinutes((Double)item.Timeout)},{"LockDate",DateTime.Now},{"LockId",0},{"Timeout",item.Timeout},{"Locked",false},
- {"SessionItems",sessionItems},{"SessionItemsCount",item.Items.Count},{"Flags",0}};
-
- Document selector = new Document(){{"SessionId",sessionID}};
- sessions.Update(session,selector,0,false);
-
-
- //Document updatedSession = sessions.FindOne(session);
- //SessionStateStoreData updatedItems = Deserialize((byte[])session["SessionItems"],item.Timeout);
- //Assert.AreEqual("test one value updated", (string)updatedItems["ItemOne"]);
- //Assert.AreEqual(3, (int)updatedItems["ItemTwo"]);
- //Assert.AreEqual(false, (bool)updatedItems["ItemThree"]);
- //Console.WriteLine((string)updatedItems["ItemOne"]);
- conn.Close();
- }
-
- [Test]
- public void DeleteExpiredSessions()
- {
-
- conn.Open();
- //Add a Sessions that is expired by a couple of minutes;
- byte[] sessionItemsExpired = Serialize((SessionStateItemCollection)item.Items);
- OidGenerator oGen = new OidGenerator();
- sessionID = oGen.Generate().ToString();
- Document expiredSession = new Document() { { "SessionId",sessionID }, {"ApplicationName",ApplicationName},{"Created",DateTime.Now},
- {"Expires",DateTime.Now.Subtract(new TimeSpan(0,2,0))},{"LockDate",DateTime.Now},{"LockId",0},{"Timeout",item.Timeout},{"Locked",false},
- {"SessionItems",sessionItemsExpired},{"SessionItemsCount",item.Items.Count},{"Flags",0}};
- sessions.Insert(expiredSession);
-
- //Add a Session that is not expired
- byte[] sessionItems = Serialize((SessionStateItemCollection)item.Items);
- sessionID = oGen.Generate().ToString();
- Document newSession = new Document() { { "SessionId",sessionID }, {"ApplicationName",ApplicationName},{"Created",DateTime.Now},
- {"Expires",DateTime.Now.AddMinutes((Double)item.Timeout)},{"LockDate",DateTime.Now},{"LockId",0},{"Timeout",item.Timeout},{"Locked",false},
- {"SessionItems",sessionItems},{"SessionItemsCount",item.Items.Count},{"Flags",0}};
-
- sessions.Insert(newSession);
-
- int i = 0;
- ICursor before = sessions.FindAll();
- foreach (Document d in before.Documents)
- {
- i++;
- }
- Assert.AreEqual(2, i);
- conn.Close();
-
- //Delete expired sessions
-
- Document expiredSelector = new Document(){{ "Expires", new Document(){{ "$lt", DateTime.Now }}}};
- sessions.Delete(expiredSelector);
- ICursor after = sessions.FindAll();
-
- i = 0;
- foreach (Document d in after.Documents)
- {
- i++;
- }
- Assert.AreEqual(1,i);
-
-
- }
-
- [Test]
- public void FindExpired()
- {
- Document expiredSelector = new Document() {{"Expires", new Document(){{"$lt", DateTime.Now }}}};
- conn.Open();
- ICursor expired = sessions.Find(expiredSelector);
- Console.WriteLine(DateTime.Now.ToString());
- foreach (Document session in expired.Documents)
- {
- string id = (string)session["SessionId"];
- DateTime created = (DateTime)session["Created"];
- created = created.ToLocalTime();
- DateTime expires = (DateTime)session["Expires"];
- expires = expires.ToLocalTime();
- string applicationName = (string)session["ApplicationName"];
- int sessionItemsCount = (int)session["SessionItemsCount"];
- Console.WriteLine("SessionId:" + id + "| Created:" + created.ToString() + "| Expires:" + expires.ToString() + "| Application:" + applicationName + "| Total Items:" + sessionItemsCount.ToString());
- }
- conn.Close();
- }
-
- [Test]
- public void DumpSessions()
- {
- conn.Open();
- ICursor allSessions = sessions.FindAll();
- foreach (Document session in allSessions.Documents)
- {
- string sessionid = (string)session["SessionId"];
- DateTime created = (DateTime)session["Created"];
- created = created.ToLocalTime();
- Binary sessionItems = (Binary)session["SessionItems"];
- DateTime expires = (DateTime)session["Expires"];
- expires = expires.ToLocalTime();
- string applicationName = (string)session["ApplicationName"];
- int sessionItemsCount = (int)session["SessionItemsCount"];
- bool locked = (bool)session["Locked"];
- string output = "SessionId:" + sessionid + " | Created:" + created.ToString() + " | Expires:" + expires.ToString() +" | Locked?: "+ locked.ToString();
- output += " | Application:" + applicationName + " | Total Items:" + sessionItemsCount.ToString() + " | Size in Bytes:" + sessionItems.Bytes.Length.ToString();
- Console.WriteLine(output);
- }
- conn.Close();
- }
-
- private byte[] Serialize(SessionStateItemCollection items)
- {
- MemoryStream ms = new MemoryStream();
- BinaryWriter writer = new BinaryWriter(ms);
- if (items != null)
- items.Serialize(writer);
- writer.Close();
- return ms.ToArray();
- }
-
- private SessionStateStoreData Deserialize(HttpContext context, byte[] serializedItems, int timeout)
- {
- MemoryStream ms = new MemoryStream(serializedItems);
- SessionStateItemCollection sessionItems = new SessionStateItemCollection();
-
- if (ms.Length > 0)
- {
- BinaryReader reader = new BinaryReader(ms);
- sessionItems = SessionStateItemCollection.Deserialize(reader);
- }
-
- return new SessionStateStoreData(sessionItems,
- SessionStateUtility.GetSessionStaticObjects(context),
- timeout);
- }
-
-
-
-
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.