LanguageDriverClassUnitTest.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 » LanguageDriverClassUnitTest.cs
using System;
using System.Collections.Generic;
using System.Text;
using Systin.Library;
using NUnit.Framework;
using System.Reflection;
using LanguageLibrary;

namespace Systin.Library.UnitTests{
    /// <summary>
    /// 
    /// </summary>
    [TestFixture]
    public class LanguageDriverClassUnitTest
    {
        private List<Type> mAssemblyTypes;
  
        /// <summary>
        /// The dll for the test language driver will be setup here.
        /// </summary>
        [TestFixtureSetUp]
        public void Init()
        {             
             //Gets the languageDriverClass dll assembly
            Assembly assembly = Util.GetAssemblyPathRelativeToCurrentAssembly("LanguageLibrary.dll", ref this.mAssemblyTypes);

        }


        #region Exception Tests
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FactoryMethodDoesNotAcceptNull()
        {
            LanguageDriverClass.Factory(null);
        }
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void FactoryMethodShouldNotAllowNonSystinClassesToBeAdded()
        {            
            Type badClass = typeof(BadLanguageDriverTestClass);
            LanguageDriverClass.Factory(badClass);
        }
        [Test]
        [Category("FileAccess")]
        [ExpectedException(typeof(TargetInvocationException))]
        public void DriverClassTestMethodIsNotFound()
        {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            MethodInfo method = null;
            ldc.CallMethod("BadMethodName", ref method);
        }
        [Test]
        [Category("FileAccess")]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestMethodSearchWithValidMethodButIsNotTaggedWithSystinAttribute()
        {

            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            Assert.IsFalse(LanguageDriverClass.MethodExists("Bad_Method_Not_Tagged", ldc));


        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodExistsShouldThrowArgumentNullExceptionForMethodNameParameter()
        {

            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            Assert.IsFalse(LanguageDriverClass.MethodExists(null, ldc));


        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodExistsShouldThrowArgumentNullExceptionForLanguageDriverClassParameter()
        {

            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            Assert.IsFalse(LanguageDriverClass.MethodExists("nonNull", null));


        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void DriverClassTestMethodRejectsNull()
        {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            MethodInfo method = null;
            ldc.CallMethod(null, ref method);

        }
        [Test]
        [ExpectedException(typeof(TargetInvocationException))]
        public void DriverMethodCausesExceptionWhenExecutedBySystin()
        {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);

            MethodInfo method = null;
            ldc.CallMethod("Bad_Method_Programmed_Incorrectly", ref method);
        }
        #endregion

        [Test]
        public void FactoryMethodCreatesNonNullObject()
        {
            Type classUnderTest = Util.FindClassInList("LanguageDriverTestClass", this.mAssemblyTypes);

            if (classUnderTest == null) {TestCase.Fail("LanguageDriverTestClass Was not found"); }
       
            LanguageDriverClass ldc = LanguageDriverClass.Factory(classUnderTest);
            Assert.IsNotNull( ldc, "LanguageDriverClass.Factory returned a null object");
        }

        [Test]
        public void FactoryMethodCorrectlyActivatesASystinClass() {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);

            Assert.IsTrue(ldc.ActivatedInstance.GetType().Equals(typeof(LanguageDriverTestClass)), "Activated Class and class parameter are not of the same type");
        }

        [Test]
        public void EmptyFactoryInstanceReturnsDefaultEmptyObject()
        {
            LanguageDriverClass ldc = LanguageDriverClass.FactoryEmpty();
            Assert.IsNull(ldc.ActivatedInstance , "ActivatedInstance should be null");
        }

        [Test]        
        public void DriverClassTestMethodHasBeenExecuted() {            
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            MethodInfo method = null;
            ldc.CallMethod("Log_Into_system", ref method);

            Stack<string> callStack = Util.GetActionTakenByMethod(ldc);
            Assert.AreEqual("Log_Into_system", callStack.Pop().ToString(), "Method was not called on object"); 
        }

        [Test]
        public void TestMethodSearchFindsValidTestMethod()
        {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            Assert.IsTrue(LanguageDriverClass.MethodExists("Log_Into_system", ldc));
        }

        [Test]
        public void TestMethodSearchFailsToFindFalseMethod()
        {

            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            Assert.IsFalse(LanguageDriverClass.MethodExists("Message_Does_Not_Exist", ldc));
        }



        /// <summary>
        /// This test ensures that when a test class calls other methods that they get logged accordingly
        /// </summary>
        [Test]
        public void DriverClassInvokesMultipleMethodsInCorrectOrderFromOneInvocation() {
            LanguageDriverClass ldc = Util.GetLanguageDriverUnderTest("LanguageDriverTestClass", this.mAssemblyTypes);
            MethodInfo method = null;
            ldc.CallMethod("Log_Into_System_fully", ref method);

            Stack<string> expectedCallStack = new Stack<string>();
            expectedCallStack.Push("Set_User_Name");
            expectedCallStack.Push("Press_Login_Button");
            expectedCallStack.Push("Set_Password");
            expectedCallStack.Push("Log_Into_System_fully");

            Stack<string> callStack = Util.GetActionTakenByMethod(ldc);


            AssertCallStacksAreEqual(expectedCallStack, callStack);
        }

        private void AssertCallStacksAreEqual(Stack<string> expectedCallStack, Stack<string> actualCallStack)
        {
            if (expectedCallStack.Count != actualCallStack.Count)
            {
                Assert.Fail("Size of stacks differ");
            }

            int origCount = expectedCallStack.Count;

            for (int i = 0; i < origCount; i++)
            {
                String expectedCall = expectedCallStack.Pop();
                String actualCall = actualCallStack.Pop();
                if (expectedCall != actualCall)
                {
                    StringAssert.AreEqualIgnoringCase(expectedCall, actualCall, "Methods Called were incorrect");
                }
            }
        }
        
        [Test]
        [Ignore("Not implemented yet")]
        public void DriverClassTestMethodDoesNotExist() { }

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