Mvc2VS2010Helper.cs :  » Testing » xUnit.net » Xunit » Installer » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » xUnit.net 
xUnit.net » Xunit » Installer » Mvc2VS2010Helper.cs
using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Xunit.Installer{
    public static class Mvc2VS2010Helper
    {
        const string TEMPLATE_NAME_CSHARP = "XunitMvc2TestProjectTemplate.cs.zip";
        const string TEMPLATE_NAME_VB = "XunitMvc2TestProjectTemplate.vb.zip";

        public static bool CanBeEnabled
        {
            get
            {
                using (RegistryKey key = OpenMvc2Key())
                    return key != null;
            }
        }

        public static bool IsEnabled
        {
            get
            {
                using (RegistryKey key = OpenMvc2Key())
                {
                    if (key == null)
                        return false;

                    using (RegistryKey templateKey = key.OpenSubKey("xUnit.net"))
                        return templateKey != null;
                }
            }
        }

        public static bool Disable(Form owner)
        {
            using (RegistryKey key = OpenMvc2Key())
                key.DeleteSubKeyTree("xUnit.net");

            UninstallZipFiles(VS2010Helper.GetTestProjectTemplatePath("CSharp"));
            UninstallZipFiles(VS2010Helper.GetTestProjectTemplatePath("VisualBasic"));

            VS2010Helper.ResetVisualStudio(owner);
            return true;
        }

        public static bool Enable(Form owner)
        {
            ResourceHelper.WriteResourceToFile("Xunit.Installer.Templates.MVC2-CS-VS2010.zip",
                                               Path.Combine(VS2010Helper.GetTestProjectTemplatePath("CSharp"), TEMPLATE_NAME_CSHARP));
            ResourceHelper.WriteResourceToFile("Xunit.Installer.Templates.MVC2-VB-VS2010.zip",
                                               Path.Combine(VS2010Helper.GetTestProjectTemplatePath("VisualBasic"), TEMPLATE_NAME_VB));

            using (RegistryKey key = OpenMvc2Key())
            using (RegistryKey templateKey = key.CreateSubKey("xUnit.net"))
            {
                using (RegistryKey csharpKey = templateKey.CreateSubKey("C#"))
                {
                    csharpKey.SetValue("AdditionalInfo", "http://xunit.codeplex.com/");
                    csharpKey.SetValue("Package", "");
                    csharpKey.SetValue("Path", @"CSharp\Test");
                    csharpKey.SetValue("Template", TEMPLATE_NAME_CSHARP);
                    csharpKey.SetValue("TestFrameworkName", "xUnit.net build " + Assembly.GetExecutingAssembly().GetName().Version);
                }
                using (RegistryKey vbKey = templateKey.CreateSubKey("VB"))
                {
                    vbKey.SetValue("AdditionalInfo", "http://xunit.codeplex.com/");
                    vbKey.SetValue("Package", "");
                    vbKey.SetValue("Path", @"VisualBasic\Test");
                    vbKey.SetValue("Template", TEMPLATE_NAME_VB);
                    vbKey.SetValue("TestFrameworkName", "xUnit.net build " + Assembly.GetExecutingAssembly().GetName().Version);
                }
            }

            VS2010Helper.ResetVisualStudio(owner);
            return true;
        }

        public static string InstalledXunitVersion()
        {
            using (RegistryKey key = OpenMvc2Key())
            using (RegistryKey csharpKey = key.OpenSubKey(@"xUnit.net\C#"))
                return String.Format("(With templates for {0})", csharpKey.GetValue("TestFrameworkName"));
        }

        static RegistryKey OpenMvc2Key()
        {
            return Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\10.0\MVC2\TestProjectTemplates", true);
        }

        static void UninstallZipFiles(string templatePath)
        {
            foreach (string file in Directory.GetFiles(templatePath, "XunitMvc2TestProjectTemplate.*"))
                File.Delete(Path.Combine(templatePath, file));

            foreach (string directory in Directory.GetDirectories(templatePath))
                UninstallZipFiles(Path.Combine(templatePath, directory));
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.