首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >黄瓜特征文件-描述聚合

黄瓜特征文件-描述聚合
EN

Stack Overflow用户
提问于 2018-10-26 17:18:20
回答 1查看 69关注 0票数 0

我是黄瓜世界的新手,我只想为我的场景描述一个聚合。我有一个模型和一个类似下面的DataTransferObject,我想写一个REST Api,它返回一个JSON。

代码语言:javascript
复制
public class Product {
  int id;
  String name;
  double basePrice;
  ProductCategory category;
}

public class ProductCategory {
  int id;
  String name;
  List<Customization> possibleCustomizationsForCategory;
}

public class Customization {
  int id;
  String characteristic;
  double additionalPrice;
}

public class ProductDTO {
  int productId;
  String productName;
  double basePrice;
  Size size;
  int productCategoryId;
  String productCategoryName;
  List<Integer> possibleCustomizationIds;
}

我想写这样的东西:

代码语言:javascript
复制
Given the system has persisted the following products
When a client requests GET /products
Then he will receive a JSON like the following:
  """
   [
    {
     "productId": 1,
     "productName": "Kaffee",
     "basePrice": 2.00,
     "size": "SMALL",
     "productCategoryId": 1,
     "productCategoryName": "Hot Drinks",
     "possibleCustomizationIds": [1,2,3,4,5,6]
    },
    {
     "productId": 2,
     "productName": "Kaffee",
     "basePrice": 3.0,
     "size": "MEDIUM",
     "productCategoryId": 1,
     "productCategoryName": "Hot Drinks",
     "possibleCustomizationIds": [1,2,3,4,5,6]
    }
    {
     "productId": 3,
     "productName": "Cookie",
     "basePrice": 1.0,
     "size": "SMALL",
     "productCategoryId": 1,
     "productCategoryName": "Biscuite",
     "possibleCustomizationIds": [8,9]
    }
   ]
  """

但是,我如何编写给定的部分并以一种明确的方式描述对象,即存在三个带有聚合的不同类?

EN

回答 1

Stack Overflow用户

发布于 2018-11-06 23:03:53

我会让Gherkin使用一种更具业务级别的语言来描述您试图解决的问题。

然后,我会让步骤定义描述问题的解决方案。

因此,您的小黄瓜可能是:

代码语言:javascript
复制
Given the following products are in stock
   | Product       |
   | Small Kaffee  |
   | Medium Kaffee |
   | Small Cookie  |
When I get a list of stock
Then I the three products should be shown as in stock
And I should be able to view the details about them

我假设这是一个库存控制的情况。然后,此方案可以针对数据库、web api或GUI运行,并且应该仍然正确,只是需要一个不同的解决方案。即使用不同的步骤定义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53005451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档