示例#1
0
        public void ShouldSuccessfullyExecuteAllTestcases()
        {
            var testcasesDir = Path.GetFullPath($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}.." +
                                                $"{Path.DirectorySeparatorChar}Matching{Path.DirectorySeparatorChar}ResponseTests{Path.DirectorySeparatorChar}BodyTests{Path.DirectorySeparatorChar}Testcases{Path.DirectorySeparatorChar}");

            var testcaseFiles = Directory.GetFiles(testcasesDir);

            var failedCases = new List <string>();

            foreach (var file in testcaseFiles)
            {
                var testcase = JsonConvert.DeserializeObject <Testcase>(File.ReadAllText(file));
                if (file.Split(Path.DirectorySeparatorChar).Last().StartsWith("pro"))
                {
                    List <string> differences = BodyMatcher.Match(testcase.Expected.Body, testcase.Actual.Body, testcase.Expected.MatchingRules);
                    if (differences.Any() == testcase.Match)
                    {
                        failedCases.Add(file.Split(Path.DirectorySeparatorChar).Last());
                        failedCases.AddRange(differences.Select(d => "- " + d));
                    }
                    else if (testcase.ExpectedMessage != null && !differences.Contains(testcase.ExpectedMessage))
                    {
                        failedCases.Add(file.Split(Path.DirectorySeparatorChar).Last());
                        failedCases.Add($"- Expected message was not returned. Expected: {testcase.ExpectedMessage}, actual: {differences.First()}");
                    }
                }
            }

            Assert.AreEqual(0, failedCases.Count, "Failed cases: " + Environment.NewLine + string.Join(Environment.NewLine, failedCases));
        }
 private async Task SetupRequestBodyExpectation(BodyMatcher requestBody)
 {
     await MockServerClient
     .When(Request()
           .WithMethod(HttpMethod.Post)
           .WithBody(requestBody),
           Times.Unlimited())
     .RespondAsync(Response()
                   .WithStatusCode(200)
                   .WithBody("response")
                   .WithDelay(TimeSpan.Zero)
                   );
 }
示例#3
0
文件: Nock.cs 项目: plog17/nock.net
        private nock SetMethod(string path, Method method, string body = null, Func <string, bool> bodyMatcherString = null, Type bodyMatcherType = null, object bodyMatcherFunc = null)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Path must be defined");
            }

            if (!path.StartsWith("/"))
            {
                throw new ArgumentException("Path must start with a '/'");
            }

            if (_method != Method.NotSet)
            {
                throw new Exception("The method of the nock has already been set!");
            }

            _path   = path;
            _method = method;

            _body = body;
            _bodyMatcherString = bodyMatcherString;
            _bodyMatcherType   = bodyMatcherType;
            _bodyMatcherFunc   = bodyMatcherFunc;

            if (_body != null)
            {
                _bodyMatcher = BodyMatcher.Body;
            }
            else if (_bodyMatcherString != null)
            {
                IsCorrectlyReferencedFunction(_bodyMatcherString);
                _bodyMatcher = BodyMatcher.StringFunc;
            }
            else if (_bodyMatcherType != null)
            {
                IsCorrectlyReferencedFunction(_bodyMatcherFunc);
                _bodyMatcher = BodyMatcher.TypedFunc;
            }

            return(this);
        }
示例#4
0
        /// <summary>
        /// Matches a Kinect body to a set of gestures within the app.
        /// </summary>
        /// <param name="kinectJoints">Body representation</param>
        /// <param name="jumpToNextPose">synthesizes a new body in correct position if true</param>
        /// <returns></returns>
        public static List <GestureStatus> TestBody(BodyMatcher matcher,
                                                    IReadOnlyDictionary <Microsoft.Kinect.JointType,
                                                                         Microsoft.Kinect.Joint> kinectJoints,
                                                    bool jumpToNextPose = false)
        {
            // convert Kinect.Body to Z3Body
            var body = new Z3Body();

            if (!jumpToNextPose)
            {
                body = Z3KinectConverter.CreateZ3Body(kinectJoints);
            }
            else
            {
                //body = GetCopiedBodyValues(this.Gestures[this.GetMostAdvancedGesturesIDs()[0]].GetTarget().Body);
                var firstGestureBody = matcher.GetLastGestureTarget().Body;
                body = new Z3Body(firstGestureBody);
            }

            return(matcher.TestBody(body));
        }
示例#5
0
 internal List <string> Match(object actualMessage)
 {
     return(BodyMatcher.Match(Contents, actualMessage, MatchingRules));
 }
示例#6
0
 public HttpRequest WithBody(BodyMatcher bodyMatcher)
 {
     Body = bodyMatcher;
     return(this);
 }