Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Visual Basic

Simulating Stored Procedures in Microsoft Access using Enterprise Library Application Blocks

Rate me:
Please Sign up or sign in to vote.
3.46/5 (12 votes)
25 Jul 2005MIT6 min read 98.3K   1.1K   37  
Simulating stored procedures in Microsoft Access using Enterprise Library Application Blocks.
//===============================================================================
// Microsoft patterns & practices Enterprise Library
// Data Access Application Block
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

#if  UNIT_TESTS
using System;
using Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Tests;
using NUnit.Framework;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.Tests
{
    [TestFixture]
    public class InstrumentationEventsFixture : WMIEventsFixtureBase
    {
        private string testMessage = "test";
        private string testConnection = "test connection";

        [SetUp]
        public void Setup()
        {
            base.wmiLogged = false;
            base.wmiResult = string.Empty;
        }

        [Test]
        public void DataCommandFailedTest()
        {
            string eventName = "DataCommandFailedEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataCommandFailedEvent);

            string expected = "Message = \"Database command failed: test connection\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataCommandFailedEvent()
        {
            DataCommandFailedEvent.Fire(testMessage, testConnection);
        }

        [Test]
        public void DataConnectionOpenedEventTest()
        {
            string eventName = "DataConnectionOpenedEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataConnectionOpenedEvent);

            string expected = "Message = \"Data Connection opened: test connection\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataConnectionOpenedEvent()
        {
            DataConnectionOpenedEvent.Fire(testConnection);
        }

        [Test]
        public void DataConnectionFailedEventTest()
        {
            string eventName = "DataConnectionFailedEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataConnectionFailedEvent);

            string expected = "Message = \"Data connection failed to open: test connection\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataConnectionFailedEvent()
        {
            DataConnectionFailedEvent.Fire(testConnection);
        }

        [Test]
        public void DataServiceFailureEventTest()
        {
            string eventName = "DataServiceFailureEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataServiceFailureEvent);

            string expected = "ExceptionMessage = \"System.Exception: test\";\n\tExceptionStackTrace = NULL;";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataServiceFailureEvent()
        {
            DataServiceFailureEvent.Fire(testMessage, new Exception(testMessage));
        }

        [Test]
        public void DataServiceConfigFailureEventTest()
        {
            string eventName = "DataServiceConfigFailureEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataServiceConfigFailureEvent);

            string expected = "ExceptionMessage = \"System.Exception: test\";\n\tExceptionStackTrace = NULL;\n\tFailedConfigurationFile = \"ConnectionSettings.config\";\n\tMessage = \"test\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataServiceConfigFailureEvent()
        {
            DataServiceConfigFailureEvent.Fire(testMessage, new Exception(testMessage), "ConnectionSettings.config");
        }

        [Test]
        public void DataTransactionFailedEventTest()
        {
            string eventName = "DataTransactionFailedEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataTransactionFailedEvent);

            string expected = "Message = \"Connection: test connection\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataTransactionFailedEvent()
        {
            DataTransactionFailedEvent.Fire(testConnection);
        }

        [Test]
        public void DataTransactionRolledBackEventTest()
        {
            string eventName = "DataTransactionRolledBackEvent";
            WmiEventDelegate action =
                new WmiEventDelegate(FireDataTransactionRolledBackEvent);

            string expected = "Message = \"Connection: test connection\"";
            base.FireMessageToWMI(eventName, action, expected);
        }

        private void FireDataTransactionRolledBackEvent()
        {
            DataTransactionRolledBackEvent.Fire(testConnection);
        }
    }
}

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
AiHelpWebsite.com,
LightSwitchHelpWebsite.com, and
HoloLensHelpWebsite.com.

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

Comments and Discussions