public ActionResult DeleteCart() { CartServiceClient CartService = new CartServiceClient(); string Email = User.Identity.Name; CartService.DeleteCartAsync(Email); return RedirectToAction("Index", "Home"); }
public async Task GetItem_NoAddItemBefore_EmptyCartReturned() { // Setup test server and client using var server = await _host.StartAsync(); var httpClient = server.GetTestClient(); string userId = Guid.NewGuid().ToString(); // Create a GRPC communication channel between the client and the server var channel = GrpcChannel.ForAddress(httpClient.BaseAddress, new GrpcChannelOptions { HttpClient = httpClient }); var cartClient = new CartServiceClient(channel); var request = new GetCartRequest { UserId = userId, }; var cart = await cartClient.GetCartAsync(request); Assert.NotNull(cart); // All grpc objects implement IEquitable, so we can compare equality with by-value semantics Assert.Equal(new Cart(), cart); }
public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var config = resolver.GetService <IConfiguration>(); var cartChannel = new Channel(config["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(config["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(config["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(config["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(config["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); }); }
public ActionResult DeleteCartItem(ShoppingCartItem Cart) { CartServiceClient cartService = new CartServiceClient(); string Email = User.Identity.Name; cartService.DeleteItem(Email, Cart.ProductID); return View(); }
private void RegisterGrpcServices(IServiceCollection services) { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); }
public CoolStoreResolverService( CatalogServiceClient catalogServiceClient, CartServiceClient cartServiceClient, InventoryServiceClient inventoryServiceClient, RatingServiceClient ratingServiceClient, ReviewServiceClient reviewServiceClient) { _catalogServiceClient = catalogServiceClient; _cartServiceClient = cartServiceClient; _inventoryServiceClient = inventoryServiceClient; _ratingServiceClient = ratingServiceClient; _reviewServiceClient = reviewServiceClient; }
public CoolStoreResolverService( IHttpContextAccessor httpContext, CatalogServiceClient catalogServiceClient, CartServiceClient cartServiceClient, InventoryServiceClient inventoryServiceClient, RatingServiceClient ratingServiceClient) { _httpContext = httpContext; _catalogServiceClient = catalogServiceClient; _cartServiceClient = cartServiceClient; _inventoryServiceClient = inventoryServiceClient; _ratingServiceClient = ratingServiceClient; }
public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>(); services.AddSingleton <CoolStoreSchema>(); services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore); services.AddSignalR(options => options.EnableDetailedErrors = true) .AddQueryStreamHubWithTracing(); services.AddCors(options => { options.AddDefaultPolicy(policy => { policy.WithOrigins("*"); policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.AllowCredentials(); policy.WithHeaders("X-Requested-With", "authorization"); }); }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }); }
public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>(); services.AddSingleton <CoolStoreSchema>(); services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore); services.AddCors(options => { options.AddPolicy("CorsPolicy", policy => policy .AllowAnyMethod() .AllowAnyHeader() /* https://github.com/aspnet/AspNetCore/issues/4457 */ .SetIsOriginAllowed(host => true) .AllowCredentials()); }); services.AddSignalR(options => options.EnableDetailedErrors = true) .AddQueryStreamHubWithTracing(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }); }
public async Task AddItem_New_Inserted() { // Setup test server and client using var server = await _host.StartAsync(); var httpClient = server.GetTestClient(); string userId = Guid.NewGuid().ToString(); // Create a GRPC communication channel between the client and the server var channel = GrpcChannel.ForAddress(httpClient.BaseAddress, new GrpcChannelOptions { HttpClient = httpClient }); // Create a proxy object to work with the server var client = new CartServiceClient(channel); var request = new AddItemRequest { UserId = userId, Item = new CartItem { ProductId = "1", Quantity = 1 } }; await client.AddItemAsync(request); var getCartRequest = new GetCartRequest { UserId = userId }; var cart = await client.GetCartAsync(getCartRequest); Assert.NotNull(cart); Assert.Equal(userId, cart.UserId); Assert.Single(cart.Items); await client.EmptyCartAsync(new EmptyCartRequest { UserId = userId }); cart = await client.GetCartAsync(getCartRequest); Assert.Empty(cart.Items); }
public async Task AddItem_ItemExists_Updated() { // Setup test server and client using var server = await _host.StartAsync(); var httpClient = server.GetTestClient(); string userId = Guid.NewGuid().ToString(); // Create a GRPC communication channel between the client and the server var channel = GrpcChannel.ForAddress(httpClient.BaseAddress, new GrpcChannelOptions { HttpClient = httpClient }); var client = new CartServiceClient(channel); var request = new AddItemRequest { UserId = userId, Item = new CartItem { ProductId = "1", Quantity = 1 } }; // First add - nothing should fail await client.AddItemAsync(request); // Second add of existing product - quantity should be updated await client.AddItemAsync(request); var getCartRequest = new GetCartRequest { UserId = userId }; var cart = await client.GetCartAsync(getCartRequest); Assert.NotNull(cart); Assert.Equal(userId, cart.UserId); Assert.Single(cart.Items); Assert.Equal(2, cart.Items[0].Quantity); // Cleanup await client.EmptyCartAsync(new EmptyCartRequest { UserId = userId }); }
public async Task AddItem_New_Inserted() { string userId = Guid.NewGuid().ToString(); // Construct server's Uri string targetUri = $"{serverHostName}:{port}"; // Create a GRPC communication channel between the client and the server var channel = new Channel(targetUri, ChannelCredentials.Insecure); // Create a proxy object to work with the server var client = new CartServiceClient(channel); var request = new AddItemRequest { UserId = userId, Item = new CartItem { ProductId = "1", Quantity = 1 } }; await client.AddItemAsync(request); var getCartRequest = new GetCartRequest { UserId = userId }; var cart = await client.GetCartAsync(getCartRequest); Assert.NotNull(cart); Assert.Equal(userId, cart.UserId); Assert.Single(cart.Items); await client.EmptyCartAsync(new EmptyCartRequest { UserId = userId }); cart = await client.GetCartAsync(getCartRequest); Assert.Empty(cart.Items); }
public async Task AddItem_ItemExists_Updated() { string userId = Guid.NewGuid().ToString(); // Construct server's Uri string targetUri = $"{serverHostName}:{port}"; // Create a GRPC communication channel between the client and the server var channel = new Channel(targetUri, ChannelCredentials.Insecure); var client = new CartServiceClient(channel); var request = new AddItemRequest { UserId = userId, Item = new CartItem { ProductId = "1", Quantity = 1 } }; // First add - nothing should fail await client.AddItemAsync(request); // Second add of existing product - quantity should be updated await client.AddItemAsync(request); var getCartRequest = new GetCartRequest { UserId = userId }; var cart = await client.GetCartAsync(getCartRequest); Assert.NotNull(cart); Assert.Equal(userId, cart.UserId); Assert.Single(cart.Items); Assert.Equal(2, cart.Items[0].Quantity); // Cleanup await client.EmptyCartAsync(new EmptyCartRequest { UserId = userId }); }
public async Task GetItem_NoAddItemBefore_EmptyCartReturned() { string userId = Guid.NewGuid().ToString(); // Create a GRPC communication channel between the client and the server using (var channel = GrpcChannel.ForAddress(TargetUrl)) { var client = new CartServiceClient(channel); var request = new GetCartRequest { UserId = userId, }; var cart = await client.GetCartAsync(request); Assert.NotNull(cart); // All grpc objects implement IEquitable, so we can compare equality with by-value semantics Assert.Equal(new Cart(), cart); } }
public async Task AddItem_New_Inserted() { string userId = Guid.NewGuid().ToString(); // Create a GRPC communication channel between the client and the server using (var channel = GrpcChannel.ForAddress(TargetUrl)) { // Create a proxy object to work with the server var client = new CartServiceClient(channel); var request = new AddItemRequest { UserId = userId, Item = new CartItem { ProductId = "1", Quantity = 1 } }; await client.AddItemAsync(request); var getCartRequest = new GetCartRequest { UserId = userId }; var cart = await client.GetCartAsync(getCartRequest); Assert.NotNull(cart); Assert.Equal(userId, cart.UserId); Assert.Single(cart.Items); await client.EmptyCartAsync(new EmptyCartRequest { UserId = userId }); cart = await client.GetCartAsync(getCartRequest); Assert.Empty(cart.Items); } }
public async Task GetItem_NoAddItemBefore_EmptyCartReturned() { string userId = Guid.NewGuid().ToString(); // Construct server's Uri string targetUri = $"{serverHostName}:{port}"; // Create a GRPC communication channel between the client and the server var channel = new Channel(targetUri, ChannelCredentials.Insecure); var client = new CartServiceClient(channel); var request = new GetCartRequest { UserId = userId, }; var cart = await client.GetCartAsync(request); Assert.NotNull(cart); // All grpc objects implement IEquitable, so we can compare equality with by-value semantics Assert.Equal(new Cart(), cart); }
public CartController(CartServiceClient cartServiceClient) { _cartServiceClient = cartServiceClient; }
public CartController(CartServiceClient serviceClient) { _serviceClient = serviceClient; }
public ActionResult Cart() { CartServiceClient order = new CartServiceClient(); IEnumerable<kaspi.lab.CartService.ProductDTO> cartList = order.GetCart(User.Identity.Name).AsEnumerable(); return View(cartList); }