LanguageDriverClassManagerUnitTest.cs :  » Testing » SystiN » Systin.Library.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 » Testing » SystiN 
SystiN » Systin.Library.UnitTests » LanguageDriverClassManagerUnitTest.cs
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Systin.Library;
using System.Reflection;
using System.Collections;

namespace Systin.Library.UnitTests{
    [TestFixture]
    public class LanguageDriverClassManagerUnitTest
    {
        private List<Type> mAssemblyTypes;
        private Assembly ClassAssembly;
        private static string LanguageLibraryName = "LanguageLibrary.dll";

        /// <summary>
        /// Drivers the manager throws null exception on null arguments.
        /// </summary>
        [Test]        
        public void DriverManagerThrowsNullExceptionOnNullArguments() {
            setup();

            try
            {
                LanguageDriverClassManager.Factory(null);
                Assert.Fail("Exception was not thrown");
            }
            catch (ArgumentNullException) { }
          
        }

        [Test]
        public void CallMethodThreadedWrapperThrowsArgumentException()
        {
            setup();
            try
            {
                Queue q = new Queue(); 
                LanguageDriverClassManager.CallMethodThreadedWrapper(q);
                Assert.Fail("Exception was not thrown");
            }
            catch (ArgumentException) { }

        }
        [Test]
        public void CallMethodThreadedWrapperThrowsArgumentNullException()
        {
            setup();
            try
            {
                LanguageDriverClassManager.CallMethodThreadedWrapper(null);
                Assert.Fail("Exception was not thrown");
            }
            catch (ArgumentException) { }

        }

        [Test]
        public void CallMethodThreadedWrapperSuccessful()
        {
            setup();
            LanguageDriverClassManager ldc = LanguageDriverClassManager.Factory(this.ClassAssembly);
            Instruction instruction = Instruction.NewInstruction("Log_Into_system");
            Queue<Instruction> instructions = new Queue<Instruction>();
            instructions.Enqueue(instruction);

            ThreadWorkerMethodCall tworker = ThreadWorkerMethodCall.Factory(instructions, ref ldc);
            LanguageDriverClassManager.CallMethodThreadedWrapper(tworker);
            
            Assert.IsTrue(tworker.LanguageDriverClassManager.InstructionStack.Count == 1);
            Assert.IsTrue(ldc.InstructionStack.Count == 1);

            MethodInfo method = tworker.LanguageDriverClassManager.InstructionStack.Pop();
            Assert.AreEqual(method.Name, "Log_Into_system");

            Assert.IsTrue(tworker.LanguageDriverClassManager.InstructionStack.Count == 0);
            Assert.IsTrue(ldc.InstructionStack.Count == 0);

        }

        /// <summary>
        /// Drivers the manager creates correct number of language driver classes from assembly.
        /// </summary>
        [Test]
        public void DriverManagerCreatesCorrectNumberOfLanguageDriverClassesFromAssembly() { 
            //How many classes are in the library under test
            setup();


            int classCount = GetNumberOfSystinClassesInAssembly();

            LanguageDriverClassManager ldcm = LanguageDriverClassManager.Factory(this.ClassAssembly);
            Assert.AreEqual( classCount, ldcm.LanguageDriverClassHash.Count, "Number in hash and number counted are different" ); 
        }

        /// <summary>
        /// Drivers the manager factory method does not return null.
        /// </summary>
        [Test]
        public void DriverManagerFactoryMethodDoesNotReturnNull()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            LanguageDriverClassManager ldcm = LanguageDriverClassManager.Factory(assembly);
            Assert.IsNotNull(ldcm, "Manager Class returned a null Value");
        }


        [Test]
        [ExpectedException(typeof(TargetException))]
        public void CallMethodThatDoesNotExist()
        {
            setup();


            LanguageDriverClassManager ldcm = LanguageDriverClassManager.Factory(this.ClassAssembly);
            ldcm = LanguageDriverClassManager.CallMethod("Non_Existant_Method", ldcm);
        }
        [Test]
        [ExpectedException(typeof(TargetException))]
        public void CallMethodWithBadName()
        {
            setup();


            LanguageDriverClassManager ldcm = LanguageDriverClassManager.Factory(this.ClassAssembly);
            ldcm = LanguageDriverClassManager.CallMethod("text of Method in Bad type_//$$$11", ldcm);
        }

        /// <summary>
        /// Calls the valid test method.
        /// </summary>
        [Test]
        public void CallValidTestMethod() {
            setup();

            LanguageDriverClassManager ldcm = LanguageDriverClassManager.Factory(this.ClassAssembly);
            ldcm = LanguageDriverClassManager.CallMethod("Log_Into_system", ldcm);
            MethodInfo methodInvoked = ldcm.InstructionStack.Pop();

            StringAssert.AreEqualIgnoringCase(methodInvoked.Name, "Log_Into_system", "Method Names aren't equal");
        }

        [Test]        
        public void CallValidTestCaseWithNullMethodValue()
        {
            try
            {
                setup();
                LanguageDriverClassManager.CallMethod(null, null);
                TestCase.Fail("ArgumentNullException should have been thrown");
            }
            catch (ArgumentNullException) { }
        }

        [Test]
        public void CallMethodWithNullLanguageDriverClassObject()
        {
            try
            {
                setup();
                LanguageDriverClassManager.CallMethod("Log_Into_system", null);
                TestCase.Fail("ArgumentNullException should have been thrown");
            }
            catch (ArgumentNullException) { }
        }
        
        #region Private Methods
        private int GetNumberOfSystinClassesInAssembly()
        {
            int classCount = 0;
            foreach (Type classType in this.ClassAssembly.GetTypes())
            {

                if (Attribute.GetCustomAttribute(classType, typeof(LanguageDriverAttribute)) != null)
                {
                    classCount++;
                }
            }
            return classCount;
        }

        private void setup()
        {
            //Gets the languageDriverClass dll assembly
            Assembly assembly = Util.GetAssemblyPathRelativeToCurrentAssembly(LanguageLibraryName, ref this.mAssemblyTypes);
            this.ClassAssembly = assembly;
        }

        #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.