private string AddProductWithSpecificMoneyType(MoneyTestTypes moneyTestTypes) { ProductDraft productDraft = Helper.GetTestProductDraft(_project, _testProductType.Id, _testTaxCategory.Id, moneyTestTypes); Task <Response <Product> > productTask = _client.Products().CreateProductAsync(productDraft); productTask.Wait(); Assert.IsTrue(productTask.Result.Success); Product product = productTask.Result.Result; Assert.NotNull(product.Id); _testProducts.Add(product); return(product.Id); }
/// <summary> /// Get List of Price Drafts Based on project Currencies /// </summary> /// <param name="project"></param> /// <param name="moneyTestType">pass type to identify money type (either CentPrecision or HighPrecisionMoney or Default Money)</param> /// <returns></returns> private static List <PriceDraft> GetListOfPriceDraft(Project.Project project, MoneyTestTypes moneyTestType) { List <PriceDraft> priceDrafts = new List <PriceDraft>(); Func <Money> valueFunc = null; long centAmount = Helper.GetRandomNumber(10, 999999); switch (moneyTestType) { case MoneyTestTypes.HighPrecision: valueFunc = () => new HighPrecisionMoney() { CentAmount = 100, FractionDigits = 3, PreciseAmount = 1000 }; break; case MoneyTestTypes.CentPrecision: valueFunc = () => new CentPrecisionMoney() { CentAmount = centAmount, FractionDigits = 2 }; break; default: valueFunc = () => new Money() { CentAmount = centAmount }; break; } foreach (string currency in project.Currencies) { var value = valueFunc(); value.CurrencyCode = currency; priceDrafts.Add(new PriceDraft(value)); } return(priceDrafts); }
/// <summary> /// Gets a test product draft. /// </summary> /// <param name="project">Project</param> /// <param name="productTypeId">Product type ID</param> /// <param name="taxCategoryId">Tax category ID</param> /// <param name="moneyTestType">pass type to identify money type (either CentPrecision or HighPrecisionMoney or Default Money)</param> /// <returns></returns> public static ProductDraft GetTestProductDraft(Project.Project project, string productTypeId, string taxCategoryId, MoneyTestTypes moneyTestType = MoneyTestTypes.Money) { List <PriceDraft> priceDrafts = GetListOfPriceDraft(project, moneyTestType); string randomSku = Helper.GetRandomString(10); ProductVariantDraft productVariantDraft = new ProductVariantDraft(); productVariantDraft.Sku = randomSku; productVariantDraft.Prices = priceDrafts; ResourceIdentifier productType = new ResourceIdentifier(); productType.Id = productTypeId; productType.TypeId = Common.ReferenceType.ProductType; LocalizedString name = new LocalizedString(); LocalizedString slug = new LocalizedString(); LocalizedString description = new LocalizedString(); LocalizedString metaTitle = new LocalizedString(); LocalizedString metaDescription = new LocalizedString(); LocalizedString metaKeywords = new LocalizedString(); foreach (string language in project.Languages) { name.SetValue(language, string.Concat("Test Product ", language, " ", randomSku)); slug.SetValue(language, string.Concat("test-product-", language, "-", randomSku)); description.SetValue(language, string.Concat("Created by commercetools.NET ", language)); metaTitle.SetValue(language, string.Concat("Product Meta Title ", language)); metaDescription.SetValue(language, string.Concat("Product Meta Description ", language)); metaKeywords.SetValue(language, string.Concat("Product Meta Keywords ", language)); } Reference taxCategory = new Reference(); taxCategory.Id = taxCategoryId; taxCategory.ReferenceType = Common.ReferenceType.TaxCategory; ProductDraft productDraft = new ProductDraft(name, productType, slug); productDraft.Key = Helper.GetRandomString(15); productDraft.Description = description; productDraft.MetaTitle = metaTitle; productDraft.MetaDescription = metaDescription; productDraft.MetaKeywords = metaKeywords; productDraft.TaxCategory = taxCategory; productDraft.MasterVariant = productVariantDraft; return(productDraft); }