public void Registration_TwoDefinitionWithSameSourceDifferentLevel_LevelShouldBeHighestOne() { var definition1 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source" && d.EventKeywords == (EventKeywords)10 && d.MinimumEventLevel == EventLevel.Informational ); var definition2 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source" && d.EventKeywords == (EventKeywords)20 && d.MinimumEventLevel == EventLevel.Verbose ); var handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { definition1, definition2 }.AsReadOnly())) }; var sut = new EventListenerParameters(handlers).Registrations.Value; var expected = (EventLevel)Math.Max((int)definition1.MinimumEventLevel, (int)definition2.MinimumEventLevel); Assert.True(sut.Count == 1); Assert.True(sut[definition1.EventSource].Level == expected); }
public void LookupWithNotExistedEventId_BothOfSourceAndEventDefinition_ShouldServeBothHandlers() { var source1_EventAll = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1"); var source1_Event10 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 10); var source1_Event20 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 20); var source1_EventAll_SubscriptionId = Guid.NewGuid().ToString(); var source1_Event10_SubscriptionId = Guid.NewGuid().ToString(); var handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == source1_EventAll_SubscriptionId && s.Events == new List <ISourceDefinition> { source1_Event10, source1_EventAll }.AsReadOnly())), Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == source1_Event10_SubscriptionId && s.Events == new List <ISourceDefinition> { source1_Event10 }.AsReadOnly())) }; var sut = new EventListenerParameters(handlers).Lookup.Value; var actual = sut[new SourceDefinitionLookup(source1_Event20, true)]; Assert.True(actual.Count() == 1); Assert.True(actual.First().Subscription.Id == source1_EventAll_SubscriptionId); }
public void Registration_TwoDefinitionWithSameSourceDifferentKeywords_KeywordsShouldBeMerged() { var definition1 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source" && d.EventKeywords == (EventKeywords)10 && d.MinimumEventLevel == EventLevel.Informational ); var definition2 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source" && d.EventKeywords == (EventKeywords)20 && d.MinimumEventLevel == EventLevel.Informational ); var handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { definition1, definition2 }.AsReadOnly())) }; var sut = new EventListenerParameters(handlers).Registrations.Value; Assert.True(sut.Count == 1); Assert.True(sut[definition1.EventSource].Keywords == (definition1.EventKeywords | definition2.EventKeywords)); }
public void Registration_DummyEvent_AllPropertiesShouldBeSame() { var definition = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source" && d.EventKeywords == (EventKeywords)10 && d.MinimumEventLevel == EventLevel.Informational ); var handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { definition }.AsReadOnly())) }; var sut = new EventListenerParameters(handlers).Registrations.Value; Assert.True(sut.Count == 1); Assert.True(sut[definition.EventSource].Source == definition.EventSource); Assert.True(sut[definition.EventSource].Keywords == definition.EventKeywords); Assert.True(sut[definition.EventSource].Level == definition.MinimumEventLevel); }
private void Enqueue(IInternalSubscriptionHandler handler, EventWrittenEventArgs eventData) { try { Registration registration = _registrations[eventData.EventSource.Name]; IEventEntry entry = new EventEntry(eventData, registration, DateTime.UtcNow); handler.Add(entry); } catch (Exception) { }//TODO : internal logging }
internal static void CreateOrUpdate(GeneralizedSubscription subscription, IInternalSubscriptionHandler handler) { if (_instance == null) { lock (_syncRoot) { if (_instance == null) { _subscription = subscription; _handler = handler; _registrations = new ConcurrentDictionary <string, Registration>(); _instance = new GeneralizedEventListener(); return; } } } throw new NotSupportedException("Currently, creating more than one SubscriptionContainer/EventListener is not supported."); }
public void Lookup_VariousSourceDefinitionsWithUniqueSourceName_RegistrationsShouldBeUnique() { var source1WithoutSpecificEvent = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1"); var source1WithSpecificEvent10 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 10); var source1WithSpecificEvent20 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 20); var source2WithSpecificEvent30 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source2" && d.EventId == 30); IInternalSubscriptionHandler[] handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { source1WithoutSpecificEvent, source1WithSpecificEvent10 }.AsReadOnly())), Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { source1WithSpecificEvent10 //source1WithSpecificEvent20, //source2WithSpecificEvent30 }.AsReadOnly())) }; var sut = new EventListenerParameters(handlers).Lookup.Value; var def10 = new SourceDefinitionLookup(source1WithSpecificEvent10.EventSource, source1WithSpecificEvent10.EventId.Value, true); var def20 = new SourceDefinitionLookup(source1WithSpecificEvent20.EventSource, source1WithSpecificEvent20.EventId.Value, true); var def10r = sut[def10].ToList(); var def20r = sut[def20].ToList(); Assert.True(sut.Count == handlers.Count()); }
public void Lookup_WithEventDefinitionExistedNameNotExistedEventId_ShouldServeNoHandler() { var source1_Event10 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 10); var source1_Event20 = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 20); var handlers = new IInternalSubscriptionHandler[] { Mock.Of <IInternalSubscriptionHandler>(h => h.Subscription == Mock.Of <ISubscription>(s => s.Id == Guid.NewGuid().ToString() && s.Events == new List <ISourceDefinition> { source1_Event10, source1_Event20 }.AsReadOnly())) }; var notExisted = Mock.Of <ISourceDefinition>(d => d.EventSource == "Source1" && d.EventId == 30); var sut = new EventListenerParameters(handlers).Lookup.Value; var actual = sut[new SourceDefinitionLookup(notExisted, true)]; Assert.True(actual.Count() == 0); }