public void CustomParser()
        {
            var args = new TestArguments();

            CommandLineParser.Parse(new[] { "|foo|" }, args).Should().BeTrue();
            args.Value.Should().Be("foo");
        }
Ejemplo n.º 2
0
        private static IEnumerable<TestResult> GetResult(TestArguments arguments)
        {
            //Prepare data
            var blockCollection = new BlockCollection<int>();
            for (int i = 0; i < BlockCount; i++)
            {
                blockCollection.Add(GetFilledBlock(ElementsInBlockCount));
            }

            var blockStructure = new ArrayMap<int>(new FixedBalancer(),  blockCollection);

            //Prepare measure engine
            var method = GetMethodInfo(arguments.MethodName);

            foreach (var currentCount in arguments.TestCountArray)
            {
                List<object> argumentList = new List<object> { blockStructure, currentCount};

                //Get middle estimation of several times calling
                long timeOfAllInvoketionsMs = 0;
                int countOfInvokations = 3;

                for (int i = 0; i < countOfInvokations; i++)
                {
                    timeOfAllInvoketionsMs += MeasureEngine.MeasureStaticMethod(method, argumentList);
                }

                yield return new TestResult(currentCount, timeOfAllInvoketionsMs / countOfInvokations);
            }
        }
Ejemplo n.º 3
0
        public async Task CommandParametersGetsBinded()
        {
            var rootCommand = new RootCommand();

            rootCommand.AddOption(new Option("--someoption")
            {
                Argument = new Argument <bool>()
            });

            var context    = new InvocationContext(new Parser(rootCommand).Parse("--someoption"), Substitute.For <IConsole>());
            var testParams = new TestArguments();

            var sut = new PretzelCommandHandler(
                Substitute.For <IConfiguration>(),
                testParams,
                new ExportFactory <Logic.Commands.ICommand, CommandInfoAttribute>(
                    () => Tuple.Create(
                        Substitute.For <Logic.Commands.ICommand>(),
                        new Action(() => { })
                        ), new CommandInfoAttribute()));

            await sut.InvokeAsync(context);

            Assert.True(testParams.SomeOption);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Tests the invoke SQLCMD returns error for arithmetic overflow error.
        /// </summary>
        public void Should_RAISERROR_on_arithmetic_overflow(TestContext testContext)
        {
            var initArgs = new TestArguments
            {
                Query            = "SELECT convert(int,100000000000)",
                ConnectionString =
                    new[]
                { $"{this.SqlServerInstanceInfo.GetServerConnection()};Application Name={testContext.TestName}" }
            };

            using (var impl = new SqlExecuteImpl(initArgs))
            {
                try
                {
                    impl.Execute();
                }
                catch (Exception e)
                {
                    if (e.InnerException is SqlException sqlException)
                    {
                        Assert.AreEqual(ArithmeticOverflowError, sqlException.Number);
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 5
0
        private static IEnumerable <TestResult> GetResult(TestArguments arguments)
        {
            //Prepare data
            var blockCollection = new BlockCollection <int>();

            for (int i = 0; i < BlockCount; i++)
            {
                blockCollection.Add(GetFilledBlock(ElementsInBlockCount));
            }

            var blockStructure = new ArrayMap <int>(new FixedBalancer(), blockCollection);

            //Prepare measure engine
            var method = GetMethodInfo(arguments.MethodName);

            foreach (var currentCount in arguments.TestCountArray)
            {
                List <object> argumentList = new List <object> {
                    blockStructure, currentCount
                };

                //Get middle estimation of several times calling
                long timeOfAllInvoketionsMs = 0;
                int  countOfInvokations     = 3;

                for (int i = 0; i < countOfInvokations; i++)
                {
                    timeOfAllInvoketionsMs += MeasureEngine.MeasureStaticMethod(method, argumentList);
                }

                yield return(new TestResult(currentCount, timeOfAllInvoketionsMs / countOfInvokations));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Tests the insert does not execute twice on not null violation base.
        /// </summary>
        /// <param name="testContext">The test context.</param>
        public void Test_InsertDoesNotExecuteTwiceOnNotNullViolationBase(TestContext testContext)
        {
            var initArgs = new TestArguments
            {
                Query            = TestUtils.LoadSqlResource("RunStackOverflow33271446"),
                ConnectionString =
                    new[]
                {
                    $"{this.SqlServerInstanceInfo.GetServerConnection()};Database={TestUtils.DatabaseName};Application Name={testContext.TestName}"
                },
                QueryTimeout    = 1,
                AbortOnErrorSet = true
            };

            using (var impl = new SqlExecuteImpl(initArgs))
            {
                try
                {
                    impl.Execute();
                }
                catch (SqlException e)
                {
                    Assert.AreEqual(InsertNullInNotNullColumn, e.Number);
                }
            }

            // Now assert only one row was inserted into table 's'
            Debug.WriteLine("Asserting that only one row was inserted");
            Assert.AreEqual(
                1,
                TestUtils.ExecuteScalar <int>(
                    $"{this.SqlServerInstanceInfo.GetServerConnection()};Database={TestUtils.DatabaseName};Application Name=RESULT_{testContext.TestName}",
                    "select count(*) from s"),
                "More than one row inserted/");
        }
Ejemplo n.º 7
0
        public void CustomParser()
        {
            var args = new TestArguments();

            CommandLineParser.Parse(new[] { "|foo|" }, args).Should().BeTrue();
            args.Value.Should().Be("foo");
        }
        private static void AssertValidArguments(TestArguments arguments)
        {
            Assert.NotNull(arguments);

            Assert.Equal(PrimitiveTypeTestValues.Byte, arguments.Byte);
            Assert.Equal(PrimitiveTypeTestValues.Short, arguments.Short);
            Assert.Equal(PrimitiveTypeTestValues.Int, arguments.Int);
            Assert.Equal(PrimitiveTypeTestValues.Long, arguments.Long);

            Assert.Equal(PrimitiveTypeTestValues.Float, arguments.Float);
            Assert.Equal(PrimitiveTypeTestValues.Double, arguments.Double);

            Assert.Equal(PrimitiveTypeTestValues.Decimal, arguments.Decimal);

            Assert.Equal(PrimitiveTypeTestValues.Bool, arguments.Bool);

            Assert.Equal(PrimitiveTypeTestValues.DateTime, arguments.DateTime);

            Assert.Equal(PrimitiveTypeTestValues.Char, arguments.Char);
            Assert.Equal(PrimitiveTypeTestValues.String, arguments.String);

            Assert.Equal(PrimitiveTypeTestValues.String, arguments.RequiredString);

            Assert.True(arguments.Toggle);
        }
Ejemplo n.º 9
0
        public void CustomFormatter()
        {
            var args = new TestArguments {
                Value = "foo"
            };

            CommandLineParser.Format(args).Should().Equal("|foo|");
        }
        public void FillProperty_StringProperty_IsParsedCorrectly()
        {
            const string testValue = "TestValue";

            var typeParsers = new List <TypeParser>()
            {
                new StringTypeParser()
            };

            var property  = typeof(TestArguments).GetTypeInfo().DeclaredProperties.First(a => a.Name == "RequiredString");
            var arguments = new TestArguments();

            ArgumentPropertiesHelper.FillProperty(arguments, property, testValue, typeParsers);

            Assert.Equal(testValue, arguments.RequiredString);
        }
Ejemplo n.º 11
0
        private static void TestParse(CommandLineParser target, string commandLine, string arg1 = null, int arg2 = 42, bool notSwitch = false, string arg3 = null,
                                      int arg4     = 47, float arg5   = 0.0f, string arg6 = null, bool arg7 = false, DayOfWeek[] arg8 = null, int?arg9 = null,
                                      bool[] arg10 = null, bool?arg11 = null, int[] arg12 = null, Dictionary <string, int> arg13 = null,
                                      Dictionary <string, int> arg14 = null, KeyValuePair <string, int>?arg15 = null, bool helpArg = false)
        {
            string[]      args   = commandLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // not using quoted arguments in the tests, so this is fine.
            TestArguments result = (TestArguments)target.Parse(args);

            Assert.AreEqual(arg1, result.Arg1);
            Assert.AreEqual(arg2, result.Arg2);
            Assert.AreEqual(arg3, result.Arg3);
            Assert.AreEqual(arg4, result.Arg4);
            Assert.AreEqual(arg5, result.Arg5);
            Assert.AreEqual(arg6, result.Arg6);
            Assert.AreEqual(arg7, result.Arg7);
            CollectionAssert.AreEqual(arg8, result.Arg8);
            Assert.AreEqual(arg9, result.Arg9);
            CollectionAssert.AreEqual(arg10, result.Arg10);
            Assert.AreEqual(arg11, result.Arg11);
            if (arg12 == null)
            {
                Assert.AreEqual(0, result.Arg12.Count);
            }
            else
            {
                CollectionAssert.AreEqual(arg12, result.Arg12);
            }
            CollectionAssert.AreEqual(arg13, result.Arg13);
            if (arg14 == null)
            {
                Assert.AreEqual(0, result.Arg14.Count);
            }
            else
            {
                CollectionAssert.AreEqual(arg14, (System.Collections.ICollection)result.Arg14);
            }
            if (arg15 == null)
            {
                Assert.AreEqual(default(KeyValuePair <string, int>), result.Arg15);
            }
            else
            {
                Assert.AreEqual(arg15.Value, result.Arg15);
            }

            Assert.AreEqual(helpArg, result.HelpArg1);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Tests the invoke SQLCMD does not return sp name nor line when error occurs in procedure.
        /// </summary>
        public void Should_report_stored_procedure_details_in_error_raised_within_an_executing_procedure(TestContext testContext)
        {
            var initArgs = new TestArguments
            {
                Query =
                    TestUtils.LoadSqlResource(
                        "InvokeSqlcmdDoesNotReturnSpNameNorLineWhenErrorOccursInProcedure"),
                ConnectionString =
                    new[]
                {
                    $"{this.SqlServerInstanceInfo.GetServerConnection()};Database={TestUtils.DatabaseName};Application Name=1_{testContext.TestName}"
                }
            };

            using (var impl = new SqlExecuteImpl(initArgs))
            {
                // Create error proc
                impl.Execute();
            }

            // ReSharper disable once StringLiteralTypo
            initArgs.Query            = "EXEC dbo.geterror";
            initArgs.ConnectionString =
                new[]
            { $"{this.SqlServerInstanceInfo.GetServerConnection()};Database={TestUtils.DatabaseName};Application Name=2_{testContext.TestName}" };

            using (var impl = new SqlExecuteImpl(initArgs))
            {
                try
                {
                    // Execute error proc
                    impl.Execute();
                }
                catch (Exception e)
                {
                    if (e.InnerException is SqlException sqlException)
                    {
                        // ReSharper disable once StringLiteralTypo
                        Assert.AreEqual("geterror", sqlException.Procedure);
                        return;
                    }

                    throw;
                }
            }
        }
        public void ParseVerbWithOptionsAnd2Options_WorksFine()
        {
            //******** GIVEN
            string[]  arguments = new string[] { @"/copy --src='C:\Temp\Pluto'", "--singleOutput", "--v=WARN" };
            Exception thrownEx  = null;

            //******** WHEN
            TestArguments parsed = this._Parser.UseAggregatedArguments().Parse <TestArguments>(arguments);

            //******** ASSERT
            thrownEx = this._Parser.GetLastError();
            string message = thrownEx == null ? "" : thrownEx.Message;

            Assert.IsNull(thrownEx, message);
            Assert.IsTrue(parsed.UseSingleFileAsOutput, "Wrong value for UseSingleFileAsOutput");
            Assert.IsFalse(String.IsNullOrEmpty(parsed.Verbosity), "Wrong value for Verbosity: cannot be null");
            Assert.AreEqual("WARN", parsed.Verbosity, "Wrong value for Verbosity");
            Assert.IsNotNull(parsed.CopyWithArguments);
            Assert.AreEqual(@"'C:\Temp\Pluto'", parsed.CopyWithArguments.SrcFolder, "Wrong value for CopyWithArguments.SrcFolder");
        }
Ejemplo n.º 14
0
        public void AddTestArgumentsToTestResult(TestArguments arguments)
        {
            this.testResults.arguments = arguments;
            bool hasProjectPath = false;

            foreach (string arg in arguments.args)
            {
                if (hasProjectPath)
                {
                    TestProjectName = arg;
                    break;
                }
                if (arg.Equals("-projectPath"))
                {
                    hasProjectPath = true;
                }
            }
            this.testResults.suites[0].name = TestProjectName;
            this.testResults.suites[0].minimalCommandLine = arguments.args;
        }
        public void ParsingVerbWithoutArguments_ReturnsThatClass()
        {
            //******** GIVEN
            string[]  arguments = new string[] { "/copy" };
            Exception thrownEx  = null;

            //******** WHEN
            TestArguments parsed = this._Parser.Parse <TestArguments>(arguments);

            //******** ASSERT
            thrownEx = this._Parser.GetLastError();
            string message = "Expected no exception at this stage";

            if (thrownEx != null)
            {
                message += (": " + thrownEx.Message);
            }
            Assert.IsNull(thrownEx, message);
            Assert.IsNotNull(parsed);
        }
        public async Task StopExectionIfCancellationIsRequested()
        {
            var contextBag = ApFrameworkHelper.GetEmptyBag();

            var testArgs = new TestArguments();
            CancellationTokenSource source = new CancellationTokenSource();

            testArgs.CancellationTokenSource  = source;
            testArgs.CancellationMatchStrinig = "2";


            contextBag.Add("testObj", testArgs);

            var request   = new Request <string>(ProcessRequest);
            var processor = new RequestProcessor();

            processor.AddAddtionalAction(Last, AddtionalActionSequence.Last);
            processor.AddAddtionalAction(First, AddtionalActionSequence.First); // 0
            processor.AddAddtionalAction(BeforeAuth, AddtionalActionSequence.BeforeAuthorization);
            processor.AddAddtionalAction(AfterAuth, AddtionalActionSequence.AfterAuthorization);
            processor.AddAddtionalAction(BeforeVal, AddtionalActionSequence.BeforeValidation);
            processor.AddAddtionalAction(AfterVal, AddtionalActionSequence.AfterValidation);
            processor.AddAddtionalAction(BeforeProcess, AddtionalActionSequence.BeforeRequestProcessing);
            processor.AddAddtionalAction(AfterProcess, AddtionalActionSequence.AfterRequestProcessing);


            await processor.ProcessRequestAsync(request, contextBag, source.Token);

            var updatedObj = contextBag["testObj"] as TestArguments;

            for (int i = 0; i < 3; i++)
            {
                Assert.True(updatedObj.Logs[i] == i.ToString());
            }

            for (int i = 3; i < 9; i++)
            {
                Assert.True(string.IsNullOrEmpty(updatedObj.Logs[i]));
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Tests the invoke SQLCMD does return raised error if query was run in single user mode.
        /// </summary>
        public void Should_correctly_RAISERROR_when_database_set_to_single_user_mode(TestContext testContext)
        {
            var initArgs = new TestArguments
            {
                Query = TestUtils.LoadSqlResource(
                    "InvokeSqlcmdDoesNotReturnRaisedErrorIfQueryWasRunInSingleUserMode"),
                ConnectionString =
                    new[]
                { $"{this.SqlServerInstanceInfo.GetServerConnection()};Application Name={testContext.TestName}" }
            };

            using (var impl = new SqlExecuteImpl(initArgs))
            {
                try
                {
                    impl.Execute();
                }
                catch (SqlException e)
                {
                    Assert.AreEqual("First Error.", e.Message);
                }
            }
        }
        /// <summary>
        /// Parse test arguments from unity log
        /// </summary>
        /// <param name="processor"></param>
        public void TryParseTestArguments(UnityTestRunnerResultsProcessor processor)
        {
            var arguments       = new TestArguments();
            var listOfArguments = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader(processor.LogFilePath))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        if (line.Contains(testArgumentsHeader))
                        {
                            string arg = sr.ReadLine();
                            arg = sr.ReadLine();    // The first line below header is Unity.exe, skip this
                            while (!arg.StartsWith(testArgumentsTailPrefix, StringComparison.CurrentCultureIgnoreCase))
                            {
                                listOfArguments.Add(arg);
                                arg = sr.ReadLine();
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                arguments.args = listOfArguments;
                processor.AddTestArgumentsToTestResult(arguments);
            }
        }
Ejemplo n.º 19
0
        public static void TestBinarySearch()
        {
            TestArguments arg = new TestArguments("BinarySearch", CallFlag.FillTestCollection, new[] { HUNDRED, THOUSAND, THOUSAND * 10, THOUSAND * 100 });

            WriteResult("BinarySearch", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }
Ejemplo n.º 20
0
        public static void TestFor()
        {
            TestArguments arg = new TestArguments("For", CallFlag.FillTestCollection, new[] { 1, 4 });

            WriteResult("For", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }
Ejemplo n.º 21
0
        public static void TestIndexOf()
        {
            TestArguments arg = new TestArguments("IndexOf", CallFlag.FillTestCollection, new[] { 10, HUNDRED, THOUSAND, THOUSAND * 10 });

            WriteResult("IndexOf", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }
Ejemplo n.º 22
0
        public static void TestLastIndexOf()
        {
            TestArguments arg = new TestArguments("LastIndexOf", CallFlag.FillTestCollection, new[] { 1, 2, 5, 10 });

            WriteResult("LastIndexOf", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }
Ejemplo n.º 23
0
 public void CustomFormatter()
 {
     var args = new TestArguments { Value = "foo" };
     CommandLineParser.Format(args).Should().ContainInOrder("|foo|");
 }
 public void SetUp()
 {
     _arguments = new TestArguments();
     _parser = null;
 }
Ejemplo n.º 25
0
        public static void TestAddRange()
        {
            TestArguments arg = new TestArguments("AddRange", CallFlag.ClearTestCollection, new[] { THOUSAND, MILLION / 100, MILLION / 10, MILLION });

            WriteResult("AddRange", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }
Ejemplo n.º 26
0
 public List <TestResult> GetResult(TestArguments arguments)
 {
     return(GetResult(arguments.MethodName, arguments.CallFlag, arguments.TestCountArray).ToList());
 }
Ejemplo n.º 27
0
        public static void TestContains()
        {
            TestArguments arg = new TestArguments("Contains", CallFlag.FillTestCollection, new[] { HUNDRED, THOUSAND, MILLION / 100 });

            WriteResult("Contains", GetBigioEngine().GetResult(arg), GetWintellectEngine().GetResult(arg), GetListEngine().GetResult(arg));
        }