~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Test/UnitTests/TestBase.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.IO;
 
4
using NUnit.Framework;
 
5
using Mono.Addins;
 
6
using SimpleApp;
 
7
 
 
8
namespace UnitTests
 
9
{
 
10
        public class TestBase
 
11
        {
 
12
                static bool firstRun = true;
 
13
                
 
14
                public static string TempDir {
 
15
                        get {
 
16
                                string dir = new Uri (typeof(TestBase).Assembly.CodeBase).LocalPath;
 
17
                                return Path.Combine (Path.GetDirectoryName (dir), "temp");
 
18
                        }
 
19
                }
 
20
                
 
21
                [TestFixtureSetUp]
 
22
                public virtual void Setup ()
 
23
                {
 
24
                        AddinManager.AddinLoadError += OnLoadError;
 
25
                        AddinManager.AddinLoaded += OnLoad;
 
26
                        AddinManager.AddinUnloaded += OnUnload;
 
27
                        
 
28
                        if (firstRun) {
 
29
                                if (Directory.Exists (TempDir))
 
30
                                        Directory.Delete (TempDir, true);
 
31
                                Directory.CreateDirectory (TempDir);
 
32
                        }
 
33
                        
 
34
                        AddinManager.Initialize (TempDir);
 
35
                        
 
36
                        if (firstRun)
 
37
                                AddinManager.Registry.Update (new ConsoleProgressStatus (true));
 
38
                        else
 
39
                                AddinManager.Registry.ResetConfiguration ();
 
40
                        
 
41
                        firstRun = false;
 
42
                }
 
43
                
 
44
                [TestFixtureTearDown]
 
45
                public virtual void Teardown ()
 
46
                {
 
47
                        AddinManager.AddinLoadError -= OnLoadError;
 
48
                        AddinManager.AddinLoaded -= OnLoad;
 
49
                        AddinManager.AddinUnloaded -= OnUnload;
 
50
                        AddinManager.Shutdown ();
 
51
                }
 
52
                
 
53
                void OnLoadError (object s, AddinErrorEventArgs args)
 
54
                {
 
55
                        Console.WriteLine ("Add-in error (" + args.AddinId + "): " + args.Message);
 
56
                        Console.WriteLine (args.Exception);
 
57
                }
 
58
                
 
59
                void OnLoad (object s, AddinEventArgs args)
 
60
                {
 
61
                        Console.WriteLine ("Add-in loaded: " + args.AddinId);
 
62
                }
 
63
                
 
64
                void OnUnload (object s, AddinEventArgs args)
 
65
                {
 
66
                        Console.WriteLine ("Add-in unloaded: " + args.AddinId);
 
67
                }
 
68
        }
 
69
}