public void FORBIDDEN_same_block()
 {
     new Action(() =>
     {
         var env = new TestEnvironment();
         env.Add <Block>();
         env.Add <Block>();
     }).Should().Throw <ArgumentException>();
 }
Пример #2
0
        public void mark_v2()
        {
            var env = new TestEnvironment();

            env.Add <Block>("mark");
            env.Add <Block2>();
            env.Remove <Block>("mark");

            env.registrations.Should().HaveCount(1);
            env.registrations.SingleOrDefault(e => e.BlockType == typeof(Block2))
            .Should().NotBeNull();
        }
Пример #3
0
        public async Task block_consume_data_produced_by_executed_block()
        {
            var env = new TestEnvironment();

            env.Add <BlockProducesDateTime>();
            env.Add <BlockConsumeDateTime>();
            await env.Build();

            var block = (BlockConsumeDateTime)env.blocks.Single(e => e is BlockConsumeDateTime);

            block.Time.Should().Be(DateTime.Today);
        }
Пример #4
0
        public async Task block_access_to_executed_block()
        {
            var env = new TestEnvironment();

            env.Add <BlockWithData>();
            env.Add <BlockAccesToBlock>();
            await env.Build("hello");

            var block = (BlockAccesToBlock)env.blocks.Single(e => e is BlockAccesToBlock);

            block.Block.Should().NotBeNull();
            block.Block.Data.Should().Be("hello");
        }
        public void multiple()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.Add <Block2>();
            env.Add <Block>("mark1");
            env.Add <Block>("mark2");

            env.RemoveAll <Block>();

            env.registrations.All(e => e.BlockType != typeof(Block));
        }
Пример #6
0
        public async Task mark_idx_1_setup()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.InsertAt <Block2>(1, "mark", block2 =>
            {
                block2.Should().BeOfType <Block2>();
                block2.Should().NotBeNull();
                block2.Property = "a";
            });

            var reg = env.registrations.SingleOrDefault(e => e.BlockType == typeof(Block2));

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block2>();
            reg.Mark.Should().Be("mark");

            (env.registrations.ToArray()[1].BlockType == typeof(Block2)).Should().BeTrue();

            await env.Build();

            var inst = (Block2)env.blocks.SingleOrDefault(e => e is Block2);

            inst.Should().NotBeNull();
            inst.Property.Should().Be("a");
        }
        public async Task setup()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.Insert <Block, Block2>(InsertMode.Before, block2 =>
            {
                block2.Should().BeOfType <Block2>();
                block2.Should().NotBeNull();
                block2.Property = "a";
            });

            var reg = env.registrations.SingleOrDefault(e => e.BlockType == typeof(Block2));

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block2>();
            reg.Mark.Should().BeNull();

            await env.Build();

            var inst = (Block2)env.blocks.SingleOrDefault(e => e is Block2);

            inst.Should().NotBeNull();
            inst.Property.Should().Be("a");
        }
        public async Task mark_setup()
        {
            var env = new TestEnvironment();

            env.Add <Block>("mark", block =>
            {
                block.Should().BeOfType <Block>();
                block.Should().NotBeNull();
                block.Property = "a";
            });

            env.IndexOf <Block>().Should().Be(-1);
            env.IndexOf <Block>("mark").Should().Be(0);

            var reg = env.registrations.FirstOrDefault();

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block>();
            reg.Mark.Should().Be("mark");

            await env.Build();

            var inst = (Block)env.blocks.FirstOrDefault();

            inst.Should().NotBeNull();
            inst.Property.Should().Be("a");
        }
Пример #9
0
        public async Task setup_markToAdd()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.Replace <Block>(block =>
            {
                block.Should().BeOfType <Block>();
                block.Should().NotBeNull();
                block.Property = "a";
            }, markToAdd: "mark");


            var reg = env.registrations.SingleOrDefault(e => e.BlockType == typeof(Block));

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block>();
            reg.Mark.Should().Be("mark");

            await env.Build();

            var inst = (Block)env.blocks.SingleOrDefault(e => e is Block);

            inst.Should().NotBeNull();
            inst.Property.Should().Be("a");
        }
        public async Task setup_env()
        {
            var env = new TestEnvironment();

            env.Add <Block>();

            env.Update <Block>((block, testEnv) =>
            {
                block.Should().BeOfType <Block>();
                block.Should().NotBeNull();
                testEnv.Should().NotBeNull();
                block.Property = "a";
            });

            var reg = env.registrations.FirstOrDefault();

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block>();
            reg.Mark.Should().BeNull();

            await env.Build();

            var inst = (Block)env.blocks.FirstOrDefault();

            inst.Should().NotBeNull();
            inst.Property.Should().Be("a");
        }
        public void markToFind()
        {
            var env = new TestEnvironment();

            env.Add <Block>("mark");
            env.Insert <Block, Block2>(InsertMode.Before, "mark");
            env.IndexOf <Block2>().Should().Be(0);
        }
Пример #12
0
        public void mark()
        {
            var env = new TestEnvironment();

            env.Add <Block>("mark");
            env.Remove <Block>("mark");

            env.registrations.Should().BeEmpty();
        }
        public void single()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.RemoveAll <Block>();

            env.registrations.Should().BeEmpty();
        }
Пример #14
0
        public async Task with_extra_data()
        {
            var env = new TestEnvironment();

            env.Add <BlockWithData>();
            await env.Build("hello");

            var block = (BlockWithData)env.blocks.Single(e => e is BlockWithData);

            block.Data.Should().Be("hello");
        }
            public async Task Test()
            {
                await using var env = new TestEnvironment();
                env.Add <InitializeIoc>(block =>
                {
                    block.AddSingleton <IUserRepository, MockedUserRepository>();
                    block.AddTransient <IGetUserById, GetUserById>();
                });
                await env.Build();

                await SampleTest(env);
            }
        public void check_arguments()
        {
            var env = new TestEnvironment();

            new Action(() => { env.Add <Block>(mark: null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add((Action <Block, ITestEnvironment>)null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add(null, (Action <Block, ITestEnvironment>)null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add("mark", (Action <Block, ITestEnvironment>)null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add((Action <Block>)null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add(null, (Action <Block>)null); }).Should().Throw <ArgumentNullException>();
            new Action(() => { env.Add("mark", (Action <Block>)null); }).Should().Throw <ArgumentNullException>();
        }
Пример #17
0
        public async Task private_blocks_are_not_supported_FORBIDDEN()
        {
            try
            {
                var env = new TestEnvironment();
                env.Add <PrivBlock>();
                await env.Build();
            }
            catch (AggregateException e)
            {
                e.InnerException.Should().BeOfType <RuntimeBinderException>();
                return;
            }

            throw new Exception("Missing exception.");
        }
        public async Task break_pipeline()
        {
            var output = new List <string>();
            var env    = new TestEnvironment();

            env.Add <ExecuteLogic>((block, builder) => { block.Logic = () => { output.Add("1 message"); }; })
            .Add <BreakBlock>()
            .Add <ExecuteLogic>(Guid.NewGuid().ToString(), (block, builder) => { block.Logic = () => { output.Add("2 message"); }; });

            await env.Build();

            await env.CreateTest();

            output.Contains("1 message").Should().BeTrue();
            output.Contains("2 message").Should().BeFalse();
        }
        public void after_before()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.Insert <Block, Block2>(InsertMode.Before);

            env.IndexOf <Block>().Should().Be(1);
            env.IndexOf <Block2>().Should().Be(0);

            env = new TestEnvironment();
            env.Add <Block>();
            env.Insert <Block, Block2>(InsertMode.After);

            env.IndexOf <Block>().Should().Be(0);
            env.IndexOf <Block2>().Should().Be(1);
        }
        public async Task insert_into_pipeline()
        {
            var output = new List <string>();
            var mark   = Guid.NewGuid().ToString();

            var env = new TestEnvironment();

            env.Add <ExecuteLogic>((block, builder) => { block.Logic = () => { output.Add("1 message"); }; })
            .Add <ExecuteLogic>(mark, (block, builder) => { block.Logic = () => { output.Add("2 message"); }; });

            env.Insert <ExecuteLogic, BreakBlock>(InsertMode.Before, mark);

            await env.Build();

            await env.CreateTest();

            output.Contains("1 message").Should().BeTrue();
            output.Contains("2 message").Should().BeFalse();
        }
Пример #21
0
        public async Task empty_idx_1()
        {
            var env = new TestEnvironment();

            env.Add <Block>();
            env.InsertAt <Block2>(1);

            var reg = env.registrations.SingleOrDefault(e => e.BlockType == typeof(Block2));

            reg.Should().NotBeNull();
            reg.BlockType.Should().Be <Block2>();
            reg.Mark.Should().BeNull();

            (env.registrations.ToArray()[1].BlockType == typeof(Block2)).Should().BeTrue();

            await env.Build();

            var inst = (Block2)env.blocks.SingleOrDefault(e => e is Block2);

            inst.Should().NotBeNull();
            inst.Property.Should().BeNull();
        }
Пример #22
0
        public TestPlan(string testPlanFileName, string applicationConfigPath, string testCaseConfigPath, string webDriversPath, string tempFilePath,
                        string emailFrom, string emailPassword, string emailTo, string ccTo, string emailHost, int emailPort, bool enableSsl, Func <string[]> attachmentGetter = null)
        {
            _applicationConfigPath = applicationConfigPath;
            _testcaseConfigPath    = testCaseConfigPath;
            _tempFilePath          = tempFilePath;
            _webDriversPath        = webDriversPath;
            _emailFrom             = emailFrom;
            _emailPassword         = emailPassword;
            _emailTo          = emailTo;
            _ccTo             = ccTo;
            _emailHost        = emailHost;
            _emailPort        = emailPort;
            _enableSsl        = enableSsl;
            _attachmentGetter = attachmentGetter;

            if (!File.Exists(testPlanFileName))
            {
                throw new Exception("Test Plan is not found.");
            }

            _name     = Path.GetFileNameWithoutExtension(testPlanFileName);
            TestCases = new List <string>();

            _testCaseStatus = new DataTable();
            _testCaseStatus.Columns.Add("Index");
            _testCaseStatus.Columns.Add("Test Case");
            _testCaseStatus.Columns.Add("Description");
            _testCaseStatus.Columns.Add("Status");
            _testCaseStatus.Columns.Add("Result");
            _testCaseStatus.Columns.Add("Exception");
            _testCaseStatus.Columns.Add("Image");

            using (StreamReader sr = new StreamReader(testPlanFileName, System.Text.Encoding.Default))
            {
                string line = sr.ReadLine();
                if (line == null)
                {
                    throw new Exception("errors in test plan file: " + testPlanFileName);
                }

                try
                {
                    foreach (string parameter in line.Split(';'))
                    {
                        string environmentApp  = parameter.Split(',')[0];
                        string environmentType = parameter.Split(',')[1];
                        string paraNameAPP     = environmentApp.Split(':')[0];
                        string paraValueAPP    = environmentApp.Split(':')[1];
                        string paraNameType    = environmentType.Split(':')[0];
                        string paraValueType   = environmentType.Split(':')[1];
                        TestEnvironment.Add(paraValueAPP, paraValueType);
                        //switch (paraName)
                        //{
                        //    case "Application":
                        //        TestEnvironment.Add(paraValue, null);
                        //        break;
                        //    case "BrowserType":
                        //        TestEnvironment.va
                        //        BrowserType = paraValue;
                        //        break;
                        //}
                    }
                    int i = 0;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("--") || string.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        i++;
                        string testcasefilename = Path.Combine(testCaseConfigPath, line);
                        if (!File.Exists(testcasefilename))
                        {
                            throw new Exception(testcasefilename + " is not existed in testing folder");
                        }
                        TestCases.Add(testcasefilename);

                        DataRow dr = _testCaseStatus.NewRow();
                        dr["Index"]     = i;
                        dr["Test Case"] = testcasefilename;
                        dr["Status"]    = "Ready";

                        using (StreamReader srTestCase = new StreamReader(testcasefilename))
                        {
                            string testcaseLine = srTestCase.ReadLine();
                            if (!string.IsNullOrEmpty(testcaseLine) && testcaseLine.StartsWith("--"))
                            {
                                dr["Description"] = testcaseLine.Substring(2);
                            }
                            //check all lines of testcases, make the inner testcase in test case is correct.
                            while ((testcaseLine = srTestCase.ReadLine()) != null)
                            {
                                if (testcaseLine.ToLower().StartsWith("innertestcase"))
                                {
                                    List <string> parameters            = CommonHelper.SplitCommand(testcaseLine, " ");
                                    string        innerTestcasefilename = Path.Combine(testCaseConfigPath, parameters[1]);
                                    if (!File.Exists(innerTestcasefilename))
                                    {
                                        throw new Exception("Test case \"" + line + "\" in the plan has inner testcase " + innerTestcasefilename + " , but " + innerTestcasefilename + " is not existed in testing folder");
                                    }
                                }
                            }
                        }

                        _testCaseStatus.Rows.Add(dr);
                    }
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }