public async Task <ProductDomain> Get(int sku) { ProductDomain product = await _productReadOnlyRepository.Get(sku); if (product == null) { throw new DomainException("Sku não foi encontrado."); } if (product.Inventory != null) { if (product.Inventory.Warehouses.Any()) { product.Inventory.Quantity = product.Inventory.Warehouses.Sum(x => x.Quantity); if (product.Inventory.Quantity > 0) { product.IsMarketable = true; } else { product.IsMarketable = false; } } } return(product); }
public async Task Add(ProductDomain product) { CheckIfProductExists(product.Sku); await _productWriteOnlyRepository.Add(product); }
public void FindProductDomain6() { // endpoints is not null and not empty // regionIds is not empty // productDomains is not empty var endpoints = new List <Endpoint>(); ISet <string> regionIds = new HashSet <string>(); regionIds.Add("regionId"); var productDomains = new List <ProductDomain>(); var productDomain = new ProductDomain("productName", "productDomain"); productDomains.Add(productDomain); var endpoint = new Endpoint("endpointName", regionIds, productDomains); endpoints.Add(endpoint); // productName id not exist var result = Endpoint.FindProductDomain("regionId", "notExistProductName", endpoints); Assert.Null(result); // productName id exist result = Endpoint.FindProductDomain("regionId", "productName", endpoints); Assert.NotNull(result); Assert.Equal("productDomain", result.DomianName); }
private static void CreateProduct(IUnitOfWork uow) { Console.WriteLine("Create Product!"); Console.WriteLine("---------------"); Console.WriteLine(); Console.Write("Please, enter the name of your product: "); var productName = Console.ReadLine(); Console.Write("Please, enter the id of the related collection: "); var collectionIdStr = Console.ReadLine(); var collectionId = int.Parse(collectionIdStr); var product = new ProductDomain { Name = productName, CollectionId = collectionId }; uow.ProductRepository.Create(product); uow.SaveChanges(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Product successfully ceated."); Console.ForegroundColor = ConsoleColor.Gray; }
private List <Endpoint> GetEndpointsFromLocation(String regionId, String product, Credential credential, String locationProduct, String locationEndpointType) { if (null == locationEndpoints) { locationEndpoints = new List <Endpoint>(); } Endpoint endpoint = FindLocationEndpointByRegionId(regionId); if (null == endpoint || CacheTimeHelper.CheckCacheIsExpire(product, regionId)) { FillEndpointFromLocation(regionId, product, credential, locationProduct, locationEndpointType); } else { List <ProductDomain> productDomains = endpoint.ProductDomains; ProductDomain productDomain = FindProductDomain(productDomains, product); if (null == productDomain) { FillEndpointFromLocation(regionId, product, credential, locationProduct, locationEndpointType); } } return(locationEndpoints); }
public override HttpRequest SignRequest(Signer signer, AlibabaCloudCredentials credentials, FormatType?format, ProductDomain domain) { var imutableMap = new Dictionary <string, string>(QueryParameters); if (null != signer && null != credentials) { var accessKeyId = credentials.GetAccessKeyId(); var accessSecret = credentials.GetAccessKeySecret(); switch (credentials) { case BasicSessionCredentials sessionCredentials: { var sessionToken = sessionCredentials.GetSessionToken(); if (null != sessionToken) { QueryParameters.Add("SecurityToken", sessionToken); } break; } case BearerTokenCredential credential: { var bearerToken = credential.GetBearerToken(); if (null != bearerToken) { QueryParameters.Add("BearerToken", bearerToken); } break; } } imutableMap = Composer.RefreshSignParameters(QueryParameters, signer, accessKeyId, format); imutableMap.Add("RegionId", RegionId); var paramsToSign = new Dictionary <string, string>(imutableMap); if (BodyParameters != null && BodyParameters.Count > 0) { var formParams = new Dictionary <string, string>(this.BodyParameters); string formStr = ConcatQueryString(formParams); byte[] formData = System.Text.Encoding.UTF8.GetBytes(formStr); SetContent(formData, "UTF-8", FormatType.FORM); foreach (var formParam in formParams) { DictionaryUtil.Add(paramsToSign, formParam.Key, formParam.Value); } } var strToSign = this.Composer.ComposeStringToSign(Method, null, signer, paramsToSign, null, null); var signature = signer.SignString(strToSign, accessSecret + "&"); imutableMap.Add("Signature", signature); StringToSign = strToSign; } Url = ComposeUrl(domain.DomianName, imutableMap); return(this); }
public void TestInitialize() { this.Connection = new SqlConnection(@"data source=(localdb)\MSSQLLocalDB;initial catalog=SimpleDAO.Tests.Database;integrated security=True;MultipleActiveResultSets=True;"); this.Connection.Open(); this.CurrentCollectionId = this.GetNextId("Collection"); this.BaseProductId = this.GetNextId("Product"); this.NbProducts = 5; var collection = new CollectionDomain { Id = this.CurrentCollectionId, Name = "Collection" }; this.Create(collection); for (int i = 0; i < this.NbProducts; i++) { var product = new ProductDomain { Id = this.BaseProductId + i, CollectionId = this.CurrentCollectionId, Name = "Product " + i, Price = i * 5 }; this.Create(product); } }
public void GetEndpoints3() { DefaultProfile.ClearDefaultProfile(); // Mock RegionIds ISet <string> regionIds = new HashSet <string>(); regionIds.Add("cn-hangzhou"); // Mock productDomains var productDomains = new List <ProductDomain>(); var productDomain = new ProductDomain("Ess", "ess.aliyuncs.com"); productDomains.Add(productDomain); // Mock endpoint var endpoint = new Endpoint("cn-hangzhou", regionIds, productDomains); var mock = new Mock <DefaultProfile>(true); mock.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); var profile = mock.Object; profile.GetEndpoints("product", "regionId", "serviceCode", "endpointType"); }
public HttpResponseMessage GetListProduct(int?id = null) { var pDomain = new ProductDomain(); var product = pDomain.GetList(id); var res = new BaseResponse <List <ProductAPIViewModel> >(); if (product != null) { res = new BaseResponse <List <ProductAPIViewModel> >() { Data = product, Message = "Success", Success = true, ResultCode = (int)ResultEnum.Success }; return(new HttpResponseMessage() { Content = new JsonContent(res), StatusCode = HttpStatusCode.OK }); } res = new BaseResponse <List <ProductAPIViewModel> >() { Data = null, Message = "Failed", Success = false, ResultCode = (int)ResultEnum.Fail }; return(new HttpResponseMessage() { Content = new JsonContent(res), StatusCode = HttpStatusCode.NoContent }); }
public List <Endpoint> GetEndpoints(String regionId, String product, Credential credential, String locationProduct) { if (null != locationProduct) { //先自动寻址,找不到再找本地配置 List <Endpoint> endPoints = GetEndPointsFromLocation(regionId, product, credential, locationProduct); Endpoint endpoint = FindLocationEndpointByRegionId(regionId); if (null == endpoint) { return(GetEndPointsFromLocal()); } else { List <ProductDomain> productDomains = endpoint.ProductDomains; ProductDomain productDomain = FindProductDomain(productDomains, product); if (null == productDomain) { return(GetEndPointsFromLocal()); } } return(endPoints); } //直接从本地配置中查找 return(GetEndPointsFromLocal()); }
private void PreCheckProductDomain(ProductDomain entity) { if (entity == null) { throw new ArgumentNullException("entity"); } if (string.IsNullOrEmpty(entity.ProductDomainName.Content)) { throw new BizException(ResouceManager.GetMessageString("IM.Product", "ProductDomainPreCheckProductDomainResult1")); } if ((entity.ProductDomainLeaderUserSysNo ?? 0) <= 0) { throw new BizException(ResouceManager.GetMessageString("IM.Product", "ProductDomainPreCheckProductDomainResult2")); } if (da.ExistSameProductDomainName(entity.ProductDomainName.Content, entity.SysNo ?? 0, entity.CompanyCode)) { throw new BizException(ResouceManager.GetMessageString("IM.Product", "ProductDomainPreCheckProductDomainResult3")); } if (entity.DepartmentMerchandiserSysNoList != null && entity.DepartmentMerchandiserSysNoList.Any()) { for (int i = 0; i < entity.DepartmentMerchandiserSysNoList.Count; i++) { var e = entity.DepartmentMerchandiserSysNoList[i]; if ((e ?? 0) <= 0) { throw new BizException(i + ResouceManager.GetMessageString("IM.Product", "ProductDomainPreCheckProductDomainResult4")); } } } }
private List <Endpoint> GetEndPointsFromLocation(String regionId, String product, Credential credential, String locationProduct) { if (null == locationEndpoints) { locationEndpoints = new List <Endpoint>(); } Endpoint endpoint = FindLocationEndpointByRegionId(regionId); if (null == endpoint) { FillEndPointFromLocation(regionId, product, credential, locationProduct); } else { List <ProductDomain> productDomains = endpoint.ProductDomains; ProductDomain productDomain = FindProductDomain(productDomains, product); if (null == productDomain) { FillEndPointFromLocation(regionId, product, credential, locationProduct); } } return(locationEndpoints); }
public override HttpRequest SignRequest(Signer signer, AlibabaCloudCredentials credentials, FormatType?format, ProductDomain domain) { if (this.BodyParameters != null && this.BodyParameters.Count > 0) { Dictionary <String, String> formParams = new Dictionary <String, String>(this.BodyParameters); string formStr = ConcatQueryString(formParams); byte[] formData = System.Text.Encoding.UTF8.GetBytes(formStr); this.SetContent(formData, "UTF-8", FormatType.FORM); } Dictionary <string, string> imutableMap = new Dictionary <string, string>(this.Headers); if (null != signer && null != credentials) { String accessKeyId = credentials.GetAccessKeyId(); imutableMap = Composer.RefreshSignParameters(Headers, signer, accessKeyId, format); if (credentials is BasicSessionCredentials) { String sessionToken = ((BasicSessionCredentials)credentials).GetSessionToken(); if (null != sessionToken) { imutableMap.Add("x-acs-security-token", sessionToken); } } String strToSign = Composer.ComposeStringToSign(Method, uriPattern, signer, QueryParameters, imutableMap, pathParameters); String signature = signer.SignString(strToSign, credentials); DictionaryUtil.Add(imutableMap, "Authorization", "acs " + accessKeyId + ":" + signature); } Url = this.ComposeUrl(domain.DomianName, QueryParameters); this.Headers = imutableMap; return(this); }
public HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId, Credential credential, ISigner signer, FormatType?format, List <Endpoint> endpoints) where T : AcsResponse { FormatType?requestFormatType = request.AcceptFormat; if (null != requestFormatType) { format = requestFormatType; } if (null == request.RegionId) { request.RegionId = regionId; } ProductDomain domain = Endpoint.FindProductDomain(regionId, request.Product, endpoints, this); if (null == domain) { throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access."); } HttpRequest httpRequest = request.SignRequest(signer, credential, format, domain); int retryTimes = 1; HttpResponse response = HttpResponse.GetResponse(httpRequest, timeoutInMilliSeconds); while (500 <= response.Status && autoRetry && retryTimes < maxRetryNumber) { httpRequest = request.SignRequest(signer, credential, format, domain); response = HttpResponse.GetResponse(httpRequest, timeoutInMilliSeconds); retryTimes++; } return(response); }
public override HttpRequest SignRequest(Signer signer, AlibabaCloudCredentials credentials, FormatType? format, ProductDomain domain) { var httpRequest = new HttpRequest(); httpRequest.Url = "Instance by MockAcsRequest"; return httpRequest; }
public virtual HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId, AlibabaCloudCredentials credentials, Signer signer, FormatType?format, List <Endpoint> endpoints) where T : AcsResponse { FormatType?requestFormatType = request.AcceptFormat; if (null != requestFormatType) { format = requestFormatType; } ProductDomain domain = null; if (request.ProductDomain != null) { domain = request.ProductDomain; } else { domain = Endpoint.FindProductDomain(regionId, request.Product, endpoints); } if (null == domain) { throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access."); } request.Headers["User-Agent"] = UserAgent.Resolve(request.GetSysUserAgentConfig(), this.userAgentConfig); bool shouldRetry = true; for (int retryTimes = 0; shouldRetry; retryTimes++) { shouldRetry = autoRetry && retryTimes < maxRetryNumber; HttpRequest httpRequest = request.SignRequest(signer, credentials, format, domain); HttpResponse response; response = this.GetResponse(httpRequest); PrintHttpDebugMsg(request, response); if (response.Content == null) { if (shouldRetry) { continue; } else { throw new ClientException("SDK.ConnectionReset", "Connection reset."); } } if (500 <= response.Status && shouldRetry) { continue; } return(response); } return(null); }
public void DoAction5() { Environment.SetEnvironmentVariable("DEBUG", "sdk"); var status = 200; var code = "ThisIsCode1"; var message = "ThisIsMessage1"; var requestId = "ThisIsRequestId1"; var response = new HttpResponse(); var content = Encoding.GetEncoding("UTF-8") .GetBytes("{\"Code\":\"" + code + "\",\"Message\":\"" + message + "\",\"RequestId\":\"" + requestId + "\"}"); response.ContentType = FormatType.JSON; response.Content = content; response.Status = status; var tmpHeaders = new Dictionary <string, string> { { "Content-MD5", "md5" }, { "Content-Length", "length" }, { "Content-Type", "text/json" } }; response.Headers = tmpHeaders; var mockInstance = new Mock <DefaultAcsClient> { CallBase = true }; mockInstance.Setup(foo => foo.GetResponse( It.IsAny <HttpRequest>() )).Returns(response); var instance = mockInstance.Object; // Mock AcsResquest var request = new MockAcsRequestForDefaultAcsClient(); request.AcceptFormat = FormatType.JSON; var productDomain = new ProductDomain("productName1", "productDomain1"); request.ProductDomain = productDomain; // Mock AlibabaCloudCredentials var mockCredentials = new Mock <AlibabaCloudCredentials>(); var credentials = mockCredentials.Object; // Mock Signer Signer signer = new HmacSHA1Signer(); var result = instance.DoAction(request, true, 1, "cn-hangzhou", credentials, signer, FormatType.JSON, null); Assert.Null(Environment.GetEnvironmentVariable("DEBUG")); status = 500; result = instance.DoAction(request, true, 0, "cn-hangzhou", credentials, signer, FormatType.JSON, null); Assert.Null(Environment.GetEnvironmentVariable("DEBUG")); }
public async Task ExecuteAsync(DeleteProductCommand command) { var productCategoryDomain = new ProductDomain(_domainService.WriteService); productCategoryDomain.Delete(command.Id); await _domainService.ApplyChangesAsync(productCategoryDomain); }
public void SetEndpoint(string endpoint) { ProductDomain = new ProductDomain { ProductName = Product, DomianName = endpoint }; }
public void GetEndpoints6() { DefaultProfile.ClearDefaultProfile(); // Mock RegionIds ISet <String> regionIds = new HashSet <String>(); regionIds.Add("cn-hangzhou"); // Mock productDomains List <ProductDomain> productDomains = new List <ProductDomain>() { }; ProductDomain productDomain = new ProductDomain("Ess", "ess.aliyuncs.com"); productDomains.Add(productDomain); // Mock endpoint Endpoint endpoint = new Endpoint("cn-hangzhou", regionIds, productDomains); var mock1 = new Mock <DefaultProfile>(true); mock1.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock1.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); DefaultProfile profile = mock1.Object; // When Get endpoint is not null List <Endpoint> endpoints1 = profile.GetEndpoints("cn-hangzhou", "Ess"); Assert.NotNull(endpoints1); // When Get endpoint is null endpoint = null; mock1.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock1.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); profile = mock1.Object; List <Endpoint> endpoints2 = profile.GetEndpoints("productNotExist", "regionId", "serviceCode", "endpointType"); Assert.Equal(endpoints1, endpoints2); }
private void InsertProduct(ProductDomain product) { List <ProductDomain> ListProducts = new List <ProductDomain>(); product.Quantity = 10; ListProducts.Add(product); MachineDomain.AvailableProducts.AddRange(ListProducts); }
public Task ExecuteAsync(DeleteProductCommand command) { var productCategoryDomain = new ProductDomain(_writeService); productCategoryDomain.Delete(command.Id); _domainService.ApplyChanges(productCategoryDomain); return(Task.CompletedTask); }
public DefaultAcsClient MockDefaultAcsClient( int status = 200, string code = "ThisIsCode", string message = "ThisIsMessage", string requestId = "ThisIsRequestId" ) { // Mock RegionIds ISet<string> regionIds = new HashSet<string>(); regionIds.Add("cn-hangzhou"); // Mock productDomains var productDomains = new List<ProductDomain>(); var productDomain = new ProductDomain("Ess", "ess.aliyuncs.com"); productDomains.Add(productDomain); // Mock endpoint var endpoint = new Endpoint("cn-hangzhou", regionIds, productDomains); // Mock endpoints var endpoints = new List<Endpoint>(); endpoints.Add(endpoint); // Mock response var response = new HttpResponse(); var content = Encoding.GetEncoding("UTF-8") .GetBytes("{\"Code\":\"" + code + "\",\"Message\":\"" + message + "\",\"RequestId\":\"" + requestId + "\"}"); response.ContentType = FormatType.JSON; response.Content = content; response.Status = status; // Mock credential var credential = new Credential(AKID, AKSE); // Mock Profile var mockProfile = new Mock<IClientProfile>(); mockProfile.Setup(foo => foo.GetCredential()).Returns(credential); var profile = mockProfile.Object; // Mock DefaultAcsClient var mockDefaultAcsClient = new Mock<DefaultAcsClient>(profile); mockDefaultAcsClient.Setup(foo => foo.DoAction( It.IsAny<AcsRequest<AcsResponse>>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<AlibabaCloudCredentials>(), It.IsAny<Signer>(), It.IsAny<FormatType>(), It.IsAny<List<Endpoint>>() )).Returns(response); var instance = mockDefaultAcsClient.Object; return instance; }
private void Create(ProductDomain domain) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = String.Format("INSERT INTO Product VALUES ({0}, '{1}', {2}, {3})", domain.Id, domain.Name, domain.Price, domain.CollectionId); cmd.CommandType = CommandType.Text; cmd.Connection = this.Connection; var nbRow = cmd.ExecuteNonQuery(); }
public void TestAddEndpointWithNullParam() { string productId = "mock_product_id"; string regionId = "mock_region_id"; EndpointUserConfig.AddEndpoint(productId, regionId, null); ProductDomain productDomain = EndpointUserConfig.GetProductDomain(productId, regionId); Assert.Null(productDomain); }
public static void UpdateProduct(ProductDomain prod) { var product = Products.SingleOrDefault(p => p.Sku == prod.Sku); if (product != null) { DeleteProduct(prod.Sku); CreateProduct(prod); } }
public ProductDomain Update(ProductDomain entity) { DataCommand cmd = DataCommandManager.GetDataCommand("ProductDomain_UpdateProductDomain"); cmd.SetParameterValue <ProductDomain>(entity); cmd.ExecuteNonQuery(); return(entity); }
public async Task <HttpResponse> DoActionAsync <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId, AlibabaCloudCredentials credentials, Signer signer, FormatType?format, List <Endpoint> endpoints, CancellationToken ct) where T : AcsResponse { FormatType?requestFormatType = request.AcceptFormat; if (null != requestFormatType) { format = requestFormatType; } ProductDomain domain = null; if (request.ProductDomain != null) { domain = request.ProductDomain; } else { domain = Endpoint.FindProductDomain(regionId, request.Product, endpoints); } if (null == domain) { throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access."); } bool shouldRetry = true; for (int retryTimes = 0; shouldRetry; retryTimes++) { shouldRetry = autoRetry && retryTimes < maxRetryNumber; HttpRequest httpRequest = request.SignRequest(signer, credentials, format, domain); HttpResponse response; response = await HttpResponse.GetResponseAsync(httpRequest, ct).ConfigureAwait(false); if (response.Content == null) { if (shouldRetry) { continue; } else { throw new ClientException("SDK.ConnectionReset", "Connection reset."); } } if (500 <= response.Status && shouldRetry) { continue; } return(response); } return(null); }
public static ProductViewModel Create(ProductDomain productViewModel) { return(new ProductViewModel { Id = productViewModel.Id, Name = productViewModel.Name, ReleaseDate = productViewModel.ReleaseDate, Type = productViewModel.Type, Customer = CustomerViewModelFactory.Create(productViewModel.Customer) }); }
public void DoAction3() { // When // request.AcceptFormat is not null // request.ProductDomain is not null // domain is not null // response.Content is not null // response.Status != 200 // Mock response var status = 400; var code = "ThisIsCode"; var message = "ThisIsMessage"; var requestId = "ThisIsRequestId"; var response = new HttpResponse(); var content = Encoding.GetEncoding("UTF-8") .GetBytes("{\"Code\":\"" + code + "\",\"Message\":\"" + message + "\",\"RequestId\":\"" + requestId + "\"}"); response.ContentType = FormatType.JSON; response.Content = content; response.Status = status; var mockInstance = new Mock <DefaultAcsClient> { CallBase = true }; mockInstance.Setup(foo => foo.GetResponse( It.IsAny <HttpRequest>() )).Returns(response); var instance = mockInstance.Object; // Mock AcsResquest var request = new MockAcsRequestForDefaultAcsClient(); request.AcceptFormat = FormatType.JSON; var productDomain = new ProductDomain("productName", "productDomain"); request.ProductDomain = productDomain; // Mock AlibabaCloudCredentials var mockCredentials = new Mock <AlibabaCloudCredentials>(); var credentials = mockCredentials.Object; // Mock Signer Signer signer = new HmacSHA1Signer(); var result = instance.DoAction(request, true, 1, "cn-hangzhou", credentials, signer, FormatType.JSON, null); Assert.NotNull(result); Assert.Equal(result.Status, response.Status); }