diff --git a/SafeExamBrowser.Configuration.UnitTests/DataFormats/XmlParserTests.cs b/SafeExamBrowser.Configuration.UnitTests/DataFormats/XmlParserTests.cs index 8dfce4dd..b0aaff69 100644 --- a/SafeExamBrowser.Configuration.UnitTests/DataFormats/XmlParserTests.cs +++ b/SafeExamBrowser.Configuration.UnitTests/DataFormats/XmlParserTests.cs @@ -119,6 +119,31 @@ namespace SafeExamBrowser.Configuration.UnitTests.DataFormats Assert.AreEqual(LoadStatus.InvalidData, result.Status); } + [TestMethod] + public void MustDecompressDataIfCompressed() + { + var bytes = Encoding.UTF8.GetBytes(""); + var data = LoadTestData(); + var stream = new MemoryStream(Encoding.UTF8.GetBytes("some incorrect data here")); + + compressor.Setup(c => c.Peek(It.IsAny(), It.IsAny())).Returns((d, c) => bytes.Take(c).ToArray()); + compressor.Setup(c => c.IsCompressed(It.IsAny())).Returns(true); + + Assert.IsTrue(sut.CanParse(stream)); + + compressor.Verify(c => c.IsCompressed(It.IsAny()), Times.Once); + compressor.Verify(c => c.Peek(It.IsAny(), It.IsAny()), Times.Once); + + compressor.Setup(c => c.Decompress(It.IsAny())).Returns(data); + + var result = sut.TryParse(stream); + + compressor.Verify(c => c.IsCompressed(It.IsAny()), Times.AtLeast(2)); + compressor.Verify(c => c.Decompress(It.IsAny()), Times.Once); + + Assert.AreEqual(LoadStatus.Success, result.Status); + } + [TestMethod] public void MustParseEmptyXml() { @@ -187,6 +212,14 @@ namespace SafeExamBrowser.Configuration.UnitTests.DataFormats Assert.IsNull(result.RawData["value"]); } + [TestMethod] + public void MustNotFailWithWrongData() + { + var result = sut.TryParse(new MemoryStream(Encoding.UTF8.GetBytes("some random text"))); + + Assert.AreEqual(LoadStatus.InvalidData, result.Status); + } + private Stream LoadTestData() { var path = $"{nameof(SafeExamBrowser)}.{nameof(Configuration)}.{nameof(UnitTests)}.{nameof(DataFormats)}.XmlTestData.xml";