diff --git a/lambda/MAS.Tests/Infrastructure/Extensions.cs b/lambda/MAS.Tests/Infrastructure/Extensions.cs deleted file mode 100644 index b27f72e3..00000000 --- a/lambda/MAS.Tests/Infrastructure/Extensions.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Shouldly; -using System.Diagnostics; -using System.IO; -using System.Text; - -namespace MAS.Tests.Infrastructure -{ - public static class Extensions - { - public static void ShouldMatchApproved(this string content, - [System.Runtime.CompilerServices.CallerMemberName] string memberName = null, - [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = null) - { - - var expectedFileDir = Path.GetDirectoryName(sourceFilePath); - var callingFileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceFilePath); - var expectedFileName = $"{callingFileNameWithoutExtension}.{memberName}.approved.txt"; - - var expectedFilePath = Path.Combine(expectedFileDir, expectedFileName); - - if (File.Exists(expectedFilePath)) - { - var expectedText = File.ReadAllText(expectedFilePath, Encoding.UTF8); - - var normalisedExpectedText = expectedText.Replace("\r", "");//normalising line endings. - var normalisedContent = content.Replace("\r", ""); - - if (normalisedExpectedText.Equals(normalisedContent)) - return; //this is the happy path. everything matches, so just exit without throwing and the test will be green. - } - else - { - File.WriteAllText(expectedFilePath, "", Encoding.UTF8); - } - - var actualFilePath = expectedFilePath.Replace(".approved.txt", ".actual.txt"); - File.WriteAllText(actualFilePath, content, Encoding.UTF8); - - var kDiffPath = "C:\\Program Files\\KDiff3\\kdiff3.exe"; - if (File.Exists(kDiffPath)) - { - Process.Start(kDiffPath, string.Format("{0} {1} -m -o {0} --cs \"CreateBakFiles=0\"", expectedFilePath, actualFilePath)); - } - else - { - var dir = Directory.GetCurrentDirectory(); - var vsDiffPath = Path.GetFullPath(Path.Combine(dir, "Difftools", "vsDiffMerge.exe")); - Process.Start(vsDiffPath, string.Format("\"{0}\" \"{1}\" /t", expectedFilePath, actualFilePath)); - } - - throw new ShouldMatchApprovedException("String didn't match", actualFilePath, expectedFilePath); - } - } -} diff --git a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApproved.approved.txt b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApproved.approved.txt index 387c884f..b30d9c1d 100644 --- a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApproved.approved.txt +++ b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApproved.approved.txt @@ -1,419 +1,418 @@ - - - - - - - - -
-

- *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - Articles that match your chosen specialities today - *|ELSE:|* - No articles match your chosen specialities today - *|END:INTERESTED|* - - Edit your subscription -

-
- - *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
-

- Evidence summary -

-
*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
- - - - - - - -
-

- - Wonder Drug - -

-

- testing -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
- - - - - - - -
-

- - Hello world - -

-

- test -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|END:INTERESTED|* - *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
-

- Evidence summary 2 -

-
*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
- - - - - - - -
-

- - MY MEDICINE - -

-

- this is my medicine -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
- - - - - - - -
-

- - A Placebo - -

-

- hello -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|END:INTERESTED|* - - + + + + + + + + + +
+

+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + Articles that match your chosen specialities today +*|ELSE:|* + No articles match your chosen specialities today +*|END:INTERESTED|* + - + Edit your subscription +

+
+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+

+ Evidence summary +

+
+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+ + + + + + + +
+

+ + Wonder Drug + +

+

+ testing +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+ + + + + + + +
+

+ + Hello world + +

+

+ test +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|END:INTERESTED|* +*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+

+ Evidence summary 2 +

+
+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+ + + + + + + +
+

+ + MY MEDICINE + +

+

+ this is my medicine +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+ + + + + + + +
+

+ + A Placebo + +

+

+ hello +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|END:INTERESTED|* *|INTERESTED:Send me everything from Medicines Awareness Daily:Send me everything|* - - - - - - -
-

- All articles from Medicines awareness services: Daily edition -

-
- - - - - - - - -
-

- Evidence summary -

-
- - - - - - -
- - - - - - - -
-

- - Wonder Drug - -

-

- testing -

-

- - Read SPS commentary - -

- -
-
- - - - - - -
- - - - - - - -
-

- - Hello world - -

-

- test -

-

- - Read SPS commentary - -

- -
-
- - - - - - -
-

- Evidence summary 2 -

-
- - - - - - -
- - - - - - - -
-

- - MY MEDICINE - -

-

- this is my medicine -

-

- - Read SPS commentary - -

- -
-
- - - - - - -
- - - - - - - -
-

- - A Placebo - -

-

- hello -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* + + + + + + +
+

+ All articles from Medicines awareness services: Daily edition +

+
+ + + + + + +
+

+ Evidence summary +

+
+ + + + + + +
+ + + + + + + +
+

+ + Wonder Drug + +

+

+ testing +

+

+ + Read SPS commentary + +

+ +
+
+ + + + + + +
+ + + + + + + +
+

+ + Hello world + +

+

+ test +

+

+ + Read SPS commentary + +

+ +
+
+ + + + + + +
+

+ Evidence summary 2 +

+
+ + + + + + +
+ + + + + + + +
+

+ + MY MEDICINE + +

+

+ this is my medicine +

+

+ + Read SPS commentary + +

+ +
+
+ + + + + + +
+ + + + + + + +
+

+ + A Placebo + +

+

+ hello +

+

+ + Read SPS commentary + +

+ +
+
*|END:INTERESTED|* + + \ No newline at end of file diff --git a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItem.approved.txt b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItem.approved.txt index 258d74ac..0636f6f1 100644 --- a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItem.approved.txt +++ b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItem.approved.txt @@ -1,143 +1,142 @@ - - - - - - - - -
-

- *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - Articles that match your chosen specialities today - *|ELSE:|* - No articles match your chosen specialities today - *|END:INTERESTED|* - - Edit your subscription -

-
- - *|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
-

- Evidence summary -

-
*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* - - - - - - - -
- - - - - - - -
-

- - Wonder Drug - -

-

- testing -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|END:INTERESTED|* - - + + + + + + + + + +
+

+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + Articles that match your chosen specialities today +*|ELSE:|* + No articles match your chosen specialities today +*|END:INTERESTED|* + - + Edit your subscription +

+
+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+

+ Evidence summary +

+
+*|INTERESTED:Daily specialities of interest:Anaesthesia and pain,Complementary and alternative therapies|* + + + + + + +
+ + + + + + + +
+

+ + Wonder Drug + +

+

+ testing +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|END:INTERESTED|* *|INTERESTED:Send me everything from Medicines Awareness Daily:Send me everything|* - - - - - - -
-

- All articles from Medicines awareness services: Daily edition -

-
- - - - - - - - -
-

- Evidence summary -

-
- - - - - - -
- - - - - - - -
-

- - Wonder Drug - -

-

- testing -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* + + + + + + +
+

+ All articles from Medicines awareness services: Daily edition +

+
+ + + + + + +
+

+ Evidence summary +

+
+ + + + + + +
+ + + + + + + +
+

+ + Wonder Drug + +

+

+ testing +

+

+ + Read SPS commentary + +

+ +
+
*|END:INTERESTED|* + + \ No newline at end of file diff --git a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItemWithSpecificDate.approved.txt b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItemWithSpecificDate.approved.txt index b303d362..e9f1d525 100644 --- a/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItemWithSpecificDate.approved.txt +++ b/lambda/MAS.Tests/IntegrationTests/DailyEmailTests.EmailBodyHtmlMatchesApprovedForSingleItemWithSpecificDate.approved.txt @@ -1,293 +1,292 @@ - - - - - - - - -
-

- *|INTERESTED:Daily specialities of interest:Cancers,Stroke,Later life|* - Articles that match your chosen specialities today - *|ELSE:|* - No articles match your chosen specialities today - *|END:INTERESTED|* - - Edit your subscription -

-
- - *|INTERESTED:Daily specialities of interest:Cancers,Stroke,Later life|* - - - - - - - -
-

- Evidence summary -

-
*|INTERESTED:Daily specialities of interest:Cancers|* - - - - - - - -
- - - - - - - -
-

- - Item 1 - -

-

- This is some short summary -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|INTERESTED:Daily specialities of interest:Stroke|* - - - - - - - -
- - - - - - - -
-

- - Item 2 - -

-

- Some short summary -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|INTERESTED:Daily specialities of interest:Later life|* - - - - - - - -
- - - - - - - -
-

- - Item 3 - -

-

- Some short summary -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* - *|END:INTERESTED|* - - + + + + + + + + + +
+

+*|INTERESTED:Daily specialities of interest:Cancers,Stroke,Later life|* + Articles that match your chosen specialities today +*|ELSE:|* + No articles match your chosen specialities today +*|END:INTERESTED|* + - + Edit your subscription +

+
+*|INTERESTED:Daily specialities of interest:Cancers,Stroke,Later life|* + + + + + + +
+

+ Evidence summary +

+
+*|INTERESTED:Daily specialities of interest:Cancers|* + + + + + + +
+ + + + + + + +
+

+ + Item 1 + +

+

+ This is some short summary +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|INTERESTED:Daily specialities of interest:Stroke|* + + + + + + +
+ + + + + + + +
+

+ + Item 2 + +

+

+ Some short summary +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|INTERESTED:Daily specialities of interest:Later life|* + + + + + + +
+ + + + + + + +
+

+ + Item 3 + +

+

+ Some short summary +

+

+ + Read SPS commentary + +

+ +
+
+*|END:INTERESTED|* +*|END:INTERESTED|* *|INTERESTED:Send me everything from Medicines Awareness Daily:Send me everything|* - - - - - - -
-

- All articles from Medicines awareness services: Daily edition -

-
- - - - - - - - -
-

- Evidence summary -

-
- - - - - - -
- - - - - - - -
-

- - Item 1 - -

-

- This is some short summary -

-

- - Read SPS commentary - -

- -
-
- - - - - - -
- - - - - - - -
-

- - Item 2 - -

-

- Some short summary -

-

- - Read SPS commentary - -

- -
-
- - - - - - -
- - - - - - - -
-

- - Item 3 - -

-

- Some short summary -

-

- - Read SPS commentary - -

- -
-
*|END:INTERESTED|* + + + + + + +
+

+ All articles from Medicines awareness services: Daily edition +

+
+ + + + + + +
+

+ Evidence summary +

+
+ + + + + + +
+ + + + + + + +
+

+ + Item 1 + +

+

+ This is some short summary +

+

+ + Read SPS commentary + +

+ +
+
+ + + + + + +
+ + + + + + + +
+

+ + Item 2 + +

+

+ Some short summary +

+

+ + Read SPS commentary + +

+ +
+
+ + + + + + +
+ + + + + + + +
+

+ + Item 3 + +

+

+ Some short summary +

+

+ + Read SPS commentary + +

+ +
+
*|END:INTERESTED|* + + \ No newline at end of file diff --git a/lambda/MAS.Tests/IntegrationTests/StaticContentTests.PutItemCreatesHTMLXMLAndSitemap.ItemHTML.approved.txt b/lambda/MAS.Tests/IntegrationTests/StaticContentTests.PutItemCreatesHTMLXMLAndSitemap.ItemHTML.approved.txt index 9633a70b..6eb3845d 100644 --- a/lambda/MAS.Tests/IntegrationTests/StaticContentTests.PutItemCreatesHTMLXMLAndSitemap.ItemHTML.approved.txt +++ b/lambda/MAS.Tests/IntegrationTests/StaticContentTests.PutItemCreatesHTMLXMLAndSitemap.ItemHTML.approved.txt @@ -1,84 +1,73 @@ - - - - - - Effect of Vitamin D and Omega-3 Fatty Acid Supplementation on Kidney Function in Patients With Type 2 Diabetes: A Randomized Clinical Trial | Medicines Awareness Service - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
-
-
-

- - Effect of Vitamin D and Omega-3 Fatty Acid Supplementation on Kidney Function in Patients With Type 2 Diabetes: A Randomized Clinical Trial - -

- -

- RCT (n=1,312) found that among adults with type 2 diabetes, supplementation with vitamin D3 or omega-3 fatty acids, compared with placebo, resulted in no significant difference in change in eGFR at 5 years. -

- -
-

SPS commentary:

- -

A related editorial discusses this research and details previous epidemiological studies that suggest improved outcomes with vitamin D supplementation in various clinical scenarios. It states that contrasting the results of this study and its predecessor vitamin D trials with the impressive body of epidemiological research that implicated vitamin D deficiency in various adverse health outcomes offers a stark lesson on the chasm between association and causation. Editorial authors highlight that it now seems safe to conclude that many prior epidemiological associations between vitamin D deficiency and adverse health outcomes were driven by unmeasured residual confounding or reverse causality.

- -
- -

Source:

-

Journal of the American Medical Association

- -

Resource links:

- -

Vitamin D and Health Outcomes - Then Came the Randomized Clinical Trials

-

Link 2

- -
-
- - - + + + + + + Effect of Vitamin D and Omega-3 Fatty Acid Supplementation on Kidney Function in Patients With Type 2 Diabetes: A Randomized Clinical Trial | Medicines Awareness Service + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+

+ + Effect of Vitamin D and Omega-3 Fatty Acid Supplementation on Kidney Function in Patients With Type 2 Diabetes: A Randomized Clinical Trial + +

+

+ RCT (n=1,312) found that among adults with type 2 diabetes, supplementation with vitamin D3 or omega-3 fatty acids, compared with placebo, resulted in no significant difference in change in eGFR at 5 years. +

+
+

SPS commentary:

+

A related editorial discusses this research and details previous epidemiological studies that suggest improved outcomes with vitamin D supplementation in various clinical scenarios. It states that contrasting the results of this study and its predecessor vitamin D trials with the impressive body of epidemiological research that implicated vitamin D deficiency in various adverse health outcomes offers a stark lesson on the chasm between association and causation. Editorial authors highlight that it now seems safe to conclude that many prior epidemiological associations between vitamin D deficiency and adverse health outcomes were driven by unmeasured residual confounding or reverse causality.

+
+

Source:

+

Journal of the American Medical Association

+

Resource links:

+

+ Vitamin D and Health Outcomes - Then Came the Randomized Clinical Trials +

+

+ Link 2 +

+
+
+ + + \ No newline at end of file diff --git a/lambda/MAS.Tests/IntegrationTests/TestBase.cs b/lambda/MAS.Tests/IntegrationTests/TestBase.cs index 7148617f..c448a04e 100644 --- a/lambda/MAS.Tests/IntegrationTests/TestBase.cs +++ b/lambda/MAS.Tests/IntegrationTests/TestBase.cs @@ -1,11 +1,24 @@ -using MAS.Tests.Infrastructure; +using AngleSharp.Html; +using AngleSharp.Html.Parser; +using MAS.Tests.Infrastructure; +using Shouldly; using System; +using System.IO; +using System.Text.RegularExpressions; using Xunit.Abstractions; namespace MAS.Tests.IntegrationTests { public abstract class TestBase : IDisposable { + private const string NewLine = "\r\n"; + private const string Indentation = "\t"; + private static PrettyMarkupFormatter HtmlFormatter = new PrettyMarkupFormatter { Indentation = Indentation, NewLine = NewLine }; + + private static Regex MergeTagAtStartOfLine = new Regex(@"^\s+\*\|", RegexOptions.Multiline); + private static Regex SpaceAfterMergeTag = new Regex(@"\|\*\s+", RegexOptions.Multiline); + private static Regex SpaceBeforeMergeTag = new Regex(@"\s+\*\|", RegexOptions.Multiline); + protected readonly MASWebApplicationFactory _factory; protected readonly ITestOutputHelper _output; @@ -13,6 +26,31 @@ public TestBase(ITestOutputHelper output) { _factory = new MASWebApplicationFactory(output); _output = output; + + // Pretty format HMTL by default yo + ShouldlyConfiguration.ShouldMatchApprovedDefaults + .WithScrubber(s => + { + // Don't try to pretty print XML, assume it's already nicely formatted for easy diffing + if (s.Contains(" +