Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestBase.cs « UnitTests « Test - github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e015b23e13fd97278466cdd6b47e65be5ad7371a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

using System;
using System.IO;
using NUnit.Framework;
using Mono.Addins;
using SimpleApp;

namespace UnitTests
{
	public class TestBase
	{
		public static string TempDir {
			get {
				string dir = new Uri (typeof(TestBase).Assembly.CodeBase).LocalPath;
				return Path.Combine (Path.GetDirectoryName (dir), "temp");
			}
		}
		
		[OneTimeSetUp]
		public virtual void Setup ()
		{
			AddinManager.AddinLoadError += OnLoadError;
			AddinManager.AddinLoaded += OnLoad;
			AddinManager.AddinUnloaded += OnUnload;
			
			if (Directory.Exists (TempDir))
				Directory.Delete (TempDir, true);
			Directory.CreateDirectory (TempDir);

			var configDir = Path.Combine(TempDir, "config");
			Directory.CreateDirectory(configDir);

			// Provide the current assembly as startup assembly, otherwise it will pick the
			// unit test runner as startup assembly

			AddinManager.AddinEngine.Initialize (GetType().Assembly, null, configDir, null, null);
			
			AddinManager.Registry.Update (new ConsoleProgressStatus (true));
		}
		
		[OneTimeTearDown]
		public virtual void Teardown ()
		{
			AddinManager.AddinLoadError -= OnLoadError;
			AddinManager.AddinLoaded -= OnLoad;
			AddinManager.AddinUnloaded -= OnUnload;
			AddinManager.Shutdown ();
		}
		
		void OnLoadError (object s, AddinErrorEventArgs args)
		{
			Console.WriteLine ("Add-in error (" + args.AddinId + "): " + args.Message);
			Console.WriteLine (args.Exception);
		}
		
		void OnLoad (object s, AddinEventArgs args)
		{
			Console.WriteLine ("Add-in loaded: " + args.AddinId);
		}
		
		void OnUnload (object s, AddinEventArgs args)
		{
			Console.WriteLine ("Add-in unloaded: " + args.AddinId);
		}
	}
}