/// <summary> /// Publishes the specified message to all subscribers /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> public void Publish <T>(T message) where T : class, IMessage { if (message == null) { throw new ArgumentNullException(nameof(message), "You can not publish a null message."); } if (!listeners.ContainsKey(typeof(T))) { return; } // Create a local reference of the collection to protect us against the collection // adding a new subscriber while we're enumerating var listenersToPublishTo = this.listeners[typeof(T)].ToArray(); foreach (INotification <T> handler in listenersToPublishTo) { var attribute = AttributeCache.GetAttribute <MessageVerbosityAttribute>(message.GetType()); if (attribute == null) { handler.ProcessMessage(message); continue; } if (attribute.Scope == this.scope || this.scope == MessageScope.Full) { handler.ProcessMessage(message); } } }
public void Get_generic_attribute_from_type() { // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture>(typeof(TypePoolFixture)); // Assert Assert.IsNotNull(attribute); }
public void Get_attribute_on_type_with_predicate() { // Act Attribute attribute = AttributeCache.GetAttribute(typeof(TypePoolFixture), null, a => a is AttributeFixture); // Assert Assert.IsNotNull(attribute); }
public void Get_generic_attribute_on_type_with_predicate() { // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture>(typeof(TypePoolFixture), null, a => a.IsEnabled); // Assert Assert.IsNotNull(attribute); Assert.IsTrue(attribute.IsEnabled); }
private static void CheckResult(Type attributeType, PropertyInfo property, object obj) { if (AttributeCache.Has(property, attributeType)) { var @attribute = AttributeCache.GetAttribute <BasePropertyAttribute>(property, attributeType); if (@attribute.IsError(obj)) { throw new ApiException(@attribute.Type, property.Name); } } }
public void Get_generic_attribute_from_instance() { // Arrange var fixture = new TypePoolFixture(); // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>(); // Assert Assert.IsNotNull(attribute); }
public void Get_generic_single_attribute_from_instance_property() { // Arrange var fixture = new TypePoolFixture(); var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute)); // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>(property, fixture); // Assert Assert.IsNotNull(attribute); }
public void Get_attribute_from_property_on_type_with_predicate() { // Arrange var fixture = new TypePoolFixture(); var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute)); // Act Attribute attribute = AttributeCache.GetAttribute(typeof(TypePoolFixture), property, a => a is AttributeFixture); // Assert Assert.IsNotNull(attribute); }
public void Get_generic_attribute_from_null_property_and_null_instance_with_predicate() { // Arrange var fixture = new TypePoolFixture(); var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute)); // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>( null, null, a => a.IsEnabled); // Assert Assert.IsNotNull(attribute); }
public void Get_generic_attribute_on_null_type() { // Act AttributeFixture attribute = AttributeCache.GetAttribute <AttributeFixture>(null, null, null); }
public void Get_attribute_on_null_type() { // Act Attribute attribute = AttributeCache.GetAttribute(null, null, null); }