public async Task RentAsync_OneRentals_ReturnSameClient() { // arrange Mock <ISocketClientFactory> optionsMonitorMock = new(MockBehavior.Strict); Mock <ISocketProtocol> protocol = new(); ISocketClientFactory optionsMonitor = optionsMonitorMock.Object; optionsMonitorMock .Setup(x => x.CreateClient("Foo")) .Returns(() => new SocketClientStub() { Protocol = protocol.Object, Name = "Foo" }); var pool = new SessionPool(optionsMonitor); ISession first = await pool.CreateAsync("Foo"); // act ISession second = await pool.CreateAsync("Foo"); // assert Assert.Equal(first, second); }
public async Task RentAsync_NoRentals_OpenSocketConnection() { // arrange Mock <ISocketClientFactory> optionsMonitorMock = new(MockBehavior.Strict); Mock <ISocketProtocol> protocol = new(); ISocketClientFactory optionsMonitor = optionsMonitorMock.Object; var socket = new SocketClientStub() { Protocol = protocol.Object, Name = "Foo" }; optionsMonitorMock .Setup(x => x.CreateClient("Foo")) .Returns(() => socket); var pool = new SessionPool(optionsMonitor); // act await pool.CreateAsync("Foo"); // assert Assert.Equal(1, socket.GetCallCount(x => x.OpenAsync(default !)));
public async Task RentAsync_NoRentals_ReturnClient() { // arrange Mock <ISocketClientFactory> optionsMonitorMock = new(MockBehavior.Strict); Mock <ISocketProtocol> protocol = new(); ISocketClientFactory optionsMonitor = optionsMonitorMock.Object; optionsMonitorMock .Setup(x => x.CreateClient("Foo")) .Returns(() => new SocketClientStub() { Protocol = protocol.Object, Name = "Foo" }); var pool = new SessionPool(optionsMonitor); // act ISession rented = await pool.CreateAsync("Foo"); // assert optionsMonitorMock.VerifyAll(); Assert.NotNull(rented); }