PageRenderTime 37ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

http://github.com/icsharpcode/ILSpy
C# | 100 lines | 74 code | 9 blank | 17 comment | 4 complexity | ec83a4967407984725563724a166de8b MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
  2// 
  3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4// software and associated documentation files (the "Software"), to deal in the Software
  5// without restriction, including without limitation the rights to use, copy, modify, merge,
  6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7// to whom the Software is furnished to do so, subject to the following conditions:
  8// 
  9// The above copyright notice and this permission notice shall be included in all copies or
 10// substantial portions of the Software.
 11// 
 12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 17// DEALINGS IN THE SOFTWARE.
 18
 19using System;
 20using System.IO;
 21using System.Linq;
 22using ICSharpCode.NRefactory.Documentation;
 23using ICSharpCode.NRefactory.TypeSystem;
 24using ICSharpCode.NRefactory.TypeSystem.Implementation;
 25using ICSharpCode.NRefactory.TypeSystem.TestCase;
 26using ICSharpCode.NRefactory.Utils;
 27using NUnit.Framework;
 28
 29namespace ICSharpCode.NRefactory.CSharp.Parser
 30{
 31	[TestFixture]
 32	public class TypeSystemConvertVisitorTests : TypeSystemTests
 33	{
 34		[TestFixtureSetUp]
 35		public void FixtureSetUp()
 36		{
 37			compilation = ParseTestCase().CreateCompilation();
 38		}
 39		
 40		internal static IProjectContent ParseTestCase()
 41		{
 42			const string fileName = "TypeSystemTests.TestCase.cs";
 43			
 44			CSharpParser parser = new CSharpParser();
 45			SyntaxTree syntaxTree;
 46			using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
 47				syntaxTree = parser.Parse(s, fileName);
 48			}
 49			
 50			var unresolvedFile = syntaxTree.ToTypeSystem();
 51			return new CSharpProjectContent()
 52				.AddOrUpdateFiles(unresolvedFile)
 53				.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
 54				.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
 55		}
 56		
 57		[Test]
 58		public void ConvertStandaloneTypeReference()
 59		{
 60			var typeRef = new MemberType(new SimpleType("System"), "Array").ToTypeReference();
 61			Assert.AreEqual(compilation.FindType(KnownTypeCode.Array), typeRef.Resolve(compilation.TypeResolveContext));
 62		}
 63		
 64		[Test]
 65		public void PartialMethodWithImplementation()
 66		{
 67			var t = compilation.FindType(typeof(PartialClass));
 68			var methods = t.GetMethods(m => m.Name == "PartialMethodWithImplementation").ToList();
 69			Assert.AreEqual(2, methods.Count);
 70			var method1 = methods.Single(m => m.Parameters[0].Type.FullName == "System.Int32");
 71			var method2 = methods.Single(m => m.Parameters[0].Type.FullName == "System.String");
 72			Assert.AreEqual(2, method1.Parts.Count);
 73			Assert.AreEqual(2, method2.Parts.Count);
 74		}
 75		
 76		[Test]
 77		public void PartialMethodWithoutImplementation()
 78		{
 79			var t = compilation.FindType(typeof(PartialClass));
 80			var method = t.GetMethods(m => m.Name == "PartialMethodWithoutImplementation").Single();
 81			Assert.AreEqual(1, method.Parts.Count);
 82		}
 83	}
 84	
 85	[TestFixture]
 86	public class SerializedTypeSystemConvertVisitorTests : TypeSystemTests
 87	{
 88		[TestFixtureSetUp]
 89		public void FixtureSetUp()
 90		{
 91			FastSerializer serializer = new FastSerializer();
 92			using (MemoryStream ms = new MemoryStream()) {
 93				serializer.Serialize(ms, TypeSystemConvertVisitorTests.ParseTestCase());
 94				ms.Position = 0;
 95				var pc = (IProjectContent)serializer.Deserialize(ms);
 96				compilation = pc.CreateCompilation();
 97			}
 98		}
 99	}
100}