public void TestMultipleOfSame()
        {
            commandBinder.Bind <NoArgSignal>().To <NoArgSignalCommand>().To <NoArgSignalCommand>();

            TestModel testModel = injectionBinder.GetInstance <TestModel>() as TestModel;

            Assert.AreEqual(0, testModel.StoredValue);
            NoArgSignal signal = injectionBinder.GetInstance <NoArgSignal>() as NoArgSignal;

            signal.Dispatch();
            Assert.AreEqual(2, testModel.StoredValue);             //first command gives 1, second gives 2
        }
        public void TestNoArgs()
        {
            commandBinder.Bind <NoArgSignal>().To <NoArgSignalCommand>();

            TestModel testModel = injectionBinder.GetInstance <TestModel>() as TestModel;

            Assert.AreEqual(testModel.StoredValue, 0);

            NoArgSignal signal = injectionBinder.GetInstance <NoArgSignal>() as NoArgSignal;

            signal.Dispatch();
            Assert.AreEqual(testModel.StoredValue, 1);
        }
Example #3
0
        public void TestUnbindWithoutUsage()
        {
            commandBinder.Bind <NoArgSignal>().To <NoArgSignalCommand>();
            TestModel testModel = injectionBinder.GetInstance <TestModel>() as TestModel;

            Assert.AreEqual(testModel.StoredValue, 0);

            commandBinder.Unbind <NoArgSignal>();

            NoArgSignal signal = injectionBinder.GetInstance <NoArgSignal>() as NoArgSignal;

            signal.Dispatch();
            Assert.AreEqual(testModel.StoredValue, 0); //Should do nothing
        }
        public void TestInterruptedSequence()
        {
            //CommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer>().ToSingleton();

            //Bind the trigger to the command
            commandBinder.Bind <NoArgSignal>().To <CommandWithInjection>().To <FailCommand>().To <CommandWithoutExecute>().InSequence();

            TestDelegate testDelegate = delegate
            {
                NoArgSignal signal = injectionBinder.GetInstance <NoArgSignal>() as NoArgSignal;
                signal.Dispatch();
            };

            //That the exception is not thrown demonstrates that the last command was interrupted
            Assert.DoesNotThrow(testDelegate);

            //That the value is 100 demonstrates that the first command ran
            ISimpleInterface instance = injectionBinder.GetInstance <ISimpleInterface>() as ISimpleInterface;

            Assert.AreEqual(100, instance.intValue);
        }
        public void TestSequence()
        {
            //CommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer>().ToSingleton();

            //Bind the trigger to the command
            commandBinder.Bind <NoArgSignal>().To <CommandWithInjection>().To <CommandWithExecute>().To <CommandWithoutExecute>().InSequence();

            TestDelegate testDelegate = delegate
            {
                NoArgSignal signal = injectionBinder.GetInstance <NoArgSignal>() as NoArgSignal;
                signal.Dispatch();
            };

            //That the exception is thrown demonstrates that the last command ran
            CommandException ex = Assert.Throws <CommandException>(testDelegate);

            Assert.AreEqual(ex.type, CommandExceptionType.EXECUTE_OVERRIDE);

            //That the value is 100 demonstrates that the first command ran
            ISimpleInterface instance = injectionBinder.GetInstance <ISimpleInterface>() as ISimpleInterface;

            Assert.AreEqual(100, instance.intValue);
        }