public static ControllerContext FakeControllerContext(Controller controller, Dictionary <string, string> routeDataValues) { var mock = new Mock <ControllerContext>(); var session = new Mock <HttpSessionStateBase>(); var routeData = new RouteData(); foreach (var keyValuePair in routeDataValues) { routeData.Values.Add(keyValuePair.Key, keyValuePair.Value); } mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true); mock.SetupGet(p => p.HttpContext.Request.ServerVariables).Returns(MockServerVariables()); mock.SetupGet(p => p.HttpContext.User.Identity.IsAuthenticated).Returns(true); mock.SetupGet(m => m.RouteData).Returns(routeData); session.SetupGet(s => s.SessionID).Returns(DatabaseTestBase.RandomString()); mock.SetupGet(p => p.HttpContext.Session).Returns(session.Object); var view = new Mock <IView>(); var engine = new Mock <IViewEngine>(); var viewEngineResult = new ViewEngineResult(view.Object, engine.Object); engine.Setup(e => e.FindPartialView(It.IsAny <ControllerContext>(), It.IsAny <string>(), It.IsAny <bool>())).Returns(viewEngineResult); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine.Object); controller.ControllerContext = mock.Object; return(mock.Object); }
public static void SessionValues_Insert_Fetch_Delete() { using (var db = CMSDataContext.Create(DatabaseFixture.Host)) { var sessionId = DatabaseTestBase.RandomString(); var name = DatabaseTestBase.RandomString(); var value = DatabaseTestBase.RandomString(); db.SessionValues.DeleteAllOnSubmit( db.SessionValues.Where(v => v.SessionId == sessionId && v.Name == name)); db.SessionValues.FirstOrDefault(v => v.Name == name && v.SessionId == sessionId).ShouldBeNull(); db.SessionValues.InsertOnSubmit(new SessionValue { SessionId = sessionId, Name = name, Value = value }); db.SubmitChanges(); var newdb = db.Copy(); var sessionValue = newdb.SessionValues.FirstOrDefault(v => v.Name == name && v.SessionId == sessionId); sessionValue.ShouldNotBeNull(); sessionValue.Value.ShouldBe(value); newdb.SessionValues.DeleteAllOnSubmit( newdb.SessionValues.Where(v => v.SessionId == sessionId && v.Name == name)); newdb.SubmitChanges(); sessionValue = newdb.SessionValues.FirstOrDefault(v => v.Name == name && v.SessionId == sessionId); sessionValue.ShouldBeNull(); } }
public void Should_Return_ProcessType(string description, int processType, int result) { using (var db = CMSDataContext.Create(DatabaseFixture.Host)) { var org = new Organization { OrganizationName = DatabaseTestBase.RandomString(), RegistrationTypeId = processType, Description = description, CreatedDate = DateTime.Now, OrganizationStatusId = 30, }; try { db.Organizations.InsertOnSubmit(org); db.SubmitChanges(); } catch (Exception e) { var i = e; } var paymentProcessType = MultipleGatewayUtils.ProcessByTransactionDescription(db, org.Description); var pp = (int)paymentProcessType; pp.ShouldBe(result); } }
public void Should_Return_RegistrationProcessType() { using (var db = CMSDataContext.Create(DatabaseFixture.Host)) { var randomDescription = DatabaseTestBase.RandomString(); var paymentProcessType = MultipleGatewayUtils.ProcessByTransactionDescription(db, randomDescription); var pp = (int)paymentProcessType; pp.ShouldBe(3); } }
private BackgroundCheckLabel CreateLabel(CMSDataContext db) { var Id = 10; if (db.BackgroundCheckLabels.Any()) { Id = db.BackgroundCheckLabels.Max(m => m.Id) + 1; } var bgChLabel = new BackgroundCheckLabel { Id = Id, Code = DatabaseTestBase.RandomString(), Description = "Description", Hardwired = false }; db.BackgroundCheckLabels.InsertOnSubmit(bgChLabel); db.SubmitChanges(); return(bgChLabel); }
public void Should_SubmitChanges_In_OneTimeLinks() { Guid id; using (var db = CMSDataContext.Create(DatabaseFixture.Host)) { OneTimeLink otl = new OneTimeLink { Id = Guid.NewGuid(), Querystring = DatabaseTestBase.RandomString(), Used = false, Expires = DateTime.Now.AddDays(1) }; db.OneTimeLinks.InsertOnSubmit(otl); db.SubmitChanges(); id = otl.Id; var result = db.OneTimeLinks.SingleOrDefault(o => o.Id == id); result.ShouldNotBeNull(); } }
public void Should_Get_Value_If_Not_In_Cache() { CmsSessionProvider sessionProvider = new CmsSessionProvider(db); string sessionId = DatabaseTestBase.RandomString(); sessionProvider.CurrentSessionId = sessionId; sessionProvider.Clear(); sessionProvider.Add("TESTKEY", "TEST VALUE"); string value = sessionProvider.Get <string>("TESTKEY"); // test retrieval from cache Assert.Equal("TEST VALUE", value); sessionProvider.CurrentSessionId = null; sessionProvider.Clear(); // only clears cache sessionProvider.CurrentSessionId = sessionId; // test retrieval from DB (key/value in cache no longer exists) value = sessionProvider.Get <string>("TESTKEY"); Assert.Equal("TEST VALUE", value); }
public static Person CreatePerson(int id, int positionInFamily, Family family = null) { if (family == null) { family = new Family() { CreatedDate = DateTime.Now }; } var child = new Person { PeopleId = id, Family = family, FirstName = DatabaseTestBase.RandomString(), LastName = DatabaseTestBase.RandomString(), EmailAddress = DatabaseTestBase.RandomString() + "@example.com", MemberStatusId = MemberStatusCode.Member, PositionInFamilyId = positionInFamily, }; return(child); }