// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net) // All rights reserved. // // This file is part of Regionerate. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . using NUnit.Framework; using Rauchy.Regionerate.Domain.Components.Construction; using Rauchy.Regionerate.Domain.Components.Tests.Properties; using Rauchy.Regionerate.Domain.Entities; namespace Rauchy.Regionerate.Domain.Components.Tests { /// /// Contains cross-unit integration tests. /// [ TestFixture ] public class IntegrationTests { #region Tests (4)  // [rgn] Public Methods (4) /// /// Constructs a object which contains Generics code segments and verifies their content. /// [ Test ] [ Category( "Integration" ) ] public void ConstructClassWithLotsOfGenerics() { ConstructionCoordinator coordinator = new ConstructionCoordinator( ConstructionContext.Document ); string input = Resources.ClassWithLotsOfGenerics; Code[] codes = coordinator.Construct( input ); Assert.AreEqual( 1, codes.Length ); Assert.IsInstanceOfType( typeof ( Class ), codes[ 0 ] ); Class classWithLotsOfGenerics = ( Class )codes[ 0 ]; Assert.AreEqual( ClassInheritanceModifier.None, classWithLotsOfGenerics.InheritanceModifier ); Assert.AreEqual( TypeVisibility.Public, classWithLotsOfGenerics.TypeVisibility ); Assert.AreEqual( "ClassWithLotsOfGenerics where X : Code", classWithLotsOfGenerics.Name ); Assert.AreEqual( 3, classWithLotsOfGenerics.Members.Count ); Assert.IsInstanceOfType( typeof ( Method ), classWithLotsOfGenerics.Members[ 0 ] ); Method method = ( Method )classWithLotsOfGenerics.Members[ 0 ]; Assert.AreEqual( Access.Public, method.Access ); Assert.AreEqual( "Y", method.Type ); Assert.AreEqual( "Method", method.Name ); Assert.AreEqual( 1, method.ParametersCount ); Assert.IsInstanceOfType( typeof ( Field ), classWithLotsOfGenerics.Members[ 1 ] ); Field field = ( Field )classWithLotsOfGenerics.Members[ 1 ]; Assert.AreEqual( Access.Private, field.Access ); Assert.AreEqual( "X", field.Type ); Assert.AreEqual( "_field", field.Name ); Assert.IsInstanceOfType( typeof ( Property ), classWithLotsOfGenerics.Members[ 2 ] ); Property property = ( Property )classWithLotsOfGenerics.Members[ 2 ]; Assert.AreEqual( Access.Public, property.Access ); Assert.AreEqual( "X", property.Type ); Assert.AreEqual( "this", property.Name ); Assert.AreEqual( PropertyAccessor.GetAndSet, property.Accessor ); } /// /// Constructs a object and its inner members and verifies their content. /// [ Test ] [ Category( "Integration" ) ] public void ConstructClassWithMembers() { ConstructionCoordinator coordinator = new ConstructionCoordinator( ConstructionContext.Document ); string input = Resources.ClassWithMembers; Code[] codes = coordinator.Construct( input ); Assert.AreEqual( 1, codes.Length ); Assert.IsInstanceOfType( typeof ( Class ), codes[ 0 ] ); Class myClass = ( Class )codes[ 0 ]; Assert.AreEqual( ClassInheritanceModifier.Sealed, myClass.InheritanceModifier ); Assert.AreEqual( "MyClass", myClass.Name ); //Assert.AreEqual("TODO", myClass.ToString()); Assert.AreEqual( TypeVisibility.Public, myClass.TypeVisibility ); Assert.AreEqual( 6, myClass.Members.Count ); Assert.IsInstanceOfType( typeof ( Field ), myClass.Members[ 0 ] ); Field myField = ( Field )myClass.Members[ 0 ]; Assert.AreEqual( "_myField", myField.Name ); Assert.AreEqual( "string", myField.Type ); Assert.AreEqual( Access.Private, myField.Access ); Assert.IsFalse( myField.Const ); Assert.IsFalse( myField.Static ); Assert.AreEqual( "private string _myField;", myField.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Property ), myClass.Members[ 1 ] ); Property myProperty = ( Property )myClass.Members[ 1 ]; Assert.AreEqual( "MyProperty", myProperty.Name ); Assert.AreEqual( "string", myProperty.Type ); Assert.AreEqual( Access.Public, myProperty.Access ); Assert.AreEqual( PropertyAccessor.GetAndSet, myProperty.Accessor ); Assert.AreEqual( LogicInheritanceModifier.None, myProperty.InheritanceModifier ); Assert.IsFalse( myProperty.Static ); Assert.AreEqual( "public string MyProperty\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\treturn _myField;\r\n\t\t}\r\n\t\tset\r\n\t\t{\r\n\t\t\t_myField = value;\r\n\t\t}\r\n\t}", myProperty.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( EnumCode ), myClass.Members[ 2 ] ); EnumCode myEnum = ( EnumCode )myClass.Members[ 2 ]; Assert.AreEqual( "MyEnum", myEnum.Name ); Assert.IsEmpty( myEnum.IntegralType ); Assert.AreEqual( TypeVisibility.Public, myEnum.TypeVisibility ); Assert.AreEqual( 3, myEnum.ValuesCount ); Assert.AreEqual( "public enum MyEnum\r\n\t{\r\n\t\tvalue1, value2, value3\r\n\t};", myEnum.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Property ), myClass.Members[ 3 ] ); Property myOtherProperty = ( Property )myClass.Members[ 3 ]; Assert.AreEqual( "MyOtherProperty", myOtherProperty.Name ); Assert.AreEqual( "string", myOtherProperty.Type ); Assert.AreEqual( Access.Public, myOtherProperty.Access ); Assert.AreEqual( PropertyAccessor.Get, myOtherProperty.Accessor ); Assert.AreEqual( LogicInheritanceModifier.None, myOtherProperty.InheritanceModifier ); Assert.IsFalse( myOtherProperty.Static ); Assert.AreEqual( "[ MyAttribute() ]\r\n\tpublic string MyOtherProperty\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tthrow new NotImplementedException();\r\n\t\t}\r\n\t}", myOtherProperty.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Method ), myClass.Members[ 4 ] ); Method myMethod = ( Method )myClass.Members[ 4 ]; Assert.AreEqual( "MyMethod", myMethod.Name ); Assert.AreEqual( "void", myMethod.Type ); Assert.AreEqual( Access.Protected, myMethod.Access ); Assert.AreEqual( 2, myMethod.ParametersCount ); Assert.AreEqual( LogicInheritanceModifier.None, myMethod.InheritanceModifier ); Assert.IsFalse( myMethod.Static ); Assert.AreEqual( "/// \r\n\t/// Does somethings...\r\n\t/// \r\n\tprotected void MyMethod( int i, int j )\r\n\t{\r\n\t\tthrow new NotImplementedException();\r\n\t}", myMethod.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( UnrecognizedCode ), myClass.Members[ 5 ] ); UnrecognizedCode myUnrecognizedCode = ( UnrecognizedCode )myClass.Members[ 5 ]; Assert.AreEqual( "some unrecognized code", myUnrecognizedCode.ToString() ); } /// /// Constructs a object which contains unrecognize code segments and verifies their content. /// [ Test ] [ Category( "Integration" ) ] public void ConstructClassWithUnrecognizedCode() { ConstructionCoordinator coordinator = new ConstructionCoordinator( ConstructionContext.Document ); string input = Resources.ClassWithUnrecognizedCode; Code[] codes = coordinator.Construct( input ); Assert.AreEqual( 1, codes.Length ); Assert.IsInstanceOfType( typeof ( Class ), codes[ 0 ] ); Class classWithUnrecognizedCode = ( Class )codes[ 0 ]; Assert.AreEqual( ClassInheritanceModifier.None, classWithUnrecognizedCode.InheritanceModifier ); Assert.AreEqual( TypeVisibility.Internal, classWithUnrecognizedCode.TypeVisibility ); Assert.AreEqual( "ClassWithUnrecognizedCode", classWithUnrecognizedCode.Name ); Assert.AreEqual( 5, classWithUnrecognizedCode.Members.Count ); Assert.IsInstanceOfType( typeof ( Field ), classWithUnrecognizedCode.Members[ 0 ] ); Field field = ( Field )classWithUnrecognizedCode.Members[ 0 ]; Assert.AreEqual( Access.Private, field.Access ); Assert.AreEqual( "string", field.Type ); Assert.IsInstanceOfType( typeof ( UnrecognizedCode ), classWithUnrecognizedCode.Members[ 1 ] ); UnrecognizedCode unrecognizedCode1 = ( UnrecognizedCode )classWithUnrecognizedCode.Members[ 1 ]; Assert.AreEqual( "SOME UNRECOGNIZED CODE", unrecognizedCode1.ToString().Trim() ); Assert.IsInstanceOfType( typeof ( Method ), classWithUnrecognizedCode.Members[ 2 ] ); Method method = ( Method )classWithUnrecognizedCode.Members[ 2 ]; Assert.AreEqual( Access.Internal, method.Access ); Assert.AreEqual( "void", method.Type ); Assert.AreEqual( "Method", method.Name ); Assert.IsInstanceOfType( typeof ( UnrecognizedCode ), classWithUnrecognizedCode.Members[ 3 ] ); UnrecognizedCode unrecognizedCode2 = ( UnrecognizedCode )classWithUnrecognizedCode.Members[ 3 ]; Assert.AreEqual( "MORE UNRECOGNIZED CODE", unrecognizedCode2.ToString().Trim() ); Assert.IsInstanceOfType( typeof ( UnrecognizedCode ), classWithUnrecognizedCode.Members[ 4 ] ); UnrecognizedCode unrecognizedCode3 = ( UnrecognizedCode )classWithUnrecognizedCode.Members[ 4 ]; Assert.AreEqual( "// LAST UNRECOGNIZED CODE", unrecognizedCode3.ToString().Trim() ); } /// /// Constructs a set of objects and verifies their content. /// [ Test ] [ Category( "Integration" ) ] public void ConstructSimpleTypeMembers() { ConstructionCoordinator coordinator = new ConstructionCoordinator( ConstructionContext.Type ); string input = Resources.SimpleTypeMembers; Code[] codes = coordinator.Construct( input ); Assert.AreEqual( 4, codes.Length ); Assert.IsInstanceOfType( typeof ( Field ), codes[ 0 ] ); Field myField = ( Field )codes[ 0 ]; Assert.AreEqual( "_myField", myField.Name ); Assert.AreEqual( "string", myField.Type ); Assert.AreEqual( Access.Private, myField.Access ); Assert.IsFalse( myField.Const ); Assert.IsFalse( myField.Static ); Assert.AreEqual( "private string _myField;", myField.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Property ), codes[ 1 ] ); Property myProperty = ( Property )codes[ 1 ]; Assert.AreEqual( "MyProperty", myProperty.Name ); Assert.AreEqual( "string", myProperty.Type ); Assert.AreEqual( Access.Public, myProperty.Access ); Assert.AreEqual( PropertyAccessor.GetAndSet, myProperty.Accessor ); Assert.AreEqual( LogicInheritanceModifier.None, myProperty.InheritanceModifier ); Assert.IsFalse( myProperty.Static ); Assert.AreEqual( "public string MyProperty\r\n{\r\n\tget\r\n\t{\r\n\t\treturn _myField;\r\n\t}\r\n\tset\r\n\t{\r\n\t\t_myField = value;\r\n\t}\r\n}", myProperty.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Property ), codes[ 2 ] ); Property myOtherProperty = ( Property )codes[ 2 ]; Assert.AreEqual( "MyOtherProperty", myOtherProperty.Name ); Assert.AreEqual( "string", myOtherProperty.Type ); Assert.AreEqual( Access.Public, myOtherProperty.Access ); Assert.AreEqual( PropertyAccessor.Get, myOtherProperty.Accessor ); Assert.AreEqual( LogicInheritanceModifier.None, myOtherProperty.InheritanceModifier ); Assert.IsFalse( myOtherProperty.Static ); Assert.AreEqual( "[ MyAttribute() ]\r\npublic string MyOtherProperty\r\n{\r\n\tget\r\n\t{\r\n\t\tthrow new NotImplementedException();\r\n\t}\r\n}", myOtherProperty.ToString().TrimStart() ); Assert.IsInstanceOfType( typeof ( Method ), codes[ 3 ] ); Method myMethod = ( Method )codes[ 3 ]; Assert.AreEqual( "MyMethod", myMethod.Name ); Assert.AreEqual( "void", myMethod.Type ); Assert.AreEqual( Access.Protected, myMethod.Access ); Assert.AreEqual( 2, myMethod.ParametersCount ); Assert.AreEqual( LogicInheritanceModifier.None, myMethod.InheritanceModifier ); Assert.IsFalse( myMethod.Static ); Assert.AreEqual( "/// \r\n/// Does somethings...\r\n/// \r\nprotected void MyMethod( int i, int j )\r\n{\r\n\tthrow new NotImplementedException();\r\n}", myMethod.ToString().TrimStart() ); } #endregion Tests  } }