public void ValidatesSafeContent() { const string SafeString = "A safe array of characters without any risk"; byte[] safeBytes = Encoding.UTF8.GetBytes(SafeString); // ARRANGE using (var client = AMSIClient.Create()) using (var testItems = new TestItemsBag(client)) { testItems .ClientTest(c => c.ScanString(SafeString, nameof(SafeString))) .ClientTest(c => c.ScanBuffer(safeBytes, safeBytes.Length, nameof(safeBytes))) .ClientTest(c => c.ScanFile(testItems.CreateTemporaryFile(safeBytes))) .SessionTest(c => c.ScanString(SafeString, nameof(SafeString))) .SessionTest(c => c.ScanBuffer(safeBytes, safeBytes.Length, nameof(safeBytes))) .SessionTest(c => c.ScanFile(testItems.CreateTemporaryFile(safeBytes))); // ACT foreach (var result in testItems) { // ASSERT Assert.IsTrue(result.IsSafe); Assert.IsTrue(result.Result == DetectionResult.NotDetected || result.Result == DetectionResult.Clean); Assert.IsTrue(HasValidData(result)); } } }
public void DetectsEICAR() { // ARRANGE var scan = new Scan(); using (var client = AMSIClient.Create()) using (var testItems = new TestItemsBag(client)) { testItems .ClientTest(c => scan.EICARString()) .ClientTest(c => scan.EICARByteArray()) .ClientTest(c => scan.String(EICARTestData.EICARText, nameof(EICARTestData.EICARText))) .ClientTest(c => scan.Buffer( EICARTestData.EICARZippedBytes , EICARTestData.EICARZippedBytes.Length , nameof(EICARTestData.EICARZippedBytes))) .ClientTest(c => scan.Buffer( EICARTestData.EICARZippedBytes , (uint)EICARTestData.EICARZippedBytes.Length , nameof(EICARTestData.EICARZippedBytes))) .ClientTest(c => scan.File(testItems.CreateTemporaryFile(EICARTestData.EICARZippedBytes))) .ClientTest(c => c.TestEICARString()) .ClientTest(c => c.TestEICARByteArray()) .ClientTest(c => c.ScanString(EICARTestData.EICARText, nameof(EICARTestData.EICARText))) .ClientTest(c => c.ScanBuffer( EICARTestData.EICARZippedBytes , EICARTestData.EICARZippedBytes.Length , nameof(EICARTestData.EICARZippedBytes))) .ClientTest(c => c.ScanFile(testItems.CreateTemporaryFile(EICARTestData.EICARZippedBytes))) .SessionTest(c => c.ScanString(EICARTestData.EICARText, nameof(EICARTestData.EICARText))) .SessionTest(c => c.ScanBuffer( EICARTestData.EICARZippedBytes , EICARTestData.EICARZippedBytes.Length , nameof(EICARTestData.EICARZippedBytes))) .SessionTest(c => c.ScanFile(testItems.CreateTemporaryFile(EICARTestData.EICARZippedBytes))); // ACT foreach (var result in testItems) { // ASSERT Assert.IsFalse(result.IsSafe); Assert.IsTrue( result.Result == DetectionResult.IdentifiedAsMalware || result.Result == DetectionResult.FileBlocked); Assert.IsTrue(HasValidData(result)); } } }