コード例 #1
0
    void when_checking_namespaces()
    {
        var projectRoot = TestExtensions.GetProjectRoot();
        var sourceFiles = TestExtensions.GetSourceFiles(projectRoot);

        it["processes roughly the correct number of files"] = () => {
            sourceFiles.Count.should_be_greater_than(80);
            sourceFiles.Count.should_be_less_than(150);
        };

        const string namespacePattern         = @"(?:^namespace)\s.*\b";
        string       expectedNamespacePattern = string.Format(@"[^\{0}]*", Path.DirectorySeparatorChar);

        var entitasSourceDir      = dir("Entitas", "Entitas");
        var entitasUnitySourceDir = dir("Entitas.Unity", "Assets", "Entitas", "Unity");

        var each = new Each <string, string, string>();

        foreach (var file in sourceFiles)
        {
            string expectedNamespace;

            var fileName = file.Key
                           .Replace(dir(projectRoot), string.Empty)
                           .Replace(entitasSourceDir + "CodeGenerator", "Entitas.CodeGenerator")
                           .Replace(entitasSourceDir + dir("Serialization", "Blueprints"), "Entitas.Serialization.Blueprints/")
                           .Replace(entitasSourceDir + dir("Serialization", "Configuration"), "Entitas.Serialization.Configuration/")
                           .Replace(entitasSourceDir + "Serialization", "Entitas.Serialization")

                           .Replace(entitasUnitySourceDir + "CodeGenerator", "Entitas.Unity.CodeGenerator")
                           .Replace(entitasUnitySourceDir + "VisualDebugging", "Entitas.Unity.VisualDebugging")
                           .Replace(entitasUnitySourceDir + dir("Serialization", "Blueprints"), "Entitas.Unity.Serialization.Blueprints/")
                           .Replace(entitasUnitySourceDir + "Migration", "Entitas.Unity.Migration");

            if (file.Key.Contains(typeof(Entitas.Feature).Name) ||
                file.Key.Contains("BlueprintEntityExtension"))
            {
                expectedNamespace = "Entitas";
            }
            else
            {
                expectedNamespace = Regex.Match(fileName, expectedNamespacePattern)
                                    .ToString()
                                    .Replace("namespace ", string.Empty)
                                    .Trim();
            }

            var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline)
                                 .ToString()
                                 .Replace("namespace ", string.Empty)
                                 .Trim();

            each.Add(new NSpecTuple <string, string, string>(fileName, foundNamespace, expectedNamespace));
        }

        each.Do((fileName, given, expected) =>
                it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected)
                );
    }
コード例 #2
0
    void when_checking_namespaces()
    {
        var projectRoot = TestExtensions.GetProjectRoot();
        var sourceFiles = TestExtensions.GetSourceFiles(projectRoot);

        it["processes roughly the correct number of files"] = () => {
            sourceFiles.Count.should_be_greater_than(80);
            sourceFiles.Count.should_be_less_than(150);
        };

        const string namespacePattern = @"(?:^namespace)\s.*\b";
        string expectedNamespacePattern = string.Format(@"[^\{0}]*", Path.DirectorySeparatorChar);

        var entitasSourceDir = dir("Entitas", "Entitas");
        var entitasUnitySourceDir = dir("Entitas.Unity", "Assets", "Entitas", "Unity");

        var each = new Each<string, string, string>();

        foreach(var file in sourceFiles) {

            string expectedNamespace;

            var fileName = file.Key
                .Replace(dir(projectRoot), string.Empty)
                .Replace(entitasSourceDir + "CodeGenerator", "Entitas.CodeGenerator")
                .Replace(entitasSourceDir + dir("Serialization", "Blueprints"), "Entitas.Serialization.Blueprints/")
                .Replace(entitasSourceDir + dir("Serialization", "Configuration"), "Entitas.Serialization.Configuration/")
                .Replace(entitasSourceDir + "Serialization", "Entitas.Serialization")

                .Replace(entitasUnitySourceDir + "CodeGenerator", "Entitas.Unity.CodeGenerator")
                .Replace(entitasUnitySourceDir + "VisualDebugging", "Entitas.Unity.VisualDebugging")
                .Replace(entitasUnitySourceDir + dir("Serialization", "Blueprints"), "Entitas.Unity.Serialization.Blueprints/")
                .Replace(entitasUnitySourceDir + "Migration", "Entitas.Unity.Migration");

            if(file.Key.Contains(typeof(Entitas.Feature).Name) ||
                file.Key.Contains("BlueprintEntityExtension")) {
                expectedNamespace = "Entitas";
            } else {
                expectedNamespace = Regex.Match(fileName, expectedNamespacePattern)
                    .ToString()
                    .Replace("namespace ", string.Empty)
                    .Trim();
            }

            var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline)
                .ToString()
                .Replace("namespace ", string.Empty)
                .Trim();

            each.Add(new NSpecTuple<string, string, string>(fileName, foundNamespace, expectedNamespace));
        }

        each.Do((fileName, given, expected) =>
            it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected)
        );
    }
コード例 #3
0
    void when_checking_namespaces()
    {
        var projectRoot = TestExtensions.GetProjectRoot();
        var sourceFiles = TestExtensions.GetSourceFiles(projectRoot);

        it["processes roughly the correct number of files"] = () => {
            sourceFiles.Count.should_be_greater_than(80);
            sourceFiles.Count.should_be_less_than(200);
        };

        System.Console.WriteLine("sourceFiles: " + sourceFiles.Count);

        const string namespacePattern         = @"(?:^namespace)\s.*\b";
        string       expectedNamespacePattern = string.Format(@"[^\{0}]*", Path.DirectorySeparatorChar);

        var addonsDir = dir("Addons");

        var each = new Each <string, string, string>();

        foreach (var file in sourceFiles)
        {
            var fileName = file.Key
                           .Replace(dir(projectRoot), string.Empty)
                           .Replace(addonsDir, string.Empty);

            string expectedNamespace;
            if (file.Key.Contains(typeof(Entitas.Feature).Name))
            {
                expectedNamespace = "Entitas";
            }
            else if (file.Key.Contains("EntityLink.cs"))
            {
                expectedNamespace = "Entitas.Unity";
            }
            else
            {
                expectedNamespace = Regex.Match(fileName, expectedNamespacePattern)
                                    .ToString()
                                    .Replace("namespace ", string.Empty)
                                    .Trim();
            }

            var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline)
                                 .ToString()
                                 .Replace("namespace ", string.Empty)
                                 .Trim();

            each.Add(new NSpecTuple <string, string, string>(fileName, foundNamespace, expectedNamespace));
        }

        each.Do((fileName, given, expected) =>
                it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected)
                );
    }
コード例 #4
0
    void when_checking_namespaces()
    {
        var          entitasDir      = getEntitasProjectDir();
        const string entitasUnity    = "Entitas.Unity";
        var          entitasUnityDir = entitasUnity + _dirChar + "Assets";

        var sourceFiles = getSourceFiles(entitasDir);

        sourceFiles.Count.should_be_greater_than(80);
        sourceFiles.Count.should_be_less_than(150);

        const string namespacePattern         = @"(?:^namespace)\s.*\b";
        string       expectedNamespacePattern = string.Format(@"[^\{0}]*", _dirChar);

        var each = new Each <string, string, string>();

        foreach (var file in sourceFiles)
        {
            var fileName = file.Key
                           .Replace(entitasDir + _dirChar, string.Empty)
                           .Replace(entitasUnityDir + _dirChar, string.Empty)

                           .Replace("Entitas" + _dirChar + "Entitas" + _dirChar + "CodeGenerator", "Entitas.CodeGenerator")
                           .Replace("Entitas" + _dirChar + "Entitas" + _dirChar + "Serialization", "Entitas.Serialization")

                           .Replace("Entitas.Unity" + _dirChar + "CodeGenerator", "Entitas.Unity.CodeGenerator")
                           .Replace("Entitas.Unity" + _dirChar + "VisualDebugging", "Entitas.Unity.VisualDebugging")
                           .Replace("Entitas.Unity" + _dirChar + "Migration", "Entitas.Unity.Migration")
                           .Replace("Entitas.Unity" + _dirChar + "Blueprints", "Entitas.Unity.Blueprints");

            var expectedNamespace = Regex.Match(fileName, expectedNamespacePattern)
                                    .ToString()
                                    .Replace("namespace ", string.Empty)
                                    .Trim();

            var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline)
                                 .ToString()
                                 .Replace("namespace ", string.Empty)
                                 .Trim();

            each.Add(new NSpecTuple <string, string, string>(fileName, foundNamespace, expectedNamespace));
        }

        each.Do((fileName, given, expected) =>
                it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected)
                );
    }
コード例 #5
0
    void when_checking_namespaces()
    {
        var entitasDir = getEntitasProjectDir();
        const string entitasUnity = "Entitas.Unity";
        var entitasUnityDir = entitasUnity + _dirChar + "Assets";

        var sourceFiles = getSourceFiles(entitasDir);

        sourceFiles.Count.should_be_greater_than(80);
        sourceFiles.Count.should_be_less_than(150);

        const string namespacePattern = @"(?:^namespace)\s.*\b";
        string expectedNamespacePattern = string.Format(@"[^\{0}]*", _dirChar);

        var each = new Each<string, string, string>();

        foreach (var file in sourceFiles) {

            var fileName = file.Key
                .Replace(entitasDir + _dirChar, string.Empty)
                .Replace(entitasUnityDir + _dirChar, string.Empty)

                .Replace("Entitas" + _dirChar + "Entitas" + _dirChar + "CodeGenerator", "Entitas.CodeGenerator")
                .Replace("Entitas" + _dirChar + "Entitas" + _dirChar + "Serialization", "Entitas.Serialization")

                .Replace("Entitas.Unity" + _dirChar + "CodeGenerator", "Entitas.Unity.CodeGenerator")
                .Replace("Entitas.Unity" + _dirChar + "VisualDebugging", "Entitas.Unity.VisualDebugging")
                .Replace("Entitas.Unity" + _dirChar + "Migration", "Entitas.Unity.Migration")
                .Replace("Entitas.Unity" + _dirChar + "Blueprints", "Entitas.Unity.Blueprints");

            var expectedNamespace = Regex.Match(fileName, expectedNamespacePattern)
                .ToString()
                .Replace("namespace ", string.Empty)
                .Trim();

            var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline)
                .ToString()
                .Replace("namespace ", string.Empty)
                .Trim();

            each.Add(new NSpecTuple<string, string, string>(fileName, foundNamespace, expectedNamespace));
        }

        each.Do((fileName, given, expected) =>
            it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected)
        );
    }