/// <summary> /// Constructs a matcher that compares properties between anonymous types. /// </summary> /// <param name="expected"></param> /// <returns></returns> public static TMessage Matches <TMessage>(object expected) where TMessage : class { return(Match.Create <TMessage>( CreateMatcher <TMessage>(expected), () => AnonymousType.Matches <TMessage>(expected))); }
/// <summary> /// Configures a <see cref="ISendEndpoint"/> mock to expect a expected. Returned mock can be verified. /// </summary> /// <param name="mockEndpointProvider"></param> /// <param name="expected"></param> /// <typeparam name="TMessage"></typeparam> /// <returns></returns> public static Mock <ISendEndpoint> SetupMessage <TMessage>(this Mock <ISendEndpointProvider> mockEndpointProvider, object expected) where TMessage : class { if (!EndpointConvention.TryGetDestinationAddress <TMessage>(out var destinationAddress)) { // this is just a mock, so the real value shouldn't matter here as long as we're not mixing // integration tests and mock tests in the same suite. Use the same convention as the // MassTransitInMemoryTestHarness just in case... EndpointConvention.Map <TMessage>(new Uri("http://localhost/input-queue")); } var mockEndpoint = new Mock <ISendEndpoint>(); mockEndpointProvider .Setup(x => x.GetSendEndpoint(It.IsAny <Uri>())) .Returns(Task.FromResult(mockEndpoint.Object)) .Verifiable(); mockEndpoint .Setup(x => x.Send <TMessage>(AnonymousType.Matches <TMessage>(expected), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Verifiable(); return(mockEndpoint); }