AttributeCommonTest.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » RegistrationAttributes » UnitTests » 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 » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » RegistrationAttributes » UnitTests » AttributeCommonTest.cs
/***************************************************************************

Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

***************************************************************************/

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VsSDK.UnitTestLibrary;
using System.Collections;
using System.Runtime.InteropServices;

namespace Microsoft.VisualStudio.Shell.RegistrationAttributes.UnitTests{
    /// <summary>
    /// This class is created just to get a type that can be used for the test.
    /// </summary>
    [Guid("EEAB0D91-86F3-4f3a-959A-9548C5642203")]
    public class DummyTypeWithGuid
    {
    }

    /// <summary>
    /// This class tests the common methods and all the properties of the attribute
    /// </summary>
    [CLSCompliant(false)]
    public abstract class AttributeCommonTest
    {
        #region fields
        /// <summary>
        /// Top level reg key to add
        /// </summary>
        protected string RegKeyToAdd = "";

        /// <summary>
        /// Attribute instance
        /// </summary>
        [CLSCompliant(false)]
        protected RegistrationAttribute _instance = null;

        /// <summary>
        /// Data to hold the expected values
        /// </summary>
        protected Hashtable _data = new Hashtable();

        /// <summary>
        /// The registration context mock that has the values set by the registration method
        /// </summary>
        private BaseRegistrationContextMock _mock = null;
        #endregion

        #region properties
        /// <summary>
        /// Returns the registration context mock object.
        /// </summary>
        protected BaseRegistrationContextMock ContextMock
        {
            get
            {
                if (_mock == null)
                    _mock = new BaseRegistrationContextMock();
                return _mock;
            }
        } 
        #endregion

        #region abstract properties
        /// <summary>
        /// This property is implemented by the derived tests to set up the expected values
        /// hash table. The table is keyed on reg key name and value is a hash table of value 
        /// name data pairs for e.g:
        /// KEY:(String)
        /// Packages\{019971D6-4685-11D2-B48A-0000F87572EB}
        /// VALUES:(HashTable)        
        ///     ""              "Visual Basic Compiler Package"
        ///     InprocServer32  "E:\binaries.x86ret.rtm\bin\i386\vspkgs\msvb7.dll"
        /// Packages\{019971D6-4685-11D2-B48A-0000F87572EB}\Automation
        ///     "My Automation Object"              "AutomationObject"
        /// </summary>
        protected abstract Hashtable ExpectedValues
        {
            get;
        }

        /// <summary>
        /// Gets an appropiately populated attribute instance
        /// </summary>
        [CLSCompliant(false)]
        protected abstract RegistrationAttribute AttributeInstance
        {
            get;
        }
        #endregion

        #region virtual methods (test helpers)
        /// <summary>
        /// This scenario tests if an instance of the attribute can be constructed
        /// </summary>
        /// 
        public virtual void CreateInstance()
        {
            Assert.IsNotNull(this.AttributeInstance);
        }

        public static void RegistrationTest(RegistrationAttribute attributeUnderTest, Hashtable expectedValues, BaseRegistrationContextMock contextMock)
        {
            attributeUnderTest.Register(contextMock);

            //Verify if the number of the registry entries is the same
            Assert.IsTrue(contextMock.RegistryEntries.Count == expectedValues.Count);

            //Verify each entry
            foreach (object regKeyName in contextMock.RegistryEntries.Keys)
            {
                Hashtable valDataActual, valDataExpected;
                Assert.IsNotNull(valDataActual = (Hashtable)(((RegistrationKeyMock)contextMock.RegistryEntries[regKeyName])).Keys);
                Assert.IsNotNull(valDataExpected = (Hashtable)expectedValues[regKeyName]);
                Assert.AreEqual(valDataExpected.Count, valDataActual.Count);
                foreach (object valueName in valDataActual.Keys)
                    Assert.IsTrue(string.Compare(valDataActual[valueName.ToString()].ToString(), valDataExpected[valueName.ToString()].ToString(), true) == 0);
            }
        }

        /// <summary>
        /// This scenario verifies Register method
        /// </summary>
        public virtual void RegistrationTest()
        {
            RegistrationTest(this.AttributeInstance, this.ExpectedValues, this.ContextMock);
        }

        /// <summary>
        /// This scenario verifies the Unregister method
        /// </summary>
        public virtual void UnRegistrationTest()
        {
            UnRegistrationTest(this.AttributeInstance, this.ContextMock);
        }

        /// <summary>
        /// This scenario verifies the Unregister method
        /// </summary>
        public static void UnRegistrationTest(RegistrationAttribute attributeUnderTest, BaseRegistrationContextMock contextMock)
        {
            attributeUnderTest.Unregister(contextMock);
            Assert.IsTrue(contextMock.RegistryEntries.Count == 0);
        }
        #endregion
    }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.