0

这是我的测试,我想将一个变量传递给函数 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());
    }
4

1 回答 1

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());
            }
于 2019-01-17T08:32:18.850 回答