|
| 1 | +@using System.IO |
| 2 | + |
| 3 | +@code { |
| 4 | + /// <summary> |
| 5 | + /// Integration test to verify that Ads.xml is properly copied to output directory. |
| 6 | + /// This test validates the fix for the Azure deployment issue where Ads.xml was missing. |
| 7 | + /// </summary> |
| 8 | + [Fact] |
| 9 | + public void AdRotator_DeploymentVerification_AdsXmlExistsInOutputDirectory() |
| 10 | + { |
| 11 | + // Arrange - Get the path where Ads.xml should be copied during build |
| 12 | + var outputDirectory = AppContext.BaseDirectory; |
| 13 | + var adsXmlPath = Path.Combine(outputDirectory, "Ads1.xml"); |
| 14 | + |
| 15 | + // Act & Assert - Verify the file exists (simulating deployment scenario) |
| 16 | + File.Exists(adsXmlPath).ShouldBeTrue($"Ads.xml should be copied to output directory. Expected path: {adsXmlPath}"); |
| 17 | + |
| 18 | + // Verify the file can be read and contains valid XML |
| 19 | + var fileContent = File.ReadAllText(adsXmlPath); |
| 20 | + fileContent.ShouldContain("<Advertisements>"); |
| 21 | + fileContent.ShouldContain("<Ad>"); |
| 22 | + } |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Integration test to verify AdRotator can load and render ads from a file in the output directory. |
| 26 | + /// This simulates the actual deployment scenario where the component loads from the file system. |
| 27 | + /// </summary> |
| 28 | + [Fact] |
| 29 | + public void AdRotator_DeploymentVerification_LoadsFromOutputDirectory() |
| 30 | + { |
| 31 | + // Arrange - Use Ads1.xml which should be in output directory |
| 32 | + var adsFile = "Ads1.xml"; |
| 33 | + |
| 34 | + // Act - Render AdRotator with the file from output directory |
| 35 | + var cut = Render(@<AdRotator AdvertisementFile="@adsFile" Target="_blank" />); |
| 36 | + |
| 37 | + // Assert - Verify the component rendered successfully |
| 38 | + var anchor = cut.Find("a"); |
| 39 | + anchor.ShouldNotBeNull("AdRotator should render an anchor element when Ads.xml is found"); |
| 40 | + |
| 41 | + var img = cut.Find("img"); |
| 42 | + img.ShouldNotBeNull("AdRotator should render an image element when Ads.xml is found"); |
| 43 | + |
| 44 | + // Verify the content matches expected values from Ads1.xml |
| 45 | + img.Attributes["alt"].Value.ShouldBe("Bing"); |
| 46 | + img.Attributes["src"].Value.ShouldBe("bing.png"); |
| 47 | + anchor.Attributes["href"].Value.ShouldBe("http://www.bing.com"); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Integration test to verify AdRotator handles missing Ads.xml gracefully. |
| 52 | + /// This helps identify deployment issues early. |
| 53 | + /// </summary> |
| 54 | + [Fact] |
| 55 | + public void AdRotator_DeploymentVerification_HandlesFileMissingScenario() |
| 56 | + { |
| 57 | + // Arrange - Use a non-existent file |
| 58 | + var nonExistentFile = "NonExistent.xml"; |
| 59 | + |
| 60 | + // Act & Assert - Should throw FileNotFoundException |
| 61 | + Should.Throw<FileNotFoundException>(() => |
| 62 | + { |
| 63 | + var cut = Render(@<AdRotator AdvertisementFile="@nonExistentFile" Target="_blank" />); |
| 64 | + }); |
| 65 | + } |
| 66 | +} |
0 commit comments