public void DoLotsOfConnectionFailures()
        {
            int numberOfEvents = 50;

            using (WmiEventWatcher eventListener = new WmiEventWatcher(numberOfEvents))
            {
                SqlDatabase db = new SqlDatabase("BadConnectionString");
                DataInstrumentationListener       listener = new DataInstrumentationListener("foo", true, true, true);
                DataInstrumentationListenerBinder binder   = new DataInstrumentationListenerBinder();
                binder.Bind(db.GetInstrumentationEventProvider(), listener);

                for (int i = 0; i < numberOfEvents; i++)
                {
                    try
                    {
                        db.ExecuteScalar(CommandType.Text, "Select count(*) from Region");
                    }
                    catch { }
                }

                eventListener.WaitForEvents();

                Assert.AreEqual(numberOfEvents, eventListener.EventsReceived.Count);
                Assert.AreEqual("ConnectionFailedEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual("foo", eventListener.EventsReceived[0].GetPropertyValue("InstanceName"));
                Assert.AreEqual(db.ConnectionStringWithoutCredentials, eventListener.EventsReceived[0].GetPropertyValue("ConnectionString"));
            }
        }
		public void DoLotsOfConnectionFailures()
		{
			int numberOfEvents = 50;
			using (WmiEventWatcher eventListener = new WmiEventWatcher(numberOfEvents))
			{
				SqlDatabase db = new SqlDatabase("BadConnectionString");
				DataInstrumentationListener listener = new DataInstrumentationListener("foo", true, true, true);
				DataInstrumentationListenerBinder binder = new DataInstrumentationListenerBinder();
				binder.Bind(db.GetInstrumentationEventProvider(), listener);

				for (int i = 0; i < numberOfEvents; i++)
				{
					try
					{
						db.ExecuteScalar(CommandType.Text, "Select count(*) from Region");
					}
					catch { }
				}

				eventListener.WaitForEvents();
				
				Assert.AreEqual(numberOfEvents, eventListener.EventsReceived.Count);
                Assert.AreEqual("ConnectionFailedEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
				Assert.AreEqual("foo", eventListener.EventsReceived[0].GetPropertyValue("InstanceName"));
				Assert.AreEqual(db.ConnectionStringWithoutCredentials, eventListener.EventsReceived[0].GetPropertyValue("ConnectionString"));
			}
		}
 public void SetUp()
 {
     nameFormatter                = new FixedPrefixNameFormatter("Prefix - ");
     listener                     = new DataInstrumentationListener(instanceName, true, true, true, nameFormatter);
     formattedInstanceName        = nameFormatter.CreateName(instanceName);
     totalConnectionOpenedCounter = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalConnectionOpenedCounter, formattedInstanceName);
     totalConnectionFailedCounter = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalConnectionFailedCounter, formattedInstanceName);
     totalCommandsExecutedCounter = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalCommandsExecutedCounter, formattedInstanceName);
     totalCommandsFailedCounter   = new EnterpriseLibraryPerformanceCounter(counterCategoryName, TotalCommandsFailedCounter, formattedInstanceName);
 }