1

テーブルを取得し、テーブルを解析してテーブルのサブセットを作成するテストを作成しようとしています。CreateSet を使用して既存の型を使用します。

私が直面している問題は、渡されるテーブルの値に応じて異なるリストを作成したいということです。

例えば:

次に: 値があります

name|otherinfo |isApple|isOrange|isMango|

ex1 |someinfo,otherinfo|true |false |false |

ex2 |someinfo,otherinfo|true |true |true |

CreateSet を使用して、これらのフラグに基づいてテーブルのサブセットのリストを作成したいと考えています。

何かのようなもの

List<apples> apples = table.CreateSet<apples>(only get apples).ToList();

しかし、私が試したすべてのliqステートメントは失敗します。ここで「リンゴだけを手に入れる」部分をどのように行うのですか?

**注: また、使用したい型にはこれらの識別子フラグがありません。これらは表にあるだけです。

4

1 に答える 1

1

要するに、あなたはできません。get applesのみを配置するパラメーターのインテリセンスは、それがであることを示していますFunc<T> methodToCreateEachInstance

しかし、それは別の方法がないという意味ではありません

Feature: SpecFlowFeature1
In order to help people on StackOverflow
As a helpful soul
I want to discover how to use CreateSet

Scenario: Retreive and filter a table
  Given I have some values:
      | name | otherinfo          | isApple | isOrange | isMango |
      | ex1  | someinfo,otherinfo | true    | false    | false   |
      | ex2  | someinfo,otherinfo | true    | true     | true    |
  Then MyApples should not be empty

そしてあなたのバインディングで

//using TechTalk.SpecFlow.Assist;
using Should;

public class Example
{
    public string name { get; set; }
    public string otherInfo { get; set; }
}

[Binding]
public class StepBindings
{
    public IEnumerable<Example> MyApples { get; set; }

    [Given(@"I have some values:")]
    public void GivenIHaveSomeValues(Table table)
    {
        var onlyApples = table.Rows.Where(x => bool.Parse(x["isApple"]));

        MyApples = from x in onlyApples
                   select new Example
                   {
                       name = x["name"],
                       otherInfo = x["otherInfo"]
                   };
    }

    [Then(@"MyApples should not be empty")]
    public void ThenMyApplesShouldNotBeEmpty()
    {
        MyApples.ShouldNotBeNull();
        MyApples.ShouldNotBeEmpty();
    }

}
于 2013-03-20T07:52:19.317 に答える