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

DirectoryCatalogDebuggerProxyTests.cs « Hosting « Composition « ComponentModel « System « ComponentModelUnitTest « Tests « System.ComponentModel.Composition « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9dfd4155727a11813695928cfb5d8062a648fc6d (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
#if !SILVERLIGHT

using System;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Linq;
using System.UnitTesting;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace System.ComponentModel.Composition.Primitives
{
    [TestClass]
    public class DirectoryCatalogDebuggerProxyTests
    {
        [TestMethod]
        public void Constructor_NullAsCatalogArgument_ShouldThrowArgumentNull()
        {
            ExceptionAssert.ThrowsArgument<ArgumentNullException>("catalog", () =>
            {
                new DirectoryCatalog.DirectoryCatalogDebuggerProxy((DirectoryCatalog)null);
            });
        }

        [TestMethod]
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetAssemblies();

            foreach (var e in expectations)
            {
                using (TemporaryFileCopier copier = new TemporaryFileCopier(e.Location))
                {
                    var catalog = CreateDirectoryCatalog(copier.DirectoryPath);

                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                    EnumerableAssert.AreSequenceEqual(catalog.Parts, proxy.Parts);
                }
            }
        }

        [TestMethod]
        public void Constructor_ValueAsCatalogArgument_ShouldSetAssemblyProperty()
        {
            var expectations = Expectations.GetAssemblies();

            using (TemporaryFileCopier copier = new TemporaryFileCopier(expectations.Select(assembly => assembly.Location).ToArray()))
            {
                var catalog = CreateDirectoryCatalog(copier.DirectoryPath);
                var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                EnumerableAssert.AreEqual(expectations, proxy.Assemblies);
            }
        }

        [TestMethod]
        public void Constuctor_ValueAsCatalogArgument_ShouldSetPathProperty()
        {
            string path = FileIO.GetNewTemporaryDirectory();

            var catalog = CreateDirectoryCatalog(path);
            var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

            Assert.AreEqual(path, proxy.Path);
        }

        [TestMethod]
        public void Constuctor_ValueAsCatalogArgument_ShouldSetSearchPatternProperty()
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                var expectations = new ExpectationCollection<string, string>();

                expectations.Add("*.*", "*.*");
                expectations.Add("*.doc", "*.doc");
                expectations.Add("*.exe", "*.exe");
                expectations.Add("*.dll", "*.dll");

                foreach (var e in expectations)
                {
                    var catalog = CreateDirectoryCatalog(directory.DirectoryPath, e.Input);
                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                    Assert.AreEqual(e.Output, proxy.SearchPattern);
                }
            }
        }

        [TestMethod]
        public void FullPath_ValidPath_ShouldBeFine()
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                var expectations = new ExpectationCollection<string, string>();

                // Ensure the path is always normalized properly.
                string rootTempPath = Path.GetFullPath(FileIO.GetRootTemporaryDirectory()).ToUpperInvariant();

                // Note: These relative paths work properly because the unit test temporary directories are always
                // created as a subfolder off the AppDomain.CurrentDomain.BaseDirectory.
                expectations.Add(".", Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".")).ToUpperInvariant());
                expectations.Add(FileIO.RootTemporaryDirectoryName, rootTempPath);
                expectations.Add(FileIO.GetRootTemporaryDirectory(), rootTempPath);
                expectations.Add(directory.DirectoryPath, Path.GetFullPath(directory.DirectoryPath).ToUpperInvariant());

                foreach (var e in expectations)
                {
                    var cat = CreateDirectoryCatalog(e.Input, DirectoryCatalogTests.NonExistentSearchPattern);
                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat);

                    Assert.AreEqual(e.Output, proxy.FullPath);
                }
            }
        }

        [TestMethod]
        public void LoadedFiles_EmptyDirectory_ShouldBeFine()
        {
            using (var directory = new TemporaryDirectory())
            {
                var cat = CreateDirectoryCatalog(directory.DirectoryPath);
                var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat);

                Assert.AreEqual(0, proxy.LoadedFiles.Count);
            }
        }

        [TestMethod]
        public void LoadedFiles_ContainsMultipleDllsAndSomeNonDll_ShouldOnlyContainDlls()
        {
            using (var directory = new TemporaryDirectory())
            {
                // Add one text file
                using (File.CreateText(Path.Combine(directory.DirectoryPath, "Test.txt"))) { }

                // Add two dll's
                string dll1 = Path.Combine(directory.DirectoryPath, "Test1.dll");
                string dll2 = Path.Combine(directory.DirectoryPath, "Test2.dll");
                File.Copy(Assembly.GetExecutingAssembly().Location, dll1);
                File.Copy(Assembly.GetExecutingAssembly().Location, dll2);

                var cat = CreateDirectoryCatalog(directory.DirectoryPath);
                var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat);

                CollectionAssert.AreEquivalent(new string[] { dll1.ToUpperInvariant(), dll2.ToUpperInvariant() },
                    proxy.LoadedFiles);
            }
        }

        private DirectoryCatalog.DirectoryCatalogDebuggerProxy CreateAssemblyDebuggerProxy(DirectoryCatalog catalog)
        {
            return new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);
        }

        private DirectoryCatalog CreateDirectoryCatalog(string path)
        {
            return new DirectoryCatalog(path);
        }

        private DirectoryCatalog CreateDirectoryCatalog(string path, string filter)
        {
            return new DirectoryCatalog(path, filter);
        }
    }
}

#endif