1 // 2 // Copyright (c) 2010-2019 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System.Linq; 8 using System; 9 using NUnit.Framework; 10 using Antmicro.Renode.Core; 11 12 namespace Antmicro.Renode.Utilities 13 { 14 [TestFixture] 15 public class AdHocCompilerTests 16 { 17 [SetUp] Init()18 public void Init() 19 { 20 adhoc = new AdHocCompiler(); 21 manager = TypeManager.Instance; 22 } 23 24 [Test] ShouldNotThrowOnEmptyFile()25 public void ShouldNotThrowOnEmptyFile() 26 { 27 var extension = TemporaryFilesManager.Instance.GetTemporaryFile(); 28 Assert.DoesNotThrow(() => { file = adhoc.Compile(extension); }); 29 Assert.IsTrue(manager.ScanFile(file)); 30 } 31 32 [Test] ShouldCompileCsFile()33 public void ShouldCompileCsFile() 34 { 35 var extension = GetType().Assembly.FromResourceToTemporaryFile("MockExtension.cs"); 36 var methodsBefore = manager.GetExtensionMethods(typeof(Emulation)); 37 Assert.IsFalse(methodsBefore.Any(x => x.Name == "GetMockString")); 38 Assert.DoesNotThrow(() => { file = adhoc.Compile(extension); }); 39 Assert.IsTrue(manager.ScanFile(file)); 40 var methodsAfter = manager.GetExtensionMethods(typeof(Emulation)); 41 Assert.IsNotEmpty(methodsAfter); 42 Assert.IsTrue(methodsAfter.Any(x => x.Name == "GetMockString")); 43 var result = manager.TryGetTypeByName("Antmicro.Renode.Utilities.MockExtension"); 44 Assert.IsNotNull(result); 45 } 46 47 private AdHocCompiler adhoc; 48 private TypeManager manager; 49 private string file; 50 } 51 } 52