public CatalogController( ICatalogService catalogService, Catalog.CatalogClient catalogClient) { _catalogService = catalogService; _catalogClient = catalogClient; }
public void SearchProductByEmptyNameTest() { // Arrange var client = new Catalog.CatalogClient(_channel); // Assert Assert.ThrowsAsync <RpcException>(async() => { try { // Act var response = await client.SearchProductByNameAsync(new SearchRequest()); } catch (RpcException ex) when(ex.StatusCode == StatusCode.NotFound) { //test success throw ex; } catch (Exception ex) { //test fail throw new Exception(ex.Message, ex); } }); }
public async Task <IActionResult> Get(CatalogItemsRequest request) { using var channel = GrpcChannel.ForAddress("https://localhost:5005"); var client = new Catalog.CatalogClient(channel); var reply = await client.GetItemsByIdsAsync(request); return(Ok(reply)); }
public async Task <IActionResult> Get(Guid id) { using var channel = GrpcChannel.ForAddress(Environment.GetEnvironmentVariable("catalogurl")); var client = new Catalog.CatalogClient(channel); var request = new CatalogItemRequest { Id = id.ToString() }; var reply = await client.GetItemByIdAsync(request); return(Accepted($"products/{reply}")); }
public async Task <CatalogInfo> GetInfoByAsync(long id) { return(await CallService(_options.Value.Catalog, async channel => { var client = new Catalog.CatalogClient(channel); var request = new CatalogItemRequest { Id = id }; var response = await client.GetInfoByAsync(request); return new CatalogInfo { Title = response.Title }; })); }
public async Task SearchProductByNameAsyncTest() { // Arrange var client = new Catalog.CatalogClient(_channel); var searchRequest = new SearchRequest { Name = "product", PageIndex = 0, PageSize = 10 }; // Act var response = await client.SearchProductByNameAsync(searchRequest); // Assert Assert.True(response.Count == 3); }
public async Task <IActionResult> Post(AddProductModel productModel) { // TODO trak user //command.UserId = Guid.Parse(User.Identity.Name); //Environment.SetEnvironmentVariable("NO_PROXY", "localhost"); GrpcEnvironment.SetLogger(new ConsoleLogger()); Console.WriteLine(Environment.GetEnvironmentVariable("catalogurl")); using var channel = GrpcChannel.ForAddress($"{Environment.GetEnvironmentVariable("catalogurl")}/api/product"); var client = new Catalog.CatalogClient(channel); var request = new AddProductRequest { Name = productModel.Name, Description = productModel.Description, Price = productModel.Price, Image = productModel.Image }; var reply = await client.AddAsyncAsync(request); return(Created($"products/{reply.Id}", reply)); }
public CatalogService(Catalog.CatalogClient client, ILogger <CatalogService> logger) { _client = client; _logger = logger; }
public CatalogService(Catalog.CatalogClient client) { _client = client; }