Esempio n. 1
0
        public async Task CanRunWithKey()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyAsyncHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new CommandWithKeyAsync();

            int initialCount = cmd.Keys.Count;

            bool allAreTrue = true;
            int  callCount  = 0;

            var result = await tasqR.RunAsync(cmd);

            foreach (var item in result)
            {
                callCount++;
                if (!item)
                {
                    allAreTrue = false;
                }
            }

            Assert.AreEqual(initialCount, callCount);
            Assert.IsTrue(allAreTrue);
        }
Esempio n. 2
0
        public async Task CanRunWithReturn()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <TestCmdWithReturnForAsyncHandler>();
            var tasqR = new TasqR(handlerResolver);
            var cmd   = new TestCmdWithReturnForAsync(2);

            var result = await tasqR.RunAsync(cmd);

            Assert.AreEqual(3, result);
        }
Esempio n. 3
0
        public void CanRunWithKeyBaseType()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyHandler>();

            var tasqR    = new TasqR(handlerResolver);
            var instance = Activator.CreateInstance(typeof(CommandWithKey));

            tasqR.Run((ITasq <int, bool>)instance);

            Assert.IsTrue(((CommandWithKey)instance).AllAreCorrect);
        }
Esempio n. 4
0
        public void CanRunWithKey()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new CommandWithKey();

            tasqR.Run(cmd);

            Assert.IsTrue(cmd.AllAreCorrect);
        }
Esempio n. 5
0
        public void CanRunWithReturnForAsyncHandler()
        {
            int startNumber     = 8;
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <TestCmdWithReturnForAsyncHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new TestCmdWithReturnForAsync(startNumber);

            int finalNumber = tasqR.Run(cmd);

            Assert.AreEqual(9, finalNumber);
        }
Esempio n. 6
0
        public void CanRunWithReturn()
        {
            int startNumber     = 8;
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <SampleCommandWithReturnHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new SampleCommandWithReturn(startNumber);

            int finalNumber = tasqR.Run(cmd);

            Assert.AreEqual(9, finalNumber);
        }
Esempio n. 7
0
        public void CanRunWithKeyForAsyncHandlerBaseType()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyAsyncHandler>();

            var tasqR    = new TasqR(handlerResolver);
            var instance = (ITasq)Activator.CreateInstance(typeof(CommandWithKeyAsync));


            tasqR.Run(instance);

            Assert.IsTrue(true);
        }
Esempio n. 8
0
        public async Task CanRunWithoutReturn()
        {
            var testModel = new Test3Model {
                StartNumber = 10
            };
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithAsyncWithoutReturnHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new CommandWithAsyncWithoutReturn(testModel);

            await tasqR.RunAsync(cmd);

            Assert.AreEqual(11, testModel.StartNumber);
        }
Esempio n. 9
0
        public void CanRunWithoutReturn()
        {
            var testModel = new TestModel {
                SampleNumber = 10
            };
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <SampleCommandWithoutReturnHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new SampleCommandWithoutReturn(testModel);

            tasqR.Run(cmd);

            Assert.AreEqual(11, testModel.SampleNumber);
        }
Esempio n. 10
0
        public async Task WillThrowExceptionFromAsyncHandler()
        {
            try
            {
                var handlerResolver = new TasqHandlerResolver();

                handlerResolver.Register <TestWithErrorCmdHandler>();
                var tasqR = new TasqR(handlerResolver);

                var cmd = new TestWithErrorCmd();
                await tasqR.RunAsync(cmd);
            }
            catch (AggregateException ex)
            {
                throw ex.GetBaseException();
            }
        }
Esempio n. 11
0
        public void CannotRunDefaultCmdWithHandlerWithNoParamlessConstructor()
        {
            try
            {
                var handlerResolver = new TasqHandlerResolver();

                handlerResolver.Register <CmdHandlerWithNoParamlessCtorHandler>();
                var tasqR = new TasqR(handlerResolver);

                var cmd = new CmdHandlerWithNoParamlessCtor();
                tasqR.Run(cmd);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("No parameterless constructor defined for type"));

                throw;
            }
        }
Esempio n. 12
0
        public async Task CanRunWithKeyBaseType()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyAsyncHandler>();

            var tasqR    = new TasqR(handlerResolver);
            var instance = (ITasq <int, bool>)Activator.CreateInstance(typeof(CommandWithKeyAsync));

            bool allAreTrue = true;

            foreach (var item in await tasqR.RunAsync(instance))
            {
                if (!item)
                {
                    allAreTrue = false;
                }
            }

            Assert.IsTrue(allAreTrue);
        }
Esempio n. 13
0
        public void CanRunWithKeyForAsyncHandler()
        {
            var handlerResolver = new TasqHandlerResolver();

            handlerResolver.Register <CommandWithKeyAsyncHandler>();

            var tasqR = new TasqR(handlerResolver);
            var cmd   = new CommandWithKeyAsync();

            bool allAreTrue = true;

            foreach (var item in tasqR.Run(cmd))
            {
                if (!item)
                {
                    allAreTrue = false;
                }
            }

            Assert.IsTrue(allAreTrue);
        }