예제 #1
0
        public void ThrowsOnMultipleNamespaces()
        {
            string code = "Namespace MyNamespace1 { public class MyClass1 {} } Namespace MyNamespace2 { public class MyClass2 {} }";

            // Mock a IElementNameReader that will act as the namespace reader.
            IElementNameReader mockedNamespaceReader = CreateElementNameReaderMock(code, new string[] { "MyNamespace1", "MyNamespace2" });

            // Mock a IElementNameReader that will provide names for the TypeLocator.
            // We do not use the CreateElementNameReaderMock since no expectations are neccesary.
            IElementNameReader mockedElementNameReader = _mockRepository.CreateMock <IElementNameReader>();

            _mockRepository.ReplayAll();

            TypeLocator typeLocator = new TypeLocator(mockedNamespaceReader, new IElementNameReader[] { mockedElementNameReader });
            string      path        = WriteTemporaryFile(code);

            IList <string> typeNames = typeLocator.GetTypeNames(path);
        }
예제 #2
0
        public void DoesNotLocateTypesInEmptyFile()
        {
            string code = string.Empty;

            // Mock a IElementNameReader that will act as the namespace reader.
            IElementNameReader mockedNamespaceReader = CreateElementNameReaderMock(code, new string[] { string.Empty });

            // Mock a IElementNameReader that will provide names for the TypeLocator.
            // We do not use the CreateElementNameReaderMock since no expectations are neccesary.
            IElementNameReader mockedElementNameReader = _mockRepository.CreateMock <IElementNameReader>();

            TypeLocator typeLocator = new TypeLocator(mockedNamespaceReader, new IElementNameReader[] { mockedElementNameReader });

            string path = WriteTemporaryFile(code);

            IList <string> typeNames = typeLocator.GetTypeNames(path);

            Assert.AreEqual(0, typeNames.Count);
        }
예제 #3
0
        public void FindsSingleType()
        {
            string code = "Namespace MyNamespace { public class MyClass {} }";

            // Mock a IElementNameReader that will act as the namespace reader.
            IElementNameReader mockedNamespaceReader = CreateElementNameReaderMock(code, new string[] { "MyNamespace" });

            // Mock a IElementNameReader that will provide names for the TypeLocator.
            IElementNameReader mockedElementNameReader = CreateElementNameReaderMock(code, new string[] { "MyClass" });

            _mockRepository.ReplayAll();

            TypeLocator typeLocator = new TypeLocator(mockedNamespaceReader, new IElementNameReader[] { mockedElementNameReader });
            string      path        = WriteTemporaryFile(code);

            IList <string> typeNames = typeLocator.GetTypeNames(path);

            Assert.AreEqual(1, typeNames.Count);
            Assert.AreEqual("MyNamespace.MyClass", typeNames[0]);
        }