private static void CleanupContextAndConfigurations() { ApplicationContext.AuthenticationType = null; ApplicationContext.DataPortalActivator = null; ConfigurationManager.AppSettings["CslaDataPortalActivator"] = null; ConfigurationManager.AppSettings["CslaDataPortalProxy"] = null; ConfigurationManager.AppSettings["CslaMobileFactoryLoader"] = null; ConfigurationManager.AppSettings["CslaDataPortalProxyFactory"] = null; ConfigurationManager.AppSettings["CslaReader"] = null; FactoryDataPortal.FactoryLoader = null; ApplicationContext.DataPortalReturnObjectOnException = true; DataPortalExceptionHandler.ExceptionInspector = null; Csla.Server.DataPortal.InterceptorType = null; ApplicationContext.DataPortalProxyFactory = string.Empty; ApplicationContext.DataPortalProxy = null; CslaReaderWriterFactory.SetCslaWriterType(null); CslaReaderWriterFactory.SetCslaReaderType(null); ConfigurationManager.AppSettings["CslaReader"] = null; ApplicationContext.RuleSet = null; Csla.Configuration.ConfigurationManager.AppSettings["CslaWriter"] = null; ApplicationContext.UseReflectionFallback = true; ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml; ApplicationContext.DefaultTransactionIsolationLevel = TransactionIsolationLevel.ReadCommitted; ApplicationContext.DefaultTransactionTimeoutInSeconds = 90; ConfigurationManager.AppSettings["CslaSerializationFormatter"] = "MobileFormatter"; new Csla.Configuration.CslaConfiguration() .PropertyChangedMode(Csla.ApplicationContext.PropertyChangedModes.Xaml) .PropertyInfoFactory(null) .RuleSet(null) .UseReflectionFallback(true); ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml; ConfigurationManager.AppSettings["CslaDefaultTransactionIsolationLevel"] = null; ApplicationContext.Clear(); }
public void Test_LogicalExecution_Values() { ApplicationContext.Clear(); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Client, ApplicationContext.LogicalExecutionLocation, "Default value of 'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Client'"); var dataPortal = new Server.DataPortal(); dataPortal.Create(typeof(LogicalExecutionTestBusiness), null, new DataPortalContext(null, false), true).Wait(); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Server, (ApplicationContext.LogicalExecutionLocations)ApplicationContext.GlobalContext["LogicalExecutionDataPortalTests_Create"], "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Server' DURING 'Create'"); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Client, ApplicationContext.LogicalExecutionLocation, "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Client' AFTER 'Create'"); ApplicationContext.Clear(); dataPortal.Fetch(typeof(LogicalExecutionTestBusiness), null, new DataPortalContext(null, false), true).Wait(); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Server, (ApplicationContext.LogicalExecutionLocations)ApplicationContext.GlobalContext["LogicalExecutionDataPortalTests_Fetch"], "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Server' DURING 'Fetch'"); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Client, ApplicationContext.LogicalExecutionLocation, "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Client' AFTER 'Fetch'"); ApplicationContext.Clear(); dataPortal.Delete(typeof(LogicalExecutionTestBusiness), null, new DataPortalContext(null, false), true).Wait(); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Server, (ApplicationContext.LogicalExecutionLocations)ApplicationContext.GlobalContext["LogicalExecutionDataPortalTests_Delete"], "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Server' DURING 'Delete'"); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Client, ApplicationContext.LogicalExecutionLocation, "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Client' AFTER 'Delete'"); ApplicationContext.Clear(); dataPortal.Update(new LogicalExecutionTestBusiness(), new DataPortalContext(null, false), true).Wait(); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Server, (ApplicationContext.LogicalExecutionLocations)ApplicationContext.GlobalContext["LogicalExecutionDataPortalTests_Update"], "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Server' DURING 'Update'"); Assert.AreEqual(ApplicationContext.LogicalExecutionLocations.Client, ApplicationContext.LogicalExecutionLocation, "'ApplicationContext.LogicalExecutionLocation' must be 'LogicalExecutionLocations.Client' AFTER 'Update'"); }
/// <summary> /// Clears the application context and current principal. /// </summary> public static void ClearContext() { ApplicationContext.Clear(); if (ApplicationContext.AuthenticationType != "Windows") { ApplicationContext.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(string.Empty), new string[] { }); } }
public void SimpleTest() { ApplicationContext.Clear(); ApplicationContext.ClientContext["v1"] = "client"; ApplicationContext.GlobalContext["v2"] = "client"; SimpleRoot root = SimpleRoot.GetSimpleRoot("data"); Assert.AreEqual("client", ApplicationContext.ClientContext["v1"], "client context didn't roundtrip"); Assert.AreEqual("client", ApplicationContext.GlobalContext["v2"], "global context didn't roundtrip"); Assert.AreEqual("Fetched", ApplicationContext.GlobalContext["Root"], "global context missing server value"); }
public void TestAppContextAcrossDifferentThreads() { List <AppContextThread> AppContextThreadList = new List <AppContextThread>(); List <Thread> ThreadList = new List <Thread>(); for (int x = 0; x < 10; x++) { AppContextThread act = new AppContextThread("Thread: " + x); AppContextThreadList.Add(act); Thread t = new Thread(new ThreadStart(act.Run)); t.Name = "Thread: " + x; t.Start(); ThreadList.Add(t); } ApplicationContext.Clear(); Exception ex = null; try { foreach (AppContextThread act in AppContextThreadList) { //We are accessing the Client/GlobalContext via this thread, therefore //it should be removed. Assert.AreEqual(true, act.Removed); } //We are now accessing the shared value. If any other thread //loses its Client/GlobalContext this will turn to true //Assert.AreEqual(false, AppContextThread.StaticRemoved); } catch (Exception e) { ex = e; } finally { foreach (AppContextThread act in AppContextThreadList) { act.Stop(); } foreach (Thread t in ThreadList) { t.Join(); } } if (ex != null) { throw ex; } }
public void TestOnDemandContexts() { //Make sure its all clear completely Csla.ApplicationContext.Clear(); System.LocalDataStoreSlot slot; Assert.IsNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNull(Thread.GetData(slot), "GlobalContext should be null"); //Add to the GlobalContext but NOT the ClientContext ApplicationContext.GlobalContext.Add("Test", "Test"); Assert.IsNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should be null"); //Add to the ClientContext but NOT the GlobalContext Csla.ApplicationContext.Clear(); ApplicationContext.ClientContext.Add("Test", "Test"); Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNull(Thread.GetData(slot), "GlobalContext should be null"); //Add to both contexts Csla.ApplicationContext.Clear(); ApplicationContext.ClientContext.Add("Test", "Test"); ApplicationContext.GlobalContext.Add("Test", "Test"); Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should be null"); //Now clear ONLY the GlobalContext Csla.ApplicationContext.GlobalContext.Clear(); Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); //The global context should still exist, it is just empty now slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should be null"); //Now add an item to the GlobalContext and clear only the ClientContext ApplicationContext.GlobalContext.Add("Test", "Test"); ApplicationContext.ClientContext.Clear(); //the clientcontext should still exist, its just empty now. Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should be null"); //Now Clear all again and make sure they're gone ApplicationContext.Clear(); Assert.IsNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "ClientContext should be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNull(Thread.GetData(slot), "GlobalContext should be null"); }
private static void ClearContext(DataPortalContext context) { // if the dataportal is not remote then // do nothing if (!context.IsRemotePortal) { return; } ApplicationContext.Clear(); if (ApplicationContext.AuthenticationType != "Windows") { ApplicationContext.User = null; } }
private void ClearContext(DataPortalContext context) { ApplicationContext.SetLogicalExecutionLocation(_oldLocation); // if the dataportal is not remote then // do nothing if (!context.IsRemotePortal) { return; } ApplicationContext.Clear(); if (ApplicationContext.AuthenticationType != "Windows") { ApplicationContext.User = null; } }
public void ClearContexts() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.ClientContext.Clear(); //put stuff into the application context ApplicationContext.ClientContext.Add("Test", "Test"); ApplicationContext.GlobalContext.Add("Test", "Test"); //it should NOT be null System.LocalDataStoreSlot slot; Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "Csla.ClientContext should not be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should not be null"); //Do a generic clear ApplicationContext.Clear(); //cleared, this stuff should be null now Assert.IsNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "Csla.ClientContext should not be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNull(Thread.GetData(slot), "GlobalContext should not be null"); //put stuff into the Application context ApplicationContext.ClientContext.Add("Test", "Test"); ApplicationContext.GlobalContext.Add("Test", "Test"); //Should NOT be null Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "Csla.ClientContext should not be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should not be null"); //clearing each individually instead of with ApplicationContext.Clear(); ApplicationContext.ClientContext.Clear(); ApplicationContext.GlobalContext.Clear(); //put stuff into ApplicationContext ApplicationContext.ClientContext.Add("Test", "Test"); ApplicationContext.GlobalContext.Add("Test", "Test"); //should NOT be null Assert.IsNotNull(AppDomain.CurrentDomain.GetData("Csla.ClientContext"), "Csla.ClientContext should not be null"); slot = Thread.GetNamedDataSlot("Csla.GlobalContext"); Assert.IsNotNull(Thread.GetData(slot), "GlobalContext should not be null"); }
public void FailDeleteContext() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.Clear(); ExceptionRoot root = null; try { ExceptionRoot.DeleteExceptionRoot("fail"); Assert.Fail("Exception didn't occur"); } catch (DataPortalException ex) { root = (ExceptionRoot)ex.BusinessObject; Assert.AreEqual("Fail delete", ex.GetBaseException().Message, "Base exception message incorrect"); Assert.IsTrue(ex.Message.StartsWith("DataPortal.Delete failed"), "Exception message incorrect"); } Assert.IsNull(root, "Business object returned"); Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved"); }
public void FailCreateContext() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.Clear(); ExceptionRoot root; try { root = ExceptionRoot.NewExceptionRoot(); Assert.Fail("Exception didn't occur"); } catch (DataPortalException ex) { Assert.IsNull(ex.BusinessObject, "Business object shouldn't be returned"); Assert.AreEqual("Fail create", ex.GetBaseException().Message, "Base exception message incorrect"); Assert.IsTrue(ex.Message.StartsWith("DataPortal.Create failed"), "Exception message incorrect"); } Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved"); }
public void DataPortalEvents() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.Clear(); ApplicationContext.GlobalContext["global"] = "global"; Csla.DataPortal.DataPortalInvoke += new Action <DataPortalEventArgs>(OnDataPortaInvoke); Csla.DataPortal.DataPortalInvokeComplete += new Action <DataPortalEventArgs>(OnDataPortalInvokeComplete); Csla.Test.Basic.Root root = Csla.Test.Basic.Root.GetRoot("testing"); Csla.DataPortal.DataPortalInvoke -= new Action <DataPortalEventArgs>(OnDataPortaInvoke); Csla.DataPortal.DataPortalInvokeComplete -= new Action <DataPortalEventArgs>(OnDataPortalInvokeComplete); //Populated in the handlers below Assert.AreEqual("global", Csla.ApplicationContext.GlobalContext["ClientInvoke"], "Client invoke incorrect"); Assert.AreEqual("global", Csla.ApplicationContext.GlobalContext["ClientInvokeComplete"], "Client invoke complete"); //populated in the Root Dataportal handlers. Assert.AreEqual("global", Csla.ApplicationContext.GlobalContext["dpinvoke"], "Server invoke incorrect"); Assert.AreEqual("global", Csla.ApplicationContext.GlobalContext["dpinvokecomplete"], "Server invoke compelte incorrect"); }
public void TearDown() { ApplicationContext.Clear(); }
public void ClearContextsAfterEachTest() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.Clear(); }
public void SetScopedSp() { ApplicationContext.GlobalContext.Clear(); ApplicationContext.Clear(); }