mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 19:10:51 +08:00 
			
		
		
		
	sticking send messages toself in to make this testable
This commit is contained in:
		
							
								
								
									
										45
									
								
								test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Infrastructure
 | 
			
		||||
{
 | 
			
		||||
    public class InMemoryBusTests
 | 
			
		||||
    {
 | 
			
		||||
        private InMemoryBus<Message> _bus;
 | 
			
		||||
 | 
			
		||||
        public InMemoryBusTests()
 | 
			
		||||
        {
 | 
			
		||||
            _bus = new InMemoryBus<Message>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public async Task should_publish_with_delay()
 | 
			
		||||
        {
 | 
			
		||||
            var called = false;
 | 
			
		||||
            _bus.Subscribe(x => {
 | 
			
		||||
                called = true;
 | 
			
		||||
            });
 | 
			
		||||
            await _bus.Publish(new Message(), 1);
 | 
			
		||||
            await Task.Delay(10);
 | 
			
		||||
            called.ShouldBeTrue();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public async Task should_not_be_publish_yet_as_no_delay_in_caller()
 | 
			
		||||
        {
 | 
			
		||||
            var called = false;
 | 
			
		||||
            _bus.Subscribe(x => {
 | 
			
		||||
                called = true;
 | 
			
		||||
            });
 | 
			
		||||
            await _bus.Publish(new Message(), 1);
 | 
			
		||||
            called.ShouldBeFalse();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        class Message
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user