title: Moq and attributes
body: <p>I am trying to create a test case where I need to set an attribute on the mocked object. I've been following the answer in <a href="https://stackoverflow.com/questions/540636/can-i-get-moq-to-add-attributes-to-the-mock-class">this question</a> but the attribute is null in the <code>CommandEventProcessingDecorator</code> method.</p>
  
  <pre><code>[Fact]
  public void RaiseEvent_AfterCommandIsExecuted_WhenCommandIsAttributedWithRaiseEventEnabled()
  {
      var command = new FakeCommand();
      Assert.IsAssignableFrom&lt;ICommand&gt;(command);
  
      var eventProcessor = new Mock&lt;IProcessEvents&gt;(MockBehavior.Strict);
      eventProcessor.Setup(x =&gt; x.Raise(command));
  
      var attribute = new RaiseEventAttribute
      {
          Enabled = true
      };
  
      var decorated = new Mock&lt;IHandleCommand&lt;FakeCommand&gt;&gt;(MockBehavior.Strict);
      TypeDescriptor.AddAttributes(decorated.Object, attribute); // Add the attribute
      decorated.Setup(x =&gt; x.Handle(command));
  
      var decorator = new CommandEventProcessingDecorator&lt;FakeCommand&gt;(eventProcessor.Object, () =&gt; decorated.Object);
      decorator.Handle(command);
  
      decorated.Verify(x =&gt; x.Handle(command), Times.Once);
      eventProcessor.Verify(x =&gt; x.Raise(command), Times.Once);
  }
  
  internal sealed class CommandEventProcessingDecorator&lt;TCommand&gt; : IHandleCommand&lt;TCommand&gt; where TCommand : ICommand
  {
      private readonly IProcessEvents _events;
      private readonly Func&lt;IHandleCommand&lt;TCommand&gt;&gt; _handlerFactory;
  
      public CommandEventProcessingDecorator(IProcessEvents events, Func&lt;IHandleCommand&lt;TCommand&gt;&gt; handlerFactory)
      {
          _events = events;
          _handlerFactory = handlerFactory;
      }
  
      public void Handle(TCommand command)
      {
          var handler = _handlerFactory();
          handler.Handle(command);
  
          var attribute = handler.GetType().GetCustomAttribute&lt;RaiseEventAttribute&gt;(); // attribute
          if (attribute != null &amp;&amp; attribute.Enabled)
          {
              _events.Raise(command);
          }
      }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>