public void DoLotsOfConnectionFailures()
        {
            int numberOfEvents = 50;
            using (WmiEventWatcher eventListener = new WmiEventWatcher(numberOfEvents))
            {
                var instrumentationProvider = new NewDataInstrumentationProvider("foo", true, true, true,
                                                                                 "ApplicationInstanceName");
                SqlDatabase db = new SqlDatabase("BadConnectionString", instrumentationProvider);

                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"));
            }
        }
        [Ignore]    //TODO try a different instrumentation mechanism
        public void CreatedProviderHasCorrectInstrumentationListener()
        {
            SecurityCacheProviderFactory factory = new SecurityCacheProviderFactory(GetConfigurationSource());
            ISecurityCacheProvider provider = factory.Create("provider1");

            Assert.AreEqual(typeof(MockSecurityCacheProvider), provider.GetType());

            MockSecurityCacheProvider mockProvider = (MockSecurityCacheProvider)provider;
            ISecurityCacheProviderInstrumentationProvider instrumentationProvider = mockProvider.GetInstrumentationProvder();
            Assert.IsInstanceOfType(instrumentationProvider, typeof(SecurityCacheProviderInstrumentationProvider));

            SecurityCacheProviderInstrumentationProvider castedProvider = (SecurityCacheProviderInstrumentationProvider)instrumentationProvider;

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                IToken token = new GuidToken();
                castedProvider.FireSecurityCacheReadPerformed(SecurityEntityType.Identity, token);
                eventWatcher.WaitForEvents();

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("SecurityCacheReadPerformedEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual(SecurityEntityType.Identity.ToString(), eventWatcher.EventsReceived[0].Properties["EntityType"].Value);
                Assert.AreEqual("provider1", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(token.Value, eventWatcher.EventsReceived[0].Properties["TokenUsed"].Value);
            }
        }
        [Ignore] // TODO try a different instrumentation mechanism
        public void CallingThroughFacadeFiresWmiEvents()
        {
            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                Validation.Validate(this);

                eventWatcher.WaitForEvents();

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("ValidationSucceededEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
            }
        }
        public void CommandFailureFiresWmiEvent()
        {
            using (WmiEventWatcher eventListener = new WmiEventWatcher(1))
            {
                Database db = DatabaseFactory.CreateDatabase();

                try
                {
                    db.ExecuteNonQuery(CommandType.StoredProcedure, "BadCommandText");
                }
                catch { }

                eventListener.WaitForEvents();
                Assert.AreEqual(1, eventListener.EventsReceived.Count);
                Assert.AreEqual("CommandFailedEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual("Service_Dflt", eventListener.EventsReceived[0].GetPropertyValue("InstanceName"));
                Assert.AreEqual(db.ConnectionStringWithoutCredentials, eventListener.EventsReceived[0].GetPropertyValue("ConnectionString"));
                Assert.AreEqual("BadCommandText", eventListener.EventsReceived[0].GetPropertyValue("CommandText"));
            }
        }