NStub.CSharp.NamespaceDetector.GetDifferingTypeFullname C# (CSharp) Method

GetDifferingTypeFullname() public method

Get the differing namespace part between object to test and unit test module, seen relative from the ShortestNamespace, prefixed with the specified string.
If the full qualified name of the input type is "NStub.CSharp.BuildContext.ISetupAndTearDownContext" and the shortest (the root namespace of the library to test) namespace is "NStub.CSharp", then the output of this method is ".Tests.BuildContext". To build a namespace for the unit test, you simply sum the result in the following way:
public GetDifferingTypeFullname ( CodeTypeDeclaration inputType, string testNamespacePart ) : string
inputType System.CodeDom.CodeTypeDeclaration The type with the input namespace.
testNamespacePart string The additional namespace part of the test project, e.g. ".Test".
return string
        public string GetDifferingTypeFullname(CodeTypeDeclaration inputType, string testNamespacePart)
        {
            string codeNs = inputType.Name;
            var indexcodeNs = inputType.Name.LastIndexOf('.');
            if (indexcodeNs > 0)
            {
                codeNs = inputType.Name.Substring(0, indexcodeNs);
            }

            var combined = codeNs;
            var splitter = codeNs.Split(new[] { this.ShortestNamespace }, StringSplitOptions.RemoveEmptyEntries);
            if (splitter.Length == 0)
            {
                combined = testNamespacePart;
            }
            else if (splitter.Length == 1)
            {
                combined = testNamespacePart + splitter[0];
            }

            return combined;
        }