public void AddFailsIfAddingSameAssemblyTwice() { AssemblyContainer tested = new AssemblyContainer(); tested.Add(GetType().Assembly.Location); DoAssert.Throws <ArgumentException>(() => tested.Add(GetType().Assembly.Location)); }
public MockAssemblyRepository() { var container = new AssemblyContainer(); container.Add(typeof(MockPlugin1).Assembly.Location); container.Add(typeof(PluginCreator).Assembly.Location); this.repos = container; this.Fetched = new Dictionary<string, byte[]>(); }
public MockAssemblyRepository() { var container = new AssemblyContainer(); container.Add(typeof(MockPlugin1).Assembly.Location); container.Add(typeof(PluginCreator).Assembly.Location); this.repos = container; this.Fetched = new Dictionary <string, byte[]>(); }
public void FetchShouldReturnExistingAssembly() { AssemblyContainer tested = new AssemblyContainer(); Assembly assembly = Assembly.GetAssembly(typeof(MockPlugin1)); tested.Add(assembly.Location); byte[] returned = tested.Fetch(assembly.FullName); Assert.IsNotNull(returned); }
public void AddShouldRaiseAssemblyAddedForValidAssembly() { AssemblyContainer tested = new AssemblyContainer(); bool raisedAssemblyAdded = false; tested.AssemblyAdded += (s, e) => raisedAssemblyAdded = true; tested.Add(GetType().Assembly.Location); Assert.IsTrue(raisedAssemblyAdded); }
public void ShouldLogToInfoWhenAddingAssembly() { var path = GetType().Assembly.Location; AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Assembly added ") && x.Message.Contains(path))); }
public void ShouldLogToDebugWhenAssemblyIsFetched() { var assemblyname = GetType().Assembly.FullName; var path = GetType().Assembly.Location; var pattern = new Regex(@"^Assembly fetched .+ \(\d+ bytes read from .*\)$"); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && pattern.IsMatch(x.Message) && x.Message.Contains(path) && x.Message.Contains(assemblyname))); }
public void RemoveShouldRaiseAssemblyRemovedForKnownAssembly() { AssemblyContainer tested = new AssemblyContainer(); tested.Add(GetType().Assembly.Location); bool raisedAssemblyRemoved = false; tested.AssemblyRemoved += (s, e) => raisedAssemblyRemoved = true; tested.Remove(GetType().Assembly.Location); Assert.IsTrue(raisedAssemblyRemoved); }
public void AddShouldHandleInvalidFile() { AssemblyContainer tested = new AssemblyContainer(); string filename = Guid.NewGuid().ToString() + ".dll"; using (var output = File.CreateText(filename)) output.WriteLine("Invalid assembly data"); try { var returned = tested.Add(filename); Assert.IsFalse(returned); } finally { File.Delete(filename); } }
public void AddShouldHandleLockedFile() { AssemblyContainer tested = new AssemblyContainer(); string filename = Guid.NewGuid().ToString() + ".dll"; try { using (var output = File.CreateText(filename)) { var returned = tested.Add(filename); Assert.IsFalse(returned); } } finally { File.Delete(filename); } }
public void ShouldLogToErrorWhenAllKnownPathsToAssemblyDoesNotExist() { var assemblyname = GetType().Assembly.FullName; var path = Guid.NewGuid().ToString() + ".dll"; var pattern = new Regex(@"^Unable to fetch .+, file not found in these locations:$"); try { File.Copy(GetType().Assembly.Location, path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); File.Delete(path); tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && pattern.IsMatch(x.Message) && x.Message.Contains(assemblyname))); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && x.Message.StartsWith(" --> ") && x.Message.EndsWith(path))); } finally { File.Delete(path); } }
public void FetchShouldLogExceptionsAsErrors() { var assemblyname = GetType().Assembly.FullName; var path = Guid.NewGuid().ToString() + ".dll"; var pattern = new Regex(@"^Exception while fetching .+ (.+) .*$"); try { File.Copy(GetType().Assembly.Location, path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); using (var file = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.None)) { tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && pattern.IsMatch(x.Message) && x.Message.Contains(assemblyname) && x.Message.Contains(path))); } } finally { File.Delete(path); } }
public void FetchShouldReturnNullForUnreadableAssembly() { AssemblyContainer tested = new AssemblyContainer(); Assembly assembly = Assembly.GetAssembly(typeof(MockPlugin1)); string location = assembly.Location.Replace(".dll", ".mock.dll"); File.Copy(assembly.Location, location, true); try { tested.Add(location); using (Stream locking = FileExtension.WaitAndOpen(location, FileMode.Open, FileAccess.Read, FileShare.None, TimeSpan.FromSeconds(5))) { byte[] returned = tested.Fetch(Assembly.GetAssembly(typeof(MockPlugin1)).FullName); Assert.IsNull(returned); } } finally { File.Delete(location); } }
public void ShouldLogToInfoWhenRemovingAssembly() { var path = GetType().Assembly.Location; AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); tested.Remove(path); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Assembly removed ") && x.Message.Contains(path))); }
public void AddRequiresArgument() { AssemblyContainer tested = new AssemblyContainer(); DoAssert.Throws <ArgumentNullException>(() => tested.Add(null)); }
public void AddRequiresExistingFile() { AssemblyContainer tested = new AssemblyContainer(); DoAssert.Throws<FileNotFoundException>(() => tested.Add(@"c:\" + Guid.NewGuid().ToString())); }
public void AddRequiresArgument() { AssemblyContainer tested = new AssemblyContainer(); DoAssert.Throws<ArgumentNullException>(() => tested.Add(null)); }
public void AddFailsIfAddingSameAssemblyTwice() { AssemblyContainer tested = new AssemblyContainer(); tested.Add(GetType().Assembly.Location); DoAssert.Throws<ArgumentException>(() => tested.Add(GetType().Assembly.Location)); }
public void AddRequiresExistingFile() { AssemblyContainer tested = new AssemblyContainer(); DoAssert.Throws <FileNotFoundException>(() => tested.Add(@"c:\" + Guid.NewGuid().ToString())); }