Example #1
0
        private string SetUp()
        {
            if (this.setUpTestnameCalled)
            {
                throw new InvalidOperationException("CodeTypeSetup.SetUpTestname() was called the second time.");
            }
            genericPart      = string.Empty;
            currentIsGeneric = false;

            // Adjust OuT with generic types parameters.
            var testObjectType = testClassDeclaration.UserData[NStubConstants.UserDataClassTypeKey] as Type;

            if (testObjectType == null)
            {
                var message = string.Format(CultureInfo.CurrentCulture, "The UserData of the type '{0}' is not correct initialized." +
                                            "Provide the System.Type info about the object under test with the {1} UserData key."
                                            , testClassDeclaration.Name, NStubConstants.UserDataClassTypeKey);
                throw new KeyNotFoundException(message);
            }

            var baseObjectFullname = this.testClassDeclaration.Name;

            baseKey = baseObjectFullname;
            if (testObjectType.IsGenericType)
            {
                var genIndexLast = this.testClassDeclaration.Name.LastIndexOf('`');
                baseObjectFullname = this.testClassDeclaration.Name.Substring(0, genIndexLast);
                //var newName = newNameFirst + "Generic";
                var newName = baseObjectFullname + "Generic";// +"<string>";
                genericPart      = "<string>";
                currentIsGeneric = true;
                this.testClassDeclaration.Name = newName;
            }

            if (testObjectType.IsAssignableFrom(typeof(INotifyPropertyChanged)))
            {
            }
            if (typeof(INotifyPropertyChanged).IsAssignableFrom(testObjectType))
            {
                var bd = buildData.GeneralString(BuilderConstants.PropertyBaseClassOfINotifyPropertyChangedTest);
                testClassDeclaration.BaseTypes.Add(new CodeTypeReference(bd));
                //testClassDeclaration.BaseTypes.Add(new CodeTypeReference("CountingPropertyChangedEventFixture"));
            }

            // expand the test class namespace by ".Test"
            //this.testClassDeclaration.Name =
            //    this.namespaceDetector.InsertAfterShortestNamespace(this.testClassDeclaration, ".Tests");

            // Add "Test" to the test classes name.
            this.testClassDeclaration.Name = Utility.GetUnqualifiedTypeName(this.testClassDeclaration.Name) + "Test";


            var objectUnderTestName = Utility.GetUnqualifiedTypeName(baseObjectFullname);

            if (testObjectType.IsGenericType)
            {
                objectUnderTestName = objectUnderTestName + genericPart;
            }

            this.setUpTestnameCalled = true;
            return(objectUnderTestName);
        }