public void Init()
		{
			EverythingAwareObject.InstanceCount = 0;
			EverythingAwareObjectFactoryPostProcessor.InstanceCount = 0;
			EverythingAwareObjectPostProcessor.InstanceCount = 0;
			_context = new MockApplicationContext("MockApplicationContextName");
		}
示例#2
0
 public void ChokesIfChildContextRegisteredUnderNameOfAnExistingContext()
 {
     MockApplicationContext original = new MockApplicationContext("original");
     ContextRegistry.RegisterContext(original);
     MockApplicationContext duplicate = new MockApplicationContext("original");
     ContextRegistry.RegisterContext(duplicate);
 }
	    public void ExecutesAllContextEventHandlersAndRethrowsExceptionsThrownDuringContextEventHandlingByDefault()
	    {
	        MockApplicationContext appCtx = new MockApplicationContext();
            bool secondHandlerExecuted = false;
            appCtx.ContextEvent += (sender, e) =>
            {
                throw new ApplicationException("dummy");
            };
            appCtx.ContextEvent += (sender,  e) =>
            {
                secondHandlerExecuted = true;
            };


	        ApplicationException resultException = null;
	        try
	        {
	            appCtx.PublishEvent(this, new ApplicationEventArgs());
                Assert.Fail();
	        }
	        catch (ApplicationContextException e)
	        {
	            resultException = (ApplicationException) e.GetBaseException();
	        }

            Assert.AreEqual("dummy", resultException.Message);
            Assert.IsTrue(secondHandlerExecuted);
        }
		public void AfterInitReturnsSameInstanceAsWasPassedIn()
		{
			MockApplicationContext ctx = new MockApplicationContext();
			ApplicationContextAwareProcessor processor = new ApplicationContextAwareProcessor(ctx);
			object obj = new object();
			object obj1 = processor.PostProcessAfterInitialization(obj, "MyContextAwareObject");
			Assert.AreEqual(obj, obj1, "Objects don't equal");
		}
		public void DoNotAttachContextForRegularObject()
		{
			MockApplicationContext ctx = new MockApplicationContext();
			ApplicationContextAwareProcessor processor = new ApplicationContextAwareProcessor(ctx);
			object obj = new object();
			object obj1 = processor.PostProcessBeforeInitialization(obj, "MyContextAwareObject");
			Assert.AreEqual(obj, obj1, "Objects don't equal");
		}
		public void AttachContext()
		{
			MockApplicationContext ctx = new MockApplicationContext();
			ApplicationContextAwareProcessor processor = new ApplicationContextAwareProcessor(ctx);
			MockContextAwareObject obj = new MockContextAwareObject();
			Assert.IsNull(obj.GetApplicationContext(), "Context Does Not Equal");
			MockContextAwareObject obj2 = (MockContextAwareObject) processor.PostProcessBeforeInitialization(obj, "MyContextAwareObject");
			Assert.AreEqual(ctx, obj2.GetApplicationContext(), "Context Does Not Equal");
		}
示例#7
0
        public void RegisterNamedRootContext()
        {
            const string           ctxName = "bingo";
            MockApplicationContext ctx     = new MockApplicationContext(ctxName);

            ContextRegistry.RegisterContext(ctx);
            IApplicationContext rootContext = ContextRegistry.GetContext();

            Assert.IsNotNull(rootContext,
                             "Root context is null even though a context has been registered.");
            Assert.AreEqual(ctxName, rootContext.Name,
                            "Root context name is different even though the root context has been registered under the lookup name.");
        }
示例#8
0
        public void RegisterNamedContext()
        {
            const string           ctxName = "bingo";
            MockApplicationContext ctx     = new MockApplicationContext(ctxName);

            ContextRegistry.RegisterContext(ctx);
            IApplicationContext context = ContextRegistry.GetContext(ctxName);

            Assert.IsNotNull(context,
                             "Named context is null even though a context has been registered under the lookup name.");
            Assert.IsTrue(Object.ReferenceEquals(ctx, context),
                          "Named context was not the same as the registered context (it must be).");
        }
示例#9
0
        public async Task DeleteAsyncTest()
        {
            //Arrange
            MockApplicationContext context = new MockApplicationContext()
                                             .MockGames()
                                             .MockFigures();

            //Act
            FigureManager manager     = new FigureManager(context.Object);
            var           result_good = await manager.DeleteAsync(ServiceDataToUse.Table.Id);

            //Assert
            Assert.IsTrue(result_good, "Failed while deleting figures for valid table.");
        }
        public void DoesNotSearchParentContextForEventRegistry()
        {
            IEventRegistry         eventRegistry = A.Fake <IEventRegistry>();
            MockApplicationContext parentCtx     = new MockApplicationContext("parentContext");

            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.EventRegistryObjectName, eventRegistry);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);

            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreSame(eventRegistry, parentCtx.EventRegistry);
            Assert.AreNotSame(eventRegistry, childContext.EventRegistry);
        }
示例#11
0
        public void GetAvailableGamesTest()
        {
            //Arrange
            var context = new MockApplicationContext()
                          .MockGames();

            Table table = ServiceDataToUse.Table;

            //Act
            var tableManager = new GameManager(context.Object);
            var result       = tableManager.GetAvailableGames(ServiceDataToUse.User.Id);

            //Assert
            Assert.AreEqual(result.Count(), 0, "Failed getting available tables.");
        }
示例#12
0
        public async Task FindByIdAsyncTest()
        {
            //Arrange
            MockApplicationContext context = new MockApplicationContext()
                                             .MockFigures();
            //Act
            FigureManager manager     = new FigureManager(context.Object);
            var           result_good = await manager.FindByIdAsync(ServiceDataToUse.Figure.Id);

            var result_bad = await manager.FindByIdAsync(123);

            //Assert
            Assert.IsNotNull(result_good, "Failed while getting figure with valid id.");
            Assert.IsNull(result_bad, "Can get figure with invalid id.");
        }
        public void DoesNotSearchParentContextForMessageSource()
        {
            IMessageSource         msgSource = A.Fake <IMessageSource>();
            MockApplicationContext parentCtx = new MockApplicationContext("parentContext");

            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.MessageSourceObjectName, msgSource);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);

            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreNotSame(msgSource, childContext.MessageSource);
            Assert.AreSame(msgSource, parentCtx.MessageSource);
            Assert.AreEqual(msgSource, ((IHierarchicalMessageSource)childContext.MessageSource).ParentMessageSource);
        }
示例#14
0
        public async Task DeleteAsyncTest()
        {
            //Arrange
            var context = new MockApplicationContext()
                          .MockGames();

            Game game = ServiceDataToUse.Game;

            //Act
            var gameManager = new GameManager(context.Object);
            var result      = await gameManager.DeleteAsync(game);

            //Assert
            Assert.IsTrue(result, "Failed while deleting table with new id.");
        }
        public void DoesNotSearchParentContextForEventRegistry()
        {
            MockRepository         mocks         = new MockRepository();
            IEventRegistry         eventRegistry = (IEventRegistry)mocks.DynamicMock(typeof(IEventRegistry));
            MockApplicationContext parentCtx     = new MockApplicationContext("parentContext");

            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.EventRegistryObjectName, eventRegistry);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);

            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreSame(eventRegistry, parentCtx.EventRegistry);
            Assert.AreNotSame(eventRegistry, childContext.EventRegistry);
        }
示例#16
0
        public async Task FindByIdTest()
        {
            //Arrange
            var context = new MockApplicationContext()
                          .MockGames();

            //Act
            var gameManager = new GameManager(context.Object);
            var result_good = await gameManager.FindByIdAsync(ServiceDataToUse.Table.Id);

            var result_bad = await gameManager.FindByIdAsync(123);

            //Assert
            Assert.IsNotNull(result_good, "Failed finding table with id.");
            Assert.IsNull(result_bad, "Succed finding table with bad id.");
        }
        public void DoesNotSearchParentContextForMessageSource()
        {
            MockRepository         mocks     = new MockRepository();
            IMessageSource         msgSource = (IMessageSource)mocks.DynamicMock(typeof(IMessageSource));
            MockApplicationContext parentCtx = new MockApplicationContext("parentContext");

            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.MessageSourceObjectName, msgSource);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);

            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreNotSame(msgSource, childContext.MessageSource);
            Assert.AreSame(msgSource, parentCtx.MessageSource);
            Assert.AreEqual(msgSource, ((IHierarchicalMessageSource)childContext.MessageSource).ParentMessageSource);
        }
示例#18
0
        public async Task CreateAsyncTest()
        {
            //Arrange
            MockApplicationContext context = new MockApplicationContext()
                                             .MockGames()
                                             .MockTables()
                                             .MockFigures();
            //Act
            FigureManager manager     = new FigureManager(context.Object);
            var           result_good = await manager.CreateAsync(ServiceDataToUse.Table.Id);

            var result_bad = await manager.CreateAsync(123);

            //Assert
            Assert.IsTrue(result_good, "Failed while creating figures for valid table.");
            Assert.IsFalse(result_bad, "Can create figures for invalid table.");
        }
示例#19
0
        public async Task CreateAsyncTest()
        {
            //Arrange
            var context = new MockApplicationContext()
                          .MockPlayerProfiles();

            PlayerProfile profile = new PlayerProfile {
                Id = ServiceDataToUse.User.PlayerProfile.Id
            };
            //Act
            var playerManager = new PlayerManager(context.Object);
            var result        = await playerManager.CreateAsync(profile);

            //Assert

            Assert.IsTrue(result, "Failed while creating player profile with new id.");
        }
示例#20
0
        public async Task TurnChangeTest()
        {
            //Arrange
            var good_game_id = ServiceDataToUse.Game.Id;
            var bad_game_id  = 123;

            var context = new MockApplicationContext()
                          .MockGames();

            //Act
            var gameManager = new GameManager(context.Object);
            var result_good = await gameManager.TurnChange(good_game_id, 2);

            var result_bad = await gameManager.TurnChange(bad_game_id, 2);

            //Assert
            Assert.IsTrue(result_good, "Failed while changing game with valid id.");
            Assert.IsFalse(result_bad, "Success while changing game with invalid id.");
        }
示例#21
0
        public async Task DeleteSingleFigureAsyncTest()
        {
            //Arrange
            MockApplicationContext context = new MockApplicationContext()
                                             .MockFigures();
            //Act
            FigureManager manager     = new FigureManager(context.Object);
            var           result_good = await manager.DeleteSomeFiguresAsync(new List <int> {
                ServiceDataToUse.Figure.Id
            });

            var result_bad = await manager.DeleteSomeFiguresAsync(new List <int> {
                123
            });

            //Assert
            Assert.IsTrue(result_good, "Failed while deleting figure with valid id.");
            Assert.IsFalse(result_bad, "Can delete figure with invalid id.");
        }
            public void Setup()
            {
                //ensure prior-registered contexts are removed
                ContextRegistry.Clear();

                _parentContext          = new MockApplicationContext();
                _parentContext.MockName = "parent";

                _childContext               = new MockApplicationContext(_parentContext);
                _childContext.MockName      = "child";
                _childContext.ParentContext = _parentContext;

                _grandChildContext               = new MockApplicationContext(_childContext);
                _grandChildContext.MockName      = "grandchild";
                _grandChildContext.ParentContext = _childContext;

                _greatGrandChildContext               = new MockApplicationContext(_grandChildContext);
                _greatGrandChildContext.MockName      = "greatgrandchild";
                _greatGrandChildContext.ParentContext = _grandChildContext;
            }
        public void ThrowsCannotLoadObjectTypeExceptionOnInvalidTypename()
        {
            try
            {
                MockApplicationContext       myContext     = new MockApplicationContext("myContext");
                DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory;
                XmlObjectDefinitionReader    reader        = new XmlObjectDefinitionReader(objectFactory);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test2' type='DOESNOTEXIST' />
</objects>
"));
                myContext.Refresh();
            }
            catch (Exception e)
            {
//            Console.WriteLine(e);
                Assert.IsInstanceOf(typeof(CannotLoadObjectTypeException), e);
            }
        }
        public void DoesNotSearchParentContextForMessageSource()
        {
            MockRepository mocks = new MockRepository();
            IMessageSource msgSource = (IMessageSource) mocks.DynamicMock(typeof (IMessageSource));
            MockApplicationContext parentCtx = new MockApplicationContext("parentContext");
            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.MessageSourceObjectName, msgSource);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);
            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreNotSame( msgSource, childContext.MessageSource );
            Assert.AreSame(msgSource, parentCtx.MessageSource);
            Assert.AreEqual(msgSource, ((IHierarchicalMessageSource)childContext.MessageSource).ParentMessageSource);
        }
 public void RegisterRootContext()
 {
     MockApplicationContext ctx = new MockApplicationContext();
     ContextRegistry.RegisterContext(ctx);
     IApplicationContext context = ContextRegistry.GetContext();
     Assert.IsNotNull(context,
         "Root context is null even though a context has been registered.");
     Assert.IsTrue(Object.ReferenceEquals(ctx, context),
         "Root context was not the same as the first context registered (it must be).");
 }
            public void RegisterContext_ConstructsNestedPathBasedNames_IfRegisteringAMixOfDefaultAndExplicitNamedContexts()
            {
                //modify the expected names for the decendent contexts for this one test
                string childContextInitialName = AbstractApplicationContext.DefaultRootContextName + "_CUSTOM";
                _expectedChildName = string.Format("{0}/{1}", _expectedParentName, childContextInitialName);
                _expectedGrandChildName = string.Format("{0}/{1}/{2}", _expectedParentName, _expectedChildName, AbstractApplicationContext.DefaultRootContextName);
                _expectedGreatGrandChildName = string.Format("{0}/{1}/{2}/{3}", _expectedParentName, _expectedChildName, _expectedGrandChildName, AbstractApplicationContext.DefaultRootContextName);

                //setup custom child instance for this one test
                _childContext = new MockApplicationContext(_expectedChildName);
                _childContext.MockName = "child";
                _childContext.ParentContext = _parentContext;
                _grandChildContext.ParentContext = _childContext;

                //register contexts in conflict with hierarchical order
                ContextRegistry.RegisterContext(_parentContext);
                ContextRegistry.RegisterContext(_childContext);
                ContextRegistry.RegisterContext(_grandChildContext);
                ContextRegistry.RegisterContext(_greatGrandChildContext);


                Assert.AreEqual(_expectedParentName, ContextRegistry.GetContext(_expectedParentName).Name);
                Assert.AreEqual(_expectedChildName, ContextRegistry.GetContext(_expectedChildName).Name);
                Assert.AreEqual(_expectedGrandChildName, ContextRegistry.GetContext(_expectedGrandChildName).Name);
                Assert.AreEqual(_expectedGreatGrandChildName, ContextRegistry.GetContext(_expectedGreatGrandChildName).Name);
            }
            public void Setup()
            {
                //ensure prior-registered contexts are removed
                ContextRegistry.Clear();

                _parentContext = new MockApplicationContext();
                _parentContext.MockName = "parent";

                _childContext = new MockApplicationContext(_parentContext);
                _childContext.MockName = "child";
                _childContext.ParentContext = _parentContext;

                _grandChildContext = new MockApplicationContext(_childContext);
                _grandChildContext.MockName = "grandchild";
                _grandChildContext.ParentContext = _childContext;

                _greatGrandChildContext = new MockApplicationContext(_grandChildContext);
                _greatGrandChildContext.MockName = "greatgrandchild";
                _greatGrandChildContext.ParentContext = _grandChildContext;
            }
 public void RegisterNamedContext()
 {
     const string ctxName = "bingo";
     MockApplicationContext ctx = new MockApplicationContext(ctxName);
     ContextRegistry.RegisterContext(ctx);
     IApplicationContext context = ContextRegistry.GetContext(ctxName);
     Assert.IsNotNull(context,
         "Named context is null even though a context has been registered under the lookup name.");
     Assert.IsTrue(Object.ReferenceEquals(ctx, context),
         "Named context was not the same as the registered context (it must be).");
 }
 public void RegisterNamedRootContext()
 {
     const string ctxName = "bingo";
     MockApplicationContext ctx = new MockApplicationContext(ctxName);
     ContextRegistry.RegisterContext(ctx);
     IApplicationContext rootContext = ContextRegistry.GetContext();
     Assert.IsNotNull(rootContext,
         "Root context is null even though a context has been registered.");
     Assert.AreEqual(ctxName, rootContext.Name,
         "Root context name is different even though the root context has been registered under the lookup name.");
 }
 public void ChokesIfChildContextRegisteredUnderNameOfAnExistingContext()
 {
     MockApplicationContext original = new MockApplicationContext("original");
     ContextRegistry.RegisterContext(original);
     MockApplicationContext duplicate = new MockApplicationContext("original");
     Assert.Throws<ApplicationContextException>(() => ContextRegistry.RegisterContext(duplicate));
 }
		private void PostProcessTProxiedObject(ProcessedObjectChecker test) 
		{
			AppDomain domain = null;
			try
			{
				AppDomainSetup setup = new AppDomainSetup();
				setup.ApplicationBase = Environment.CurrentDirectory;
				domain = AppDomain.CreateDomain("Spring", new Evidence(AppDomain.CurrentDomain.Evidence), setup);
				object foo = domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(MockContextAwareObject).FullName);
	
				MockApplicationContext ctx = new MockApplicationContext();
				ApplicationContextAwareProcessor processor = new ApplicationContextAwareProcessor(ctx);
				MockContextAwareObject afterFoo = (MockContextAwareObject) processor.PostProcessBeforeInitialization(foo, "MyContextAwareObject");
				test(afterFoo);
			}
			finally
			{
				try
				{
					AppDomain.Unload(domain);
				}
				catch (Exception ex)
				{
					Console.Write("Error unloading AppDomain used during testing : " + ex);
				}
			}
		}
		public void ReinitWithDiffContext()
		{
			MockApplicationContext ctx = new MockApplicationContext();
			ApplicationObjectSupport support = new MyApplicationObjectSupport(ctx);
			support.ApplicationContext = new MockApplicationContext();
		}
		public void Destroy()
		{
			_context.Dispose();
			_context = null;
		}
        public void ThrowsCannotLoadObjectTypeExceptionOnInvalidTypename()
        {
          try
          {
            MockApplicationContext myContext = new MockApplicationContext("myContext");
            DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory;
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(objectFactory);
            reader.LoadObjectDefinitions(new StringResource(
                                           @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test2' type='DOESNOTEXIST' />
</objects>
"));      
            myContext.Refresh();
          }
          catch (Exception e)
          {
//            Console.WriteLine(e);
            Assert.IsInstanceOf(typeof(CannotLoadObjectTypeException), e);
          }
        }
		public void DefaultObjectFactoryProcessorsDontGetAddedTwice()
		{
			MockApplicationContext myContext = new MockApplicationContext("myContext");
			DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory;
			Assert.AreEqual(0, objectFactory.ObjectPostProcessorCount);
			myContext.Refresh();
			int defaultProcessors = objectFactory.ObjectPostProcessors.Count;
			myContext.Refresh();
			Assert.AreEqual(defaultProcessors, objectFactory.ObjectPostProcessors.Count);
		}
 public void Destroy()
 {
     _context.Dispose();
     _context = null;
 }
        public void DoesNotSearchParentContextForEventRegistry()
        {
            MockRepository mocks = new MockRepository();
            IEventRegistry eventRegistry = (IEventRegistry)mocks.DynamicMock(typeof(IEventRegistry));
            MockApplicationContext parentCtx = new MockApplicationContext("parentContext");
            parentCtx.ObjectFactory.RegisterSingleton(AbstractApplicationContext.EventRegistryObjectName, eventRegistry);
            MockApplicationContext childContext = new MockApplicationContext("childContext", parentCtx);
            parentCtx.Refresh();
            childContext.Refresh();

            Assert.AreSame( eventRegistry, parentCtx.EventRegistry );
            Assert.AreNotSame( eventRegistry, childContext.EventRegistry );
        }
		public void ParentNotNullGrandparentNull()
		{
			IApplicationContext parentContext = new MockApplicationContext("MockApplicationContextParent");
			_context = new MockApplicationContext("MockApplicationContextName", parentContext);
			Assert.IsNotNull(_context.ParentContext, "parent is null");
			Assert.IsNull(_context.ParentContext.ParentContext, "parent is null");
		}
		public void ReinitWithSameContext()
		{
			MockApplicationContext ctx = new MockApplicationContext();
			ApplicationObjectSupport support = new MyApplicationObjectSupport(ctx);
			support.ApplicationContext = ctx;
			Assert.AreEqual(ctx, support.ApplicationContext);
		}