Example #1
0
        public static void VerifyBaseline(string baselinePath, string actualContent)
        {
            string expectedContentPath = GetExpectedContentPath(baselinePath);
            string expectedContent     = File.ReadAllText(expectedContentPath);

            if (!string.Equals(expectedContent, actualContent))
            {
                string actualContentRootFolder = Path.GetFullPath("ActualBaselines");
                string actualContentPath       = Path.Combine(actualContentRootFolder, baselinePath + ".txt");

                // Recompute the actual folder in case baselinePath contained directories.
                string actualContentCompleteFolder = Path.GetDirectoryName(actualContentPath);
                if (!Directory.Exists(actualContentCompleteFolder))
                {
                    Directory.CreateDirectory(actualContentCompleteFolder);
                }

                File.WriteAllText(actualContentPath, actualContent);

                // TODO GitHubIssue#45 : Improve baseline test
                Assert.True(false, string.Format(
                                "The Response.Content is not correct. \r\nExpected:\r\n{0}\r\n\r\nActual:\r\n{1}\r\n\r\n" +
                                "Run the following command to update the baselines:  \r\nCopy /y {2} {3}\r\n",
                                expectedContent,
                                actualContent,
                                actualContentPath,
                                BaselineHelpers.GetExpectedContentPathInSourceControl(baselinePath)));
            }
        }
Example #2
0
        public static async Task CheckResponse(
            HttpResponseMessage response,
            HttpStatusCode expectedStatusCode,
            string baselineFileName,
            Func <string, string> postProcessContentHandler = null)
        {
            string content = await BaselineHelpers.GetFormattedContent(response);

            Assert.Equal(expectedStatusCode, response.StatusCode);

            if (content != null)
            {
                if (postProcessContentHandler != null)
                {
                    content = postProcessContentHandler(content);
                }

                BaselineHelpers.VerifyBaseline(baselineFileName, content);
            }
            else
            {
                BaselineHelpers.VerifyBaselineDoesNotExist(baselineFileName);
            }
        }