PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/src/UnitTests/IOC/FileWatcherTests.cs

http://github.com/philiplaureano/LinFu
C# | 43 lines | 31 code | 7 blank | 5 comment | 0 complexity | 836943d9b58f9e1bbc868b71e1356205 MD5 | raw file
 1using System;
 2using System.IO;
 3using System.Threading;
 4using LinFu.IoC;
 5using Xunit;
 6using SampleLibrary;
 7
 8namespace LinFu.UnitTests.IOC
 9{
10    public class FileWatcherTests
11    {
12        [Fact]
13        public void ShouldLoadAssemblyIntoLoaderAtRuntime()
14        {
15            var path = Path.Combine(@"..\..\..\SampleFileWatcherLibrary\bin\Debug",
16                AppDomain.CurrentDomain.BaseDirectory);
17            var targetFile = "SampleFileWatcherLibrary.dll";
18            var sourceFileName = Path.Combine(path, targetFile);
19
20            var container = new ServiceContainer();
21            container.AutoLoadFrom(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");
22
23            // There should be nothing loaded at this point since the assembly hasn't
24            // been copied to the target directory yet
25            Assert.False(container.Contains(typeof(ISampleService)));
26
27            // Copy the assembly to the target directory
28            // and watch for changes
29            var targetFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");
30            File.Copy(sourceFileName, targetFileName, true);
31
32            // Give the watcher thread enough time to load the assembly into memory
33            Thread.Sleep(500);
34            Assert.True(container.Contains(typeof(ISampleService)));
35
36            var instance = container.GetService<ISampleService>();
37            Assert.NotNull(instance);
38
39            var typeName = instance.GetType().Name;
40            Assert.Equal("SampleFileWatcherServiceClassAddedAtRuntime", typeName);
41        }
42    }
43}