public void IgnoresAlreadyPopulatedState() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); MockRepository mocks = new MockRepository(); ISharedStateFactory ssf1 = mocks.StrictMock <ISharedStateFactory>(); ISharedStateAware ssa = (ISharedStateAware)mocks.DynamicMock(typeof(ISharedStateAware)); SharedStateAwareProcessor ssap = new SharedStateAwareProcessor(); ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1 }; of.RegisterSingleton("ssap", ssap); using (Record(mocks)) { // preset SharedState - ssap must ignore it Expect.Call(ssa.SharedState).Return(new Hashtable()); // expect nothing else! } using (Playback(mocks)) { ssap.PostProcessBeforeInitialization(ssa, "myPage"); } }
public void BeforeInitializationIsNoOp() { SharedStateAwareProcessor ssap = new SharedStateAwareProcessor(); object res = ssap.PostProcessBeforeInitialization(this, null); Assert.AreSame(this, res); }
public void ProbesSharedStateFactories() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); MockRepository mocks = new MockRepository(); ISharedStateFactory ssf1 = mocks.StrictMock <ISharedStateFactory>(); ISharedStateFactory ssf2 = mocks.StrictMock <ISharedStateFactory>(); ISharedStateFactory ssf3 = mocks.StrictMock <ISharedStateFactory>(); ISharedStateFactory ssf4 = mocks.StrictMock <ISharedStateFactory>(); IDictionary ssf3ProvidedState = new Hashtable(); SharedStateAwareProcessor ssap = new SharedStateAwareProcessor(); ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1, ssf2, ssf3, ssf4 }; of.RegisterSingleton("ssap", ssap); ISharedStateAware ssa = (ISharedStateAware)mocks.DynamicMock(typeof(ISharedStateAware)); // Ensure we iterate over configured SharedStateFactories until // the first provider is found that // a) true == provider.CanProvideState( instance, name ) // b) null != provider.GetSharedState( instance, name ) using (Record(mocks)) { Expect.Call(ssa.SharedState).Return(null); Expect.Call(ssf1.CanProvideState(ssa, "pageName")).Return(false); Expect.Call(ssf2.CanProvideState(ssa, "pageName")).Return(true); Expect.Call(ssf2.GetSharedStateFor(ssa, "pageName")).Return(null); Expect.Call(ssf3.CanProvideState(ssa, "pageName")).Return(true); Expect.Call(ssf3.GetSharedStateFor(ssa, "pageName")).Return(ssf3ProvidedState); Expect.Call(ssa.SharedState = ssf3ProvidedState); } using (Playback(mocks)) { ssap.PostProcessBeforeInitialization(ssa, "pageName"); } }
public void DoesNotAllowNullOrEmptyFactoryList() { // check default ctor init SharedStateAwareProcessor ssap = new SharedStateAwareProcessor(); Assert.IsNotNull(ssap.SharedStateFactories); Assert.AreEqual(0, ssap.SharedStateFactories.Length); // check we accept a list at all ssap = new SharedStateAwareProcessor(new ISharedStateFactory[] { new ByTypeSharedStateFactory() }, Int32.MaxValue); // now ensure that SharedStateFactories will never be null or empty ssap = new SharedStateAwareProcessor(); try { ssap.SharedStateFactories = null; Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } try { ssap.SharedStateFactories = new ISharedStateFactory[0]; Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } try { ssap.SharedStateFactories = new ISharedStateFactory[] { null }; Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } try { ssap = new SharedStateAwareProcessor(null, Int32.MaxValue); Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } try { ssap = new SharedStateAwareProcessor(new ISharedStateFactory[0], Int32.MaxValue); Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } try { ssap = new SharedStateAwareProcessor(new ISharedStateFactory[] { null }, Int32.MaxValue); Assert.Fail("should throw ArgumentException"); } catch (ArgumentException) { } }