storyQ将参数传递给函数

时间:2019-01-15 14:39:57

标签: c# bdd storyq

这是我的测试,我想将一个变量传递给函数ImageSelectionDatabaseIsValidAllTotalGainsAssigned,我希望它为8和7一次检查断言。

但是您不能将参数传递给函数并调用.Then()

您能解释一下如何做到吗?

    [Test]
    public void Set8NewImagesAndTotalGainsRemove2ImagesTest()
    {
        _imageSelectionStory.WithScenario("init new ImagesSelectionViewModel and load 8 new images from database and assign total gain 1,2 to all, and then remove 2 images")
            .Given(InitImageSelectionViewModelAndDatabaseImages)
            .When(SetNewImagesFromDatabase)
            .And(UpdateAssignedToTotalGains)
            .Then(ImageSelectionDatabaseIsValidAllTotalGainsAssigned)
            .Execute();
    }


    private void ImageSelectionDatabaseIsValidAllTotalGainsAssigned()
    {
        foreach (var image in _imagesSelectionViewModel.Images)
        {
            CollectionAssert.AreEqual(new List<double>{1,2}, image.AssignedToTotalGain);
        }
        Assert.AreEqual(8, _imagesSelectionViewModel.Images.Count);
        Assert.True(_imagesSelectionViewModel.IsValid());
    }

1 个答案:

答案 0 :(得分:1)

           [Test]
            public void Set8NewImagesAndTotalGainsRemove2ImagesTest()
            {
                _imageSelectionStory.WithScenario("init new ImagesSelectionViewModel and load 8 new images from database and assign total gain" +
                                                  " 1,2 to all, and then remove 2 images")
                    .Given(InitImageSelectionViewModelAndDatabaseImages)
                    .When(SetNewImagesFromDatabase)
                    .And(UpdateAssignedToTotalGainsAndRemove2Images)
                    .Then(ImageSelectionDatabaseIsValidImagesAllTotalGainsAssigned,6)
                    .Execute();
            }

            private void ImageSelectionDatabaseIsValidImagesAllTotalGainsAssigned(int expected)
            {
               foreach (var image in _imagesSelectionViewModel.Images)
              {
                   CollectionAssert.AreEqual(new List<double> { 1, 2 }, image.AssignedToTotalGain);
              }
              Assert.AreEqual(expected, _imagesSelectionViewModel.Images.Count);
              Assert.True(_imagesSelectionViewModel.IsValid());
            }