public async Task TestSetEndpoint() { var endpoint1 = new TestEndpoint("id1"); var endpoint2 = new TestEndpoint("id1"); var endpoint3 = new TestEndpoint("id3"); IEndpointExecutor executor = await Factory.CreateAsync(endpoint1); Assert.Equal(new List <IMessage>(), endpoint1.Processed); Assert.Equal(new List <IMessage>(), endpoint2.Processed); Assert.Equal(new List <IMessage>(), endpoint3.Processed); await Assert.ThrowsAsync <ArgumentException>(() => executor.SetEndpoint(endpoint3)); await executor.Invoke(Message1); await executor.Invoke(Message1); Assert.Equal(new List <IMessage> { Message1, Message1 }, endpoint1.Processed); Assert.Equal(new List <IMessage>(), endpoint2.Processed); Assert.Equal(new List <IMessage>(), endpoint3.Processed); await executor.SetEndpoint(endpoint2); Assert.Equal(new List <IMessage> { Message1, Message1 }, endpoint1.Processed); Assert.Equal(new List <IMessage>(), endpoint2.Processed); Assert.Equal(new List <IMessage>(), endpoint3.Processed); await executor.Invoke(Message2); await executor.Invoke(Message3); Assert.Equal(new List <IMessage> { Message1, Message1 }, endpoint1.Processed); Assert.Equal(new List <IMessage> { Message2, Message3 }, endpoint2.Processed); Assert.Equal(new List <IMessage>(), endpoint3.Processed); await executor.CloseAsync(); }
public async Task TestSetEndpoint() { var endpoint1 = new TestEndpoint("id"); var endpoint2 = new NullEndpoint("id"); var endpoint3 = new TestEndpoint("id1"); IEndpointExecutor executor = await Factory.CreateAsync(endpoint1, null); Assert.Equal(endpoint1, executor.Endpoint); await Assert.ThrowsAsync <ArgumentNullException>(() => executor.SetEndpoint(null, null)); await Assert.ThrowsAsync <ArgumentException>(() => executor.SetEndpoint(endpoint3, null)); await executor.SetEndpoint(endpoint2, null); Assert.Equal(endpoint2, executor.Endpoint); await executor.CloseAsync(); await Assert.ThrowsAsync <InvalidOperationException>(() => executor.SetEndpoint(endpoint1, null)); }
public async Task TestClose() { var endpoint = new TestEndpoint("id"); IEndpointExecutor executor = await Factory.CreateAsync(endpoint); Task running = executor.Invoke(Default); await executor.CloseAsync(); await running; Assert.True(running.IsCompleted); // ensure this doesn't throw await executor.CloseAsync(); await Assert.ThrowsAsync <InvalidOperationException>(() => executor.Invoke(Default)); await Assert.ThrowsAsync <InvalidOperationException>(() => executor.SetEndpoint(endpoint)); }