public void GetCached_Cached_Compiled_Assembly() { //Arrange var urls = new string[] { TestContext.TestRunDirectory }; var dslEngineMock = new Mock<DslEngine>(); dslEngineMock.Setup(x => x.ForceCompile(urls, It.IsAny<string>())) .Returns(new CompilerContext { GeneratedAssembly = typeof(int).Assembly }); var storageMock = new Mock<IDslEngineStorage>(); var checksumForFiles = Guid.NewGuid().ToString("N"); storageMock.Setup(x => x.GetChecksumForUrls(dslEngineMock.Object.GetType(), urls)) .Returns(checksumForFiles); var contextCache = new DslCompilerContextCache(storageMock.Object); //Load the first time and cache the compiled assembly var compilerContext = contextCache.GetCached(dslEngineMock.Object, urls); //TODO: Create the file, at the moment no one does use this cache. Implement caching compiled assemblies File.Create(Path.Combine(Path.GetTempPath(), checksumForFiles + ".dslconfigcache")); contextCache.AssemblyLoaded += (string filename, Assembly assembly, bool fromCache) => { //Assert filename.ShouldEqual(Path.Combine(Path.GetTempPath(), checksumForFiles + ".dslconfigcache")); assembly.ShouldEqual(typeof(int).Assembly); fromCache.ShouldBeTrue(); }; //Act compilerContext = contextCache.GetCached(dslEngineMock.Object, urls); //Assert compilerContext.ShouldNotBeNull(); compilerContext.GeneratedAssembly.ShouldEqual(typeof(int).Assembly); }
public void GetCached_Invalid_Parameters() { //Arrange var contextCache = new DslCompilerContextCache(null); //Act try { contextCache.GetCached(null, new string[1] {""}); Assert.Fail("Exception should be thrown"); } catch (ArgumentNullException ex) { //Assert ex.ParamName.ShouldEqual("engine"); } catch { Assert.Fail("Exception should be thrown"); } //Act try { contextCache.GetCached(new Mock<DslEngine>().Object, null); Assert.Fail("Exception should be thrown"); } catch (ArgumentNullException ex) { //Assert ex.ParamName.ShouldEqual("urls"); } catch { Assert.Fail("Exception should be thrown"); } //Act try { contextCache.GetCached(new Mock<DslEngine>().Object, new string[0]); Assert.Fail("Exception should be thrown"); } catch (ArgumentNullException ex) { //Assert ex.ParamName.ShouldEqual("urls"); } catch { Assert.Fail("Exception should be thrown"); } }