测试 gRPC 购物车服务
This commit is contained in:
1 parent
c192d209fd
commit
680ce10fa7
12 files changed
+494
-3
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Grpc.Net.Client;
|
||||
using HelloShop.BasketService.Protos;
|
||||
|
||||
namespace HelloShop.BasketService.FunctionalTests
|
||||
{
|
||||
public class BasketServiceIntegrationTest
|
||||
{
|
||||
private readonly Basket.BasketClient _client;
|
||||
|
||||
public BasketServiceIntegrationTest()
|
||||
{
|
||||
GrpcChannel channel = GrpcChannel.ForAddress(GrpcConstants.GrpcAddress);
|
||||
CallInvoker invoker = channel.Intercept(new AuthenticatedInterceptor());
|
||||
_client = new Basket.BasketClient(invoker);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBasketReturnsBasket()
|
||||
{
|
||||
// Arrange
|
||||
var request = new Empty();
|
||||
|
||||
// Act
|
||||
var reply = await _client.GetBasketAsync(request);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(reply);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateBasketReturnsBasketResponse()
|
||||
{
|
||||
// Arrange
|
||||
var request = new UpdateBasketRequest
|
||||
{
|
||||
Items =
|
||||
{
|
||||
new BasketListItem { ProductId = 1, Quantity = 2 },
|
||||
new BasketListItem { ProductId = 2, Quantity = 3 }
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var reply = await _client.UpdateBasketAsync(request);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, reply.Items.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteBasketReturnsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
var request = new Empty();
|
||||
|
||||
// Act
|
||||
var reply = await _client.DeleteBasketAsync(request);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user