Пример #1
0
 public void InvalidTemplate_SameParameterTwiceThrows()
 {
     ExceptionAssert.Throws <ArgumentException>(
         () => TemplateParser.Parse("{aaa}/{AAA}"),
         "The route parameter name 'AAA' appears more than one time in the route template. (Parameter 'routeTemplate')");
 }
Пример #2
0
 public void UnclosedIndexer()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("Blah[0"); }, @"Path ended with open indexer.");
 }
Пример #3
0
 public void IndexerCloseInProperty()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("]"); }, "Unexpected character while parsing path: ]");
 }
Пример #4
0
 public void NoAtAfterOr()
 {
     ExceptionAssert.Throws <JsonException>(() => new JPath("[?(@.name||s"), "Unexpected character while parsing path query: s");
 }
Пример #5
0
 public void NoPathAfterDot2()
 {
     ExceptionAssert.Throws <JsonException>(() => new JPath("[?(@.name||@.)]"), @"Unexpected end while parsing path.");
 }
Пример #6
0
 public void RootWithBadWhitespace2()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("$. Blah"); }, @"Unexpected character while parsing path:  ");
 }
Пример #7
0
 public void BaddOr3()
 {
     ExceptionAssert.Throws <JsonException>(() => new JPath("[?(@.name|"), "Unexpected character while parsing path query: |");
 }
Пример #8
0
 public void TestWinsorizedMeanOfNullCollectionThrowsArgumentNullException()
 {
     ExceptionAssert.Throws <ArgumentNullException>(
         CalculateWinsorizedMeanOfNullCollection);
 }
Пример #9
0
 public void TestWinsorizedMeanOfEmptyCollectionThrowsInvalidOperationException()
 {
     ExceptionAssert.Throws <InvalidOperationException>(
         CalculateWinsorizedMeanOfEmptyCollection);
 }
 public void DeserializeUnexpectedEnd()
 {
     ExceptionAssert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <KeyValuePair <string, int> >(@"{""Key"": ""123"","), "Unexpected end when reading KeyValuePair. Path 'Key', line 1, position 14.");
 }
 public void DeserializeInvalidDataTable()
 {
     ExceptionAssert.Throws <JsonException>(() => JsonConvert.DeserializeObject <DataSet>("{\"pending_count\":23,\"completed_count\":45}"), "Unexpected JSON token when reading DataTable. Expected StartArray, got Integer. Path 'pending_count', line 1, position 19.");
 }
Пример #12
0
 public void InvalidTemplate_CatchAllMarkedOptional()
 {
     ExceptionAssert.Throws <ArgumentException>(
         () => TemplateParser.Parse("{a}/{*b?}"),
         "A catch-all parameter cannot be marked optional. (Parameter 'routeTemplate')");
 }
Пример #13
0
 public void InvalidTemplate_CannotContainQuestionMark()
 {
     ExceptionAssert.Throws <ArgumentException>(
         () => TemplateParser.Parse("foor?bar"),
         "The literal section 'foor?bar' is invalid. Literal sections cannot contain the '?' character. (Parameter 'routeTemplate')");
 }
Пример #14
0
 public void InvalidTemplate_CannotStartWithTilde()
 {
     ExceptionAssert.Throws <ArgumentException>(
         () => TemplateParser.Parse("~foo"),
         "The route template cannot start with a '~' character unless followed by a '/'. (Parameter 'routeTemplate')");
 }
Пример #15
0
 public void InvalidTemplate_CatchAllMarkedOptional()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("{a}/{*b?}"),
         "A catch-all parameter cannot be marked optional.");
 }
Пример #16
0
 public void InvalidTemplate_WithRepeatedParameter()
 {
     var ex = ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("{Controller}.mvc/{id}/{controller}"),
         "The route parameter name 'controller' appears more than one time in the route template.");
 }
Пример #17
0
 public void NoFieldNameAfterDot()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("$.Blah."); }, @"Unexpected end while parsing path.");
 }
Пример #18
0
 public void InvalidTemplate_CannotHaveMoreThanOneCatchAll()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("{*p1}/{*p2}"),
         "A catch-all parameter can only appear as the last segment of the route template.");
 }
Пример #19
0
 public void SinglePropertyAndFilterWithUnknownEscape()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath(@"Blah[ ?( @.name=='h\i' ) ]"); }, @"Unknown escape chracter: \i");
 }
Пример #20
0
 public void InvalidTemplate_SameParameterTwiceAndOneCatchAllThrows()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("{aaa}/{*AAA}"),
         "The route parameter name 'AAA' appears more than one time in the route template.");
 }
Пример #21
0
 public void BaddOr4()
 {
     ExceptionAssert.Throws <JsonException>(() => new JPath("[?(@.name||"), "Path ended with open query.");
 }
Пример #22
0
 public void InvalidTemplate_InvalidParameterNameWithOpenBracketThrows()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("{a}/{a{aa}/{z}"),
         "In a route parameter, '{' and '}' must be escaped with '{{' and '}}'.");
 }
Пример #23
0
 public void NoPathAfterAt()
 {
     ExceptionAssert.Throws <JsonException>(() => new JPath("[?(@.name||@"), @"Path ended with open query.");
 }
Пример #24
0
 public void InvalidTemplate_WithCatchAllNotAtTheEndThrows()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("foo/{p1}/{*p2}/{p3}"),
         "A catch-all parameter can only appear as the last segment of the route template.");
 }
Пример #25
0
 public void BadCharactersInIndexer()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("Blah[[0]].Two.Three[1].Four"); }, @"Unexpected character while parsing path indexer: [");
 }
Пример #26
0
 public void InvalidTemplate_CannotStartWithTilde()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("~foo"),
         "The route template cannot start with a '~' character unless followed by a '/'.");
 }
Пример #27
0
 public void EmptyIndexer()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("[]"); }, "Array index expected.");
 }
Пример #28
0
 public void InvalidTemplate_CannotContainQuestionMark()
 {
     ExceptionAssert.Throws <RoutePatternException>(
         () => RoutePatternParser.Parse("foor?bar"),
         "The literal section 'foor?bar' is invalid. Literal sections cannot contain the '?' character.");
 }
Пример #29
0
 public void MissingDotAfterIndexer()
 {
     ExceptionAssert.Throws <JsonException>(() => { new JPath("[1]Blah"); }, "Unexpected character following indexer: B");
 }
Пример #30
0
        static IEnumerable <CommandBaseTests.TestArgs <Command <T> > > _ExecutionSuccessful <T>()
        {
            var counter = new CommandBaseTests.CommandExecutionCounter();

            var reentrancyContainer = new CommandBaseTests.ReentrancyContainer <Command <T> >();

            void Execute(T arg)
            {
                counter.Execution++;

                if (reentrancyContainer.Command.RunningExecution != null)
                {
                    counter.RunningExecution++;

                    if (reentrancyContainer.Command.RunningExecution.CancelCommand != null)
                    {
                        counter.CancelCommand++;

                        if (reentrancyContainer.Command.RunningExecution.CancelCommand.CanExecute() == reentrancyContainer.IsCancelCommandEnabled)
                        {
                            counter.IsCancelCommandEnabled++;
                        }

                        if (Math.Abs(reentrancyContainer.Command.RunningExecution.Progress) < float.Epsilon)
                        {
                            counter.Progress++;
                        }
                    }
                }

                if (!reentrancyContainer.Command.CanExecute(default(T)))
                {
                    counter.CanExecuteWhileExecuting++;
                }

                // nested execution
                reentrancyContainer.Command.Execute(arg);
            }

            void ExecuteWithCancellationToken(T arg, CancellationToken cancellationToken)
            {
                if (cancellationToken.CanBeCanceled)
                {
                    counter.CanBeCanceled++;
                }
                if (!cancellationToken.IsCancellationRequested)
                {
                    counter.CancellationRequest++;
                }

                Execute(arg);
            }

            void ExecuteWithController(T arg, CommandExecutionController controller, CancellationToken cancellationToken)
            {
                if (controller != null)
                {
                    counter.Controller++;
                }

                if (controller.Execution == reentrancyContainer.Command.RunningExecution)
                {
                    counter.SameRunningExecution++;
                }

                ExecuteWithCancellationToken(arg, cancellationToken);

                ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => controller.ReportProgress(-0.1f), "value");
                ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => controller.ReportProgress(1.1f), "value");

                controller.ReportProgress(0.3f);
                if (Math.Abs(controller.Execution.Progress - 0.3f) < float.Epsilon)
                {
                    counter.ProgressReporting++;
                }

                controller.DisableCancelCommand();
                if (!controller.Execution.CancelCommand.CanExecute())
                {
                    counter.DisabledCancelCommand++;
                }

                ((IProgress <float>)controller).Report(-0.1f);
                ((IProgress <float>)controller).Report(1.1f);
                ((IProgress <float>)controller).Report(0.35f);
                if (Math.Abs(controller.Execution.Progress - 0.35f) < float.Epsilon)
                {
                    counter.ProgressReportingAsIProgress++;
                }

                reentrancyContainer.CapturedController = controller;
            }

            foreach (var args in GetTestArgs(reentrancyContainer, Execute, ExecuteWithCancellationToken, ExecuteWithController))
            {
                yield return(args);
            }

            Assert.AreEqual(reentrancyContainer.ExecutionCount, counter.Execution);
            Assert.AreEqual(counter.Execution, counter.RunningExecution);
            Assert.AreEqual(counter.Execution, counter.CancelCommand);
            Assert.AreEqual(counter.Execution, counter.IsCancelCommandEnabled);
            Assert.AreEqual(counter.Execution, counter.Progress);
            Assert.AreEqual(counter.Execution, counter.CanExecuteWhileExecuting);

            Assert.AreEqual(reentrancyContainer.ExecutionCount / 3 * 2, counter.CanBeCanceled);
            Assert.AreEqual(counter.CanBeCanceled, counter.CancellationRequest);

            Assert.AreEqual(reentrancyContainer.ExecutionCount / 3, counter.Controller);
            Assert.AreEqual(counter.Controller, counter.SameRunningExecution);
            Assert.AreEqual(counter.Controller, counter.ProgressReporting);
            Assert.AreEqual(counter.Controller, counter.ProgressReportingAsIProgress);
            Assert.AreEqual(counter.Controller, counter.DisabledCancelCommand);
        }