0

所以我安装了这些 nuget 包:

努吉特

最终参考这些参考资料:

参考

我使用 NCrunch。我有这个规格:

namespace GlobPatternMatching.Tests
{
    using FluentAssertions;

    using Machine.Fakes;
    using Machine.Specifications;

    [Subject(typeof(GlobMatching))]
    public class When_Given_Literal : WithSubject<GlobMatching>
    {
        private static string pattern = "path";

        private static string[] result;

        private Establish context => () =>
            {
                pattern = "path";
            };

        private Because of => () => result = Subject.GetGlobs(pattern);

        private It should_return_path_in_the_array = () =>
            {
                result[0].Should().Be("path");
            };
    }
}

对于这个类:

namespace GlobPatternMatching
{
    using System;

    public class GlobMatching
    {
        public string[] GetGlobs(string pattern)
        {
            return pattern.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
        }
    }
}

TDD'ing 直接,我得到空引用异常。当我调试时,我无法单步执行该方法,并且所有规范类字段都是空的.....

我不觉得我错过了什么,但如果你不介意看看我在这里做错了什么,那就太好了。我正在使用最新的 VS2015、NCrunch 等...

4

1 回答 1

2

你不会相信问题是什么...

private Establish context => () =>
{
    pattern = "path";
};

private Because of => () => result = Subject.GetGlobs(pattern);

我已经把=>而不是=......

// ----------------------\/-------
private Establish context = () =>
{
    pattern = "path";
};

// ----------------\/------------    
private Because of = () => result = Subject.GetGlobs(pattern);
于 2016-10-05T13:05:14.300 回答