public void InvalidTypeWhenGetting() { ExceptionAssert.Throws<ArgumentException>(() => { HttpApplicationStateBase appState = new HttpApplicationStateWrapper(Activator.CreateInstance(typeof(HttpApplicationState), true) as HttpApplicationState); dynamic d = new DynamicHttpApplicationState(appState); var x = d[new object()]; }, WebPageResources.DynamicHttpApplicationState_UseOnlyStringOrIntToGet); }
public void InvalidNumberOfIndexes() { ExceptionAssert.Throws<ArgumentException>(() => { HttpApplicationStateBase appState = new HttpApplicationStateWrapper(Activator.CreateInstance(typeof(HttpApplicationState), true) as HttpApplicationState); dynamic d = new DynamicHttpApplicationState(appState); d[1, 2] = 3; }, WebPageResources.DynamicDictionary_InvalidNumberOfIndexes); ExceptionAssert.Throws<ArgumentException>(() => { HttpApplicationStateBase appState = new HttpApplicationStateWrapper(Activator.CreateInstance(typeof(HttpApplicationState), true) as HttpApplicationState); dynamic d = new DynamicHttpApplicationState(appState); var x = d[1, 2]; }, WebPageResources.DynamicDictionary_InvalidNumberOfIndexes); }
public void DynamicTest() { HttpApplicationStateBase appState = new HttpApplicationStateWrapper(Activator.CreateInstance(typeof(HttpApplicationState), true) as HttpApplicationState); dynamic d = new DynamicHttpApplicationState(appState); d["x"] = "y"; Assert.AreEqual("y", d.x); Assert.AreEqual("y", d[0]); d.a = "b"; Assert.AreEqual("b", d["a"]); d.Foo = "bar"; Assert.AreEqual("bar", d.Foo); Assert.AreEqual(null, d.XYZ); Assert.AreEqual(null, d["xyz"]); ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { var x = d[5]; }); }
/// <summary> /// Creates the and configure application di container. /// </summary> /// <returns> /// A StructureMap Container. /// </returns> protected override IContainer CreateAndConfigureApplicationDiContainer() { var appContainer = base.CreateAndConfigureApplicationDiContainer(); var applicationState = new HttpApplicationStateWrapper(_applicationState); appContainer.Configure(x => x.For<HttpApplicationStateBase>().Singleton().Use(applicationState)); return appContainer; }