2 // Microsoft.VisualBasic.* Test Cases
5 // Gert Driesen (drieseng@users.sourceforge.net)
12 using System.CodeDom.Compiler;
13 using System.Globalization;
15 using Microsoft.VisualBasic;
17 using NUnit.Framework;
19 using MonoTests.System.CodeDom.Compiler;
21 namespace MonoTests.Microsoft.VisualBasic
24 public class CodeGeneratorFromTypeTest_Class : CodeGeneratorFromTypeTestBase
26 private CodeTypeDeclaration _typeDeclaration;
27 private ICodeGenerator _codeGenerator;
29 protected override ICodeGenerator CodeGenerator
31 get { return _codeGenerator; }
34 protected override CodeTypeDeclaration TypeDeclaration
36 get { return _typeDeclaration; }
40 public override void SetUp ()
43 _typeDeclaration = new CodeTypeDeclaration ();
45 CodeDomProvider provider = new VBCodeProvider ();
46 _codeGenerator = provider.CreateGenerator ();
50 public override void DefaultTypeTest ()
52 string code = GenerateDefaultType (Options);
53 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
55 "End Class{0}", NewLine), code);
59 [ExpectedException (typeof (NullReferenceException))]
60 public override void NullTypeTest ()
62 GenerateNullType (Options);
66 public override void SimpleTypeTest ()
68 string code = GenerateSimpleType (Options);
69 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
70 "Public Class Test1{0}" +
71 "End Class{0}", NewLine), code);
75 public override void DerivedTypeTest ()
77 string code = GenerateDerivedType (Options);
78 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
79 "Friend MustInherit Class Test1{0}" +
80 " Inherits Integer{0}" +
81 " Implements System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
82 "End Class{0}", NewLine), code);
86 public override void AttributesAndTypeTest ()
88 string code = GenerateAttributesAndType (Options);
89 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
92 "Public Class Test1{0}" +
93 "End Class{0}", NewLine), code);
97 public override void EventMembersTypeTest1 ()
99 string code = GenerateEventMembersType1 (Options);
100 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
101 "Public Class Test1{0}" +
105 " Private Event __exception As System.Void{0}" +
106 "End Class{0}", NewLine), code);
110 public override void EventMembersTypeTest2 ()
112 string code = GenerateEventMembersType2 (Options);
113 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
114 "Public Class Test1{0}" +
116 " Public Event Click As Integer{0}" +
117 "End Class{0}", NewLine), code);
121 public override void EventImplementationTypes ()
123 string code = GenerateEventImplementationTypes (Options);
124 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
125 "Public Class Test1{0}" +
127 " Friend Event Click As Integer Implements IPolicy.Click , IWhatever.Click{0}" +
128 "End Class{0}", NewLine), code);
132 /// Ensure no access modifiers are output if PrivateImplementationType
136 public override void EventPrivateImplementationType ()
138 string code = GenerateEventPrivateImplementationType (Options);
139 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
140 "Public Class Test1{0}" +
142 " Protected Event System_Int32_Click As Integer Implements Integer.Click{0}" +
143 "End Class{0}", NewLine), code);
147 /// If both ImplementationTypes and PrivateImplementationType are set,
148 /// then only ImplementationTypes are output.
151 public override void EventImplementationTypeOrder ()
153 string code = GenerateEventImplementationTypeOrder (Options);
154 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
155 "Public Class Test1{0}" +
157 " Public Event System_Int32_Click As Integer Implements IPolicy.Click{0}" +
158 "End Class{0}", NewLine), code);
162 public override void FieldMembersAttributesTest ()
164 string code = GenerateFieldMembersAttributes (Options);
165 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
166 "Public Class Test1{0}" +
170 " Private __exception As System.Void{0}" +
171 "End Class{0}", NewLine), code);
175 public override void FieldMembersTypeTest ()
177 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
178 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
179 "Public Class Test1{0}" +
181 " Public Name As Integer = 2{0}" +
182 "End Class{0}", NewLine), code);
186 public override void FieldNewSlotTest ()
188 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
189 MemberAttributes.New, Options);
190 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
191 "Public Class Test1{0}" +
193 " Friend Shadows Name As Integer = 2{0}" +
194 "End Class{0}", NewLine), code);
198 public void AbstractPropertyTest ()
200 string code = GenerateAbstractProperty (Options);
201 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
202 "Public MustInherit Class Test1{0}" +
204 " Public MustOverride Property Name() As String{0}" +
208 "End Class{0}", NewLine), code);
212 public void StaticPropertyTest ()
214 string code = GenerateStaticProperty (Options);
215 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
216 "Public Class Test1{0}" +
218 " Public Shared WriteOnly Property Name() As String{0}" +
222 "End Class{0}", NewLine), code);
226 public override void PropertyMembersTypeTest1 ()
228 string code = GeneratePropertyMembersAttributes (Options);
229 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
230 "Public Class Test1{0}" +
234 " Private Property () As System.Void{0}" +
236 "End Class{0}", NewLine), code);
240 public override void PropertyMembersTypeTest2 ()
242 string code = GeneratePropertyMembersType (MemberAttributes.Public,
243 false, false, Options);
244 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
245 "Public Class Test1{0}" +
247 " Public Overridable Property Name() As Integer{0}" +
249 "End Class{0}", NewLine), code);
253 public override void PropertyMembersTypeGetOnly ()
255 string code = GeneratePropertyMembersType (MemberAttributes.Family,
256 true, false, Options);
257 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
258 "Public Class Test1{0}" +
260 " Protected Overridable ReadOnly Property Name() As Integer{0}" +
264 "End Class{0}", NewLine), code);
268 public override void PropertyMembersTypeSetOnly ()
270 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
271 false, true, Options);
272 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
273 "Public Class Test1{0}" +
275 " Friend Overridable WriteOnly Property Name() As Integer{0}" +
279 "End Class{0}", NewLine), code);
283 public override void PropertyMembersTypeGetSet ()
285 string code = GeneratePropertyMembersType (MemberAttributes.Family,
286 true, true, Options);
287 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
288 "Public Class Test1{0}" +
290 " Protected Overridable Property Name() As Integer{0}" +
296 "End Class{0}", NewLine), code);
300 public override void PropertyMembersTypeFamilyOrAssembly ()
302 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
303 false, false, Options);
304 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
305 "Public Class Test1{0}" +
307 " Protected Friend Property Name() As Integer{0}" +
309 "End Class{0}", NewLine), code);
313 public override void PropertyMembersTypeAssembly ()
315 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
316 false, false, Options);
317 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
318 "Public Class Test1{0}" +
320 " Friend Overridable Property Name() As Integer{0}" +
322 "End Class{0}", NewLine), code);
326 /// Apparently VB.NET CodeDOM also allows properties that aren't indexers
327 /// to have parameters.
330 public override void PropertyParametersTest ()
332 string code = GeneratePropertyParameters (Options);
333 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
334 "Public Class Test1{0}" +
336 " Public Overridable Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
338 "End Class{0}", NewLine), code);
342 public override void PropertyIndexerTest1 ()
344 string code = GeneratePropertyIndexer (MemberAttributes.Public,
345 false, false, true, Options);
346 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
347 "Public Class Test1{0}" +
349 " Public Overridable Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
351 "End Class{0}", NewLine), code);
355 /// Ensures Default keyword is only output if property is named "Item"
356 /// (case-insensitive comparison) AND parameters are defined.
359 public override void PropertyIndexerTest2 ()
361 string code = GeneratePropertyIndexer (MemberAttributes.Public,
362 false, false, false, Options);
363 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
364 "Public Class Test1{0}" +
366 " Public Overridable Property iTem() As Integer{0}" +
368 "End Class{0}", NewLine), code);
372 /// Ensures Default keyword is output after ReadOnly modifier.
375 public override void PropertyIndexerGetOnly ()
377 string code = GeneratePropertyIndexer (MemberAttributes.Family,
378 true, false, true, Options);
379 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
380 "Public Class Test1{0}" +
382 " Protected Overridable Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
386 "End Class{0}", NewLine), code);
390 /// Ensures Default keyword is output after WriteOnly modifier.
393 public override void PropertyIndexerSetOnly ()
395 string code = GeneratePropertyIndexer (MemberAttributes.Family,
396 false, true, true, Options);
397 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
398 "Public Class Test1{0}" +
400 " Protected Overridable Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
404 "End Class{0}", NewLine), code);
408 public override void PropertyImplementationTypes ()
410 string code = GeneratePropertyImplementationTypes (Options);
411 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
412 "Public Class Test1{0}" +
414 " Public Overridable Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
416 "End Class{0}", NewLine), code);
420 /// Ensure that Overloads keyword is output for a property which has
421 /// explicitly been marked as Overloaded.
424 public override void PropertyOverloadsTest1 ()
426 string code = GeneratePropertyOverloads1 (Options);
427 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
428 "Public Class Test1{0}" +
430 " Protected Overloads Overridable Property Name() As Integer{0}" +
432 "End Class{0}", NewLine), code);
436 /// Ensure that Overloads keyword is output if multiple properties with
437 /// the same name are defined.
440 public override void PropertyOverloadsTest2 ()
442 string code = GeneratePropertyOverloads2 (Options);
443 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
444 "Public Class Test1{0}" +
446 " Public Overloads Overridable Property Name() As Integer{0}" +
449 " Private Overloads Property Name(ByVal value1 As Object) As Integer{0}" +
451 "End Class{0}", NewLine), code);
455 /// Ensure that a property with a PrivateImplementationType and with
456 /// the same name does not qualify as an overload.
459 public override void PropertyOverloadsTest3 ()
461 string code = GeneratePropertyOverloads3 (Options);
462 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
463 "Public Class Test1{0}" +
465 " Public Overridable Property Name() As Integer{0}" +
468 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
470 "End Class{0}", NewLine), code);
474 /// Ensure no access modifiers are output if PrivateImplementationType
475 /// is set. Default keyword is also not output in this case.
478 public override void PropertyPrivateImplementationType ()
480 string code = GeneratePropertyPrivateImplementationType (Options);
481 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
482 "Public Class Test1{0}" +
484 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
486 "End Class{0}", NewLine), code);
490 /// If both ImplementationTypes and PrivateImplementationType are set,
491 /// then only ImplementationTypes are output.
494 public override void PropertyImplementationTypeOrder ()
496 string code = GeneratePropertyImplementationTypeOrder (Options);
497 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
498 "Public Class Test1{0}" +
500 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
502 "End Class{0}", NewLine), code);
506 public override void PropertyNewSlotTest ()
508 string code = GeneratePropertyMembersType (MemberAttributes.Private |
509 MemberAttributes.New, true, true, Options);
510 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
511 "Public Class Test1{0}" +
513 " Private Shadows Property Name() As Integer{0}" +
519 "End Class{0}", NewLine), code);
523 public override void MethodMembersTypeTest1 ()
525 string code = GenerateMethodMembersType1 (Options);
526 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
527 "Public Class Test1{0}" +
531 " Private Sub (){0}" +
533 "End Class{0}", NewLine), code);
537 public override void MethodMembersTypeTest2 ()
539 string code = GenerateMethodMembersType2 (Options);
540 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
541 "Public Class Test1{0}" +
543 " Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
545 "End Class{0}", NewLine), code);
549 public override void MethodMembersTypeTest3 ()
551 string code = GenerateMethodMembersType3 (Options);
552 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
553 "Public Class Test1{0}" +
555 " Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
557 "End Class{0}", NewLine), code);
561 public override void MethodImplementationTypes ()
563 string code = GenerateMethodImplementationTypes (Options);
564 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
565 "Public Class Test1{0}" +
567 " Friend Overridable Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
569 "End Class{0}", NewLine), code);
573 /// Ensure that Overloads keyword is output for a method which has
574 /// explicitly been marked as Overloaded.
577 public override void MethodOverloadsTest1 ()
579 string code = GenerateMethodOverloads1 (Options);
580 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
581 "Public Class Test1{0}" +
583 " Friend Overloads Overridable Function Execute() As Integer{0}" +
585 "End Class{0}", NewLine), code);
589 /// Ensure that Overloads keyword is output if multiple methods with
590 /// the same name are defined.
593 public override void MethodOverloadsTest2 ()
595 string code = GenerateMethodOverloads2 (Options);
596 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
597 "Public Class Test1{0}" +
599 " Public Overloads Overridable Sub Execute(){0}" +
602 " Private Overloads Function Execute(ByVal value1 As Object) As Integer{0}" +
604 "End Class{0}", NewLine), code);
608 /// Ensure that a method with a PrivateImplementationType and with
609 /// the same name does not qualify as an overload.
612 public override void MethodOverloadsTest3 ()
614 string code = GenerateMethodOverloads3 (Options);
615 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
616 "Public Class Test1{0}" +
618 " Public Overridable Sub Execute(){0}" +
621 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
623 "End Class{0}", NewLine), code);
627 /// Ensure no access modifiers are output if PrivateImplementationType
631 public override void MethodPrivateImplementationType ()
633 string code = GenerateMethodPrivateImplementationType (Options);
634 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
635 "Public Class Test1{0}" +
637 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
639 "End Class{0}", NewLine), code);
643 /// If both ImplementationTypes and PrivateImplementationType are set,
644 /// then only ImplementationTypes are output.
647 public override void MethodImplementationTypeOrder ()
649 string code = GenerateMethodImplementationTypeOrder (Options);
650 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
651 "Public Class Test1{0}" +
653 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
655 "End Class{0}", NewLine), code);
659 public override void MethodParamArrayAttribute ()
661 string code = GenerateMethodParamArrayAttribute (Options);
662 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
663 "Public Class Test1{0}" +
665 " Public Overridable Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
667 "End Class{0}", NewLine), code);
671 public override void MethodReturnTypeAttributes ()
673 string code = GenerateMethodReturnTypeAttributes (Options);
674 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
675 "Public Class Test1{0}" +
679 " System.ParamArrayAttribute()> _{0}" +
680 " Public Overridable Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
682 "End Class{0}", NewLine), code);
686 public override void MethodNewSlotTest ()
688 string code = GenerateMethodNewSlot (Options);
689 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
690 "Public Class Test1{0}" +
692 " Public Shadows Overridable Function Execute() As Integer{0}" +
694 "End Class{0}", NewLine), code);
698 public override void ConstructorAttributesTest ()
700 // FIXME: updated to reflect mbas workaround
701 string code = GenerateConstructorAttributes (Options);
702 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
703 "Public Class Test1{0}" +
707 " Private Sub New(){0}" +
710 "End Class{0}", NewLine), code);
714 public override void ConstructorParametersTest ()
716 // FIXME: updated to reflect mbas workaround
717 string code = GenerateConstructorParameters (Options);
718 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
719 "Public Class Test1{0}" +
721 " Public Sub New(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer){0}" +
724 "End Class{0}", NewLine), code);
728 public override void ConstructorParameterAttributesTest ()
730 // FIXME: updated to reflect mbas workaround
731 string code = GenerateConstructorParameterAttributes (Options);
732 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
733 "Public Class Test1{0}" +
735 " Private Sub New(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer){0}" +
738 "End Class{0}", NewLine), code);
742 public override void BaseConstructorSingleArg ()
744 string code = GenerateBaseConstructor (false, Options);
745 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
746 "Public Class Test1{0}" +
748 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
749 " MyBase.New(value1){0}" +
751 "End Class{0}", NewLine), code);
755 public override void BaseConstructorMultipleArgs ()
757 string code = GenerateBaseConstructor (true, Options);
758 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
759 "Public Class Test1{0}" +
761 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
762 " MyBase.New(value1, value2){0}" +
764 "End Class{0}", NewLine), code);
768 public override void ChainedConstructorSingleArg ()
770 string code = GenerateChainedConstructor (false, Options);
771 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
772 "Public Class Test1{0}" +
774 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
775 " Me.New(value1){0}" +
777 "End Class{0}", NewLine), code);
781 public override void ChainedConstructorMultipleArgs ()
783 string code = GenerateChainedConstructor (true, Options);
784 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
785 "Public Class Test1{0}" +
787 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
788 " Me.New(value1, value2){0}" +
790 "End Class{0}", NewLine), code);
794 public override void TypeConstructorTest ()
796 string code = GenerateTypeConstructor (Options);
797 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
798 "Public Class Test1{0}" +
802 " Shared Sub New(){0}" +
804 "End Class{0}", NewLine), code);
808 public override void EntryPointMethodTest ()
810 string code = GenerateEntryPointMethod (Options);
811 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
812 "Public Class Test1{0}" +
815 " Public Shared Sub Main(){0}" +
816 " Dim x As Test.InnerType{0}" +
818 "End Class{0}", NewLine), code);
822 public override void PartialTypeTest ()
824 string code = GeneratePartialType (Options);
825 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
826 "Partial Public Class Test1{0}" +
827 "End Class{0}", NewLine), code);
832 public class CodeGeneratorFromTypeTest_Delegate : CodeGeneratorFromTypeTestBase
834 private CodeTypeDeclaration _typeDeclaration;
835 private ICodeGenerator _codeGenerator;
837 protected override ICodeGenerator CodeGenerator
839 get { return _codeGenerator; }
842 protected override CodeTypeDeclaration TypeDeclaration
844 get { return _typeDeclaration; }
848 public override void SetUp ()
851 _typeDeclaration = new CodeTypeDelegate ();
853 CodeDomProvider provider = new VBCodeProvider ();
854 _codeGenerator = provider.CreateGenerator ();
858 public override void DefaultTypeTest ()
860 string code = GenerateDefaultType (Options);
861 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
862 "Public Delegate Sub (){0}", NewLine), code);
866 [ExpectedException (typeof (NullReferenceException))]
867 public override void NullTypeTest ()
869 GenerateNullType (Options);
873 public override void SimpleTypeTest ()
875 string code = GenerateSimpleType (Options);
876 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
877 "Public Delegate Sub Test1(){0}", NewLine), code);
881 public override void DerivedTypeTest ()
883 string code = GenerateDerivedType (Options);
884 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
885 "Delegate Sub Test1(){0}", NewLine), code);
889 public override void AttributesAndTypeTest ()
891 CodeTypeDelegate delegateDecl = new CodeTypeDelegate ();
892 delegateDecl.ReturnType = new CodeTypeReference (typeof (int));
894 _typeDeclaration = delegateDecl;
896 string code = GenerateAttributesAndType (Options);
897 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
900 "Public Delegate Function Test1() As Integer{0}", NewLine), code);
904 public override void EventMembersTypeTest1 ()
906 string code = GenerateEventMembersType1 (Options);
907 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
908 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
912 public override void EventMembersTypeTest2 ()
914 string code = GenerateEventMembersType2 (Options);
915 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
916 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
920 public override void EventImplementationTypes ()
922 string code = GenerateEventImplementationTypes (Options);
923 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
924 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
928 /// Ensure no access modifiers are output if PrivateImplementationType
932 public override void EventPrivateImplementationType ()
934 string code = GenerateEventPrivateImplementationType (Options);
935 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
936 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
940 /// If both ImplementationTypes and PrivateImplementationType are set,
941 /// then only ImplementationTypes are output.
944 public override void EventImplementationTypeOrder ()
946 string code = GenerateEventImplementationTypeOrder (Options);
947 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
948 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
952 public override void FieldMembersAttributesTest ()
954 string code = GenerateFieldMembersAttributes (Options);
955 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
956 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
960 public override void FieldMembersTypeTest ()
962 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
963 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
964 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
968 public override void FieldNewSlotTest ()
970 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
971 MemberAttributes.New, Options);
972 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
973 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
977 public override void PropertyMembersTypeTest1 ()
979 string code = GeneratePropertyMembersAttributes (Options);
980 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
981 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
985 public override void PropertyMembersTypeTest2 ()
987 string code = GeneratePropertyMembersType (MemberAttributes.Public,
988 false, false, Options);
989 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
990 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
994 public override void PropertyMembersTypeGetOnly ()
996 string code = GeneratePropertyMembersType (MemberAttributes.Family,
997 true, false, Options);
998 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
999 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1003 public override void PropertyMembersTypeSetOnly ()
1005 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1006 false, true, Options);
1007 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1008 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1012 public override void PropertyMembersTypeGetSet ()
1014 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1015 true, true, Options);
1016 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1017 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1021 public override void PropertyMembersTypeFamilyOrAssembly ()
1023 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
1024 false, false, Options);
1025 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1026 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1030 public override void PropertyMembersTypeAssembly ()
1032 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1033 false, false, Options);
1034 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1035 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1039 public override void PropertyParametersTest ()
1041 string code = GeneratePropertyParameters (Options);
1042 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1043 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1047 public override void PropertyIndexerTest1 ()
1049 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1050 false, false, true, Options);
1051 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1052 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1056 public override void PropertyIndexerTest2 ()
1058 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1059 false, false, false, Options);
1060 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1061 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1065 public override void PropertyIndexerGetOnly ()
1067 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1068 true, false, true, Options);
1069 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1070 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1074 public override void PropertyIndexerSetOnly ()
1076 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1077 false, true, true, Options);
1078 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1079 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1083 public override void PropertyImplementationTypes ()
1085 string code = GeneratePropertyImplementationTypes (Options);
1086 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1087 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1091 public override void PropertyOverloadsTest1 ()
1093 string code = GeneratePropertyOverloads1 (Options);
1094 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1095 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1099 public override void PropertyOverloadsTest2 ()
1101 string code = GeneratePropertyOverloads2 (Options);
1102 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1103 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1107 public override void PropertyOverloadsTest3 ()
1109 string code = GeneratePropertyOverloads3 (Options);
1110 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1111 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1115 public override void PropertyPrivateImplementationType ()
1117 string code = GeneratePropertyPrivateImplementationType (Options);
1118 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1119 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1123 public override void PropertyImplementationTypeOrder ()
1125 string code = GeneratePropertyImplementationTypeOrder (Options);
1126 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1127 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1131 public override void PropertyNewSlotTest ()
1133 string code = GeneratePropertyMembersType (MemberAttributes.Private |
1134 MemberAttributes.New, true, true, Options);
1135 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1136 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1140 public override void MethodMembersTypeTest1 ()
1142 string code = GenerateMethodMembersType1 (Options);
1143 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1144 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1148 public override void MethodMembersTypeTest2 ()
1150 string code = GenerateMethodMembersType2 (Options);
1151 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1152 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1156 public override void MethodMembersTypeTest3 ()
1158 string code = GenerateMethodMembersType3 (Options);
1159 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1160 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1164 public override void MethodImplementationTypes ()
1166 string code = GenerateMethodImplementationTypes (Options);
1167 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1168 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1172 public override void MethodOverloadsTest1 ()
1174 string code = GenerateMethodOverloads1 (Options);
1175 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1176 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1180 public override void MethodOverloadsTest2 ()
1182 string code = GenerateMethodOverloads2 (Options);
1183 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1184 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1188 public override void MethodOverloadsTest3 ()
1190 string code = GenerateMethodOverloads3 (Options);
1191 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1192 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1196 public override void MethodPrivateImplementationType ()
1198 string code = GenerateMethodPrivateImplementationType (Options);
1199 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1200 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1204 public override void MethodImplementationTypeOrder ()
1206 string code = GenerateMethodImplementationTypeOrder (Options);
1207 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1208 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1212 public override void MethodParamArrayAttribute ()
1214 string code = GenerateMethodParamArrayAttribute (Options);
1215 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1216 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1220 public override void MethodReturnTypeAttributes ()
1222 string code = GenerateMethodReturnTypeAttributes (Options);
1223 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1224 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1228 public override void MethodNewSlotTest ()
1230 string code = GenerateMethodNewSlot (Options);
1231 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1232 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1236 public override void ConstructorAttributesTest ()
1238 string code = GenerateConstructorAttributes (Options);
1239 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1240 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1244 public override void ConstructorParametersTest ()
1246 string code = GenerateConstructorParameters (Options);
1247 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1248 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1252 public override void ConstructorParameterAttributesTest ()
1254 string code = GenerateConstructorParameterAttributes (Options);
1255 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1256 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1260 public override void BaseConstructorSingleArg ()
1262 string code = GenerateBaseConstructor (false, Options);
1263 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1264 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1268 public override void BaseConstructorMultipleArgs ()
1270 string code = GenerateBaseConstructor (true, Options);
1271 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1272 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1276 public override void ChainedConstructorSingleArg ()
1278 string code = GenerateChainedConstructor (false, Options);
1279 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1280 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1284 public override void ChainedConstructorMultipleArgs ()
1286 string code = GenerateChainedConstructor (true, Options);
1287 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1288 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1292 public override void TypeConstructorTest ()
1294 string code = GenerateTypeConstructor (Options);
1295 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1296 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1300 public override void EntryPointMethodTest ()
1302 string code = GenerateEntryPointMethod (Options);
1303 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1304 "Public Delegate Sub Test1(){0}{0}" +
1306 "Public Shared Sub Main(){0}" +
1307 " Dim x As Test.InnerType{0}" +
1308 "End Sub{0}", NewLine), code);
1312 public void DelegateWithParametersTest ()
1314 CodeTypeDelegate type = new CodeTypeDelegate("A");
1315 type.Parameters.Add (new CodeParameterDeclarationExpression ("type", "param"));
1317 string code = GenerateCodeFromType (type, Options);
1318 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1319 "Public Delegate Sub A(ByVal param As type){0}", NewLine), code);
1323 public override void PartialTypeTest ()
1325 string code = GeneratePartialType (Options);
1326 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1327 "Public Delegate Sub Test1(){0}", NewLine), code);
1332 public class CodeGeneratorFromTypeTest_Interface : CodeGeneratorFromTypeTestBase
1334 private CodeTypeDeclaration _typeDeclaration;
1335 private ICodeGenerator _codeGenerator;
1337 protected override ICodeGenerator CodeGenerator
1339 get { return _codeGenerator; }
1342 protected override CodeTypeDeclaration TypeDeclaration
1344 get { return _typeDeclaration; }
1348 public override void SetUp ()
1351 _typeDeclaration = new CodeTypeDeclaration ();
1352 _typeDeclaration.IsInterface = true;
1354 CodeDomProvider provider = new VBCodeProvider ();
1355 _codeGenerator = provider.CreateGenerator ();
1359 public override void DefaultTypeTest ()
1361 string code = GenerateDefaultType (Options);
1362 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1363 "Public Interface {0}" +
1364 "End Interface{0}", NewLine), code);
1368 [ExpectedException (typeof (NullReferenceException))]
1369 public override void NullTypeTest ()
1371 GenerateNullType (Options);
1375 public override void SimpleTypeTest ()
1377 string code = GenerateSimpleType (Options);
1378 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1379 "Public Interface Test1{0}" +
1380 "End Interface{0}", NewLine), code);
1384 public override void DerivedTypeTest ()
1386 string code = GenerateDerivedType (Options);
1387 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1388 "Friend Interface Test1{0}" +
1389 " Inherits Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
1390 "End Interface{0}", NewLine), code);
1394 public override void AttributesAndTypeTest ()
1396 string code = GenerateAttributesAndType (Options);
1397 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1400 "Public Interface Test1{0}" +
1401 "End Interface{0}", NewLine), code);
1405 public override void EventMembersTypeTest1 ()
1407 string code = GenerateEventMembersType1 (Options);
1408 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1409 "Public Interface Test1{0}" +
1413 " Private Event __exception As System.Void{0}" +
1414 "End Interface{0}", NewLine), code);
1418 public override void EventMembersTypeTest2 ()
1420 string code = GenerateEventMembersType2 (Options);
1421 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1422 "Public Interface Test1{0}" +
1424 " Public Event Click As Integer{0}" +
1425 "End Interface{0}", NewLine), code);
1429 public override void EventImplementationTypes ()
1431 string code = GenerateEventImplementationTypes (Options);
1432 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1433 "Public Interface Test1{0}" +
1435 " Friend Event Click As Integer Implements IPolicy.Click , IWhatever.Click{0}" +
1436 "End Interface{0}", NewLine), code);
1440 public override void EventPrivateImplementationType ()
1442 string code = GenerateEventPrivateImplementationType (Options);
1443 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1444 "Public Interface Test1{0}" +
1446 " Protected Event System_Int32_Click As Integer Implements Integer.Click{0}" +
1447 "End Interface{0}", NewLine), code);
1451 public override void EventImplementationTypeOrder ()
1453 string code = GenerateEventImplementationTypeOrder (Options);
1454 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1455 "Public Interface Test1{0}" +
1457 " Public Event System_Int32_Click As Integer Implements IPolicy.Click{0}" +
1458 "End Interface{0}", NewLine), code);
1462 public override void FieldMembersAttributesTest ()
1464 string code = GenerateFieldMembersAttributes (Options);
1465 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1466 "Public Interface Test1{0}" +
1468 "End Interface{0}", NewLine), code);
1472 public override void FieldMembersTypeTest ()
1474 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
1475 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1476 "Public Interface Test1{0}" +
1478 "End Interface{0}", NewLine), code);
1482 public override void FieldNewSlotTest ()
1484 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
1485 MemberAttributes.New, Options);
1486 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1487 "Public Interface Test1{0}" +
1489 "End Interface{0}", NewLine), code);
1493 public override void PropertyMembersTypeTest1 ()
1495 string code = GeneratePropertyMembersAttributes (Options);
1496 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1497 "Public Interface Test1{0}" +
1501 " Property () As System.Void{0}" +
1502 "End Interface{0}", NewLine), code);
1506 public override void PropertyMembersTypeTest2 ()
1508 string code = GeneratePropertyMembersType (MemberAttributes.Public,
1509 false, false, Options);
1510 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1511 "Public Interface Test1{0}" +
1513 " Property Name() As Integer{0}" +
1514 "End Interface{0}", NewLine), code);
1518 public override void PropertyMembersTypeGetOnly ()
1520 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1521 true, false, Options);
1522 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1523 "Public Interface Test1{0}" +
1525 " ReadOnly Property Name() As Integer{0}" +
1526 "End Interface{0}", NewLine), code);
1530 public override void PropertyMembersTypeSetOnly ()
1532 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1533 false, true, Options);
1534 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1535 "Public Interface Test1{0}" +
1537 " WriteOnly Property Name() As Integer{0}" +
1538 "End Interface{0}", NewLine), code);
1542 public override void PropertyMembersTypeGetSet ()
1544 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1545 true, true, Options);
1546 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1547 "Public Interface Test1{0}" +
1549 " Property Name() As Integer{0}" +
1550 "End Interface{0}", NewLine), code);
1554 public override void PropertyMembersTypeFamilyOrAssembly ()
1556 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
1557 false, false, Options);
1558 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1559 "Public Interface Test1{0}" +
1561 " Property Name() As Integer{0}" +
1562 "End Interface{0}", NewLine), code);
1566 public override void PropertyMembersTypeAssembly ()
1568 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1569 false, false, Options);
1570 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1571 "Public Interface Test1{0}" +
1573 " Property Name() As Integer{0}" +
1574 "End Interface{0}", NewLine), code);
1578 public override void PropertyParametersTest ()
1580 string code = GeneratePropertyParameters (Options);
1581 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1582 "Public Interface Test1{0}" +
1584 " Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1585 "End Interface{0}", NewLine), code);
1589 public override void PropertyIndexerTest1 ()
1591 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1592 false, false, true, Options);
1593 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1594 "Public Interface Test1{0}" +
1596 " Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1597 "End Interface{0}", NewLine), code);
1601 public override void PropertyIndexerTest2 ()
1603 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1604 false, false, false, Options);
1605 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1606 "Public Interface Test1{0}" +
1608 " Property iTem() As Integer{0}" +
1609 "End Interface{0}", NewLine), code);
1613 public override void PropertyIndexerGetOnly ()
1615 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1616 true, false, true, Options);
1617 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1618 "Public Interface Test1{0}" +
1620 " Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1621 "End Interface{0}", NewLine), code);
1625 public override void PropertyIndexerSetOnly ()
1627 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1628 false, true, true, Options);
1629 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1630 "Public Interface Test1{0}" +
1632 " Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1633 "End Interface{0}", NewLine), code);
1637 public override void PropertyImplementationTypes ()
1639 string code = GeneratePropertyImplementationTypes (Options);
1640 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1641 "Public Interface Test1{0}" +
1643 " Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
1644 "End Interface{0}", NewLine), code);
1648 public override void PropertyOverloadsTest1 ()
1650 string code = GeneratePropertyOverloads1 (Options);
1651 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1652 "Public Interface Test1{0}" +
1654 " Property Name() As Integer{0}" +
1655 "End Interface{0}", NewLine), code);
1659 public override void PropertyOverloadsTest2 ()
1661 string code = GeneratePropertyOverloads2 (Options);
1662 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1663 "Public Interface Test1{0}" +
1665 " Property Name() As Integer{0}" +
1667 " Property Name(ByVal value1 As Object) As Integer{0}" +
1668 "End Interface{0}", NewLine), code);
1672 public override void PropertyOverloadsTest3 ()
1674 string code = GeneratePropertyOverloads3 (Options);
1675 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1676 "Public Interface Test1{0}" +
1678 " Property Name() As Integer{0}" +
1680 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
1681 "End Interface{0}", NewLine), code);
1685 public override void PropertyPrivateImplementationType ()
1687 string code = GeneratePropertyPrivateImplementationType (Options);
1688 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1689 "Public Interface Test1{0}" +
1691 " Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
1692 "End Interface{0}", NewLine), code);
1696 public override void PropertyImplementationTypeOrder ()
1698 string code = GeneratePropertyImplementationTypeOrder (Options);
1699 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1700 "Public Interface Test1{0}" +
1702 " Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
1703 "End Interface{0}", NewLine), code);
1707 public override void PropertyNewSlotTest ()
1709 string code = GeneratePropertyMembersType (MemberAttributes.Private |
1710 MemberAttributes.New, true, true, Options);
1711 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1712 "Public Interface Test1{0}" +
1714 " Shadows Property Name() As Integer{0}" +
1715 "End Interface{0}", NewLine), code);
1719 public override void MethodMembersTypeTest1 ()
1721 string code = GenerateMethodMembersType1 (Options);
1722 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1723 "Public Interface Test1{0}" +
1728 "End Interface{0}", NewLine), code);
1732 public override void MethodMembersTypeTest2 ()
1734 string code = GenerateMethodMembersType2 (Options);
1735 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1736 "Public Interface Test1{0}" +
1738 " Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
1739 "End Interface{0}", NewLine), code);
1743 public override void MethodMembersTypeTest3 ()
1745 string code = GenerateMethodMembersType3 (Options);
1746 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1747 "Public Interface Test1{0}" +
1749 " Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
1750 "End Interface{0}", NewLine), code);
1754 public override void MethodImplementationTypes ()
1756 string code = GenerateMethodImplementationTypes (Options);
1757 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1758 "Public Interface Test1{0}" +
1760 " Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
1761 "End Interface{0}", NewLine), code);
1765 public override void MethodOverloadsTest1 ()
1767 string code = GenerateMethodOverloads1 (Options);
1768 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1769 "Public Interface Test1{0}" +
1771 " Function Execute() As Integer{0}" +
1772 "End Interface{0}", NewLine), code);
1776 public override void MethodOverloadsTest2 ()
1778 string code = GenerateMethodOverloads2 (Options);
1779 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1780 "Public Interface Test1{0}" +
1782 " Sub Execute(){0}" +
1784 " Function Execute(ByVal value1 As Object) As Integer{0}" +
1785 "End Interface{0}", NewLine), code);
1789 public override void MethodOverloadsTest3 ()
1791 string code = GenerateMethodOverloads3 (Options);
1792 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1793 "Public Interface Test1{0}" +
1795 " Sub Execute(){0}" +
1797 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
1798 "End Interface{0}", NewLine), code);
1802 public override void MethodPrivateImplementationType ()
1804 string code = GenerateMethodPrivateImplementationType (Options);
1805 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1806 "Public Interface Test1{0}" +
1808 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
1809 "End Interface{0}", NewLine), code);
1813 public override void MethodImplementationTypeOrder ()
1815 string code = GenerateMethodImplementationTypeOrder (Options);
1816 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1817 "Public Interface Test1{0}" +
1819 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
1820 "End Interface{0}", NewLine), code);
1824 public override void MethodParamArrayAttribute ()
1826 string code = GenerateMethodParamArrayAttribute (Options);
1827 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1828 "Public Interface Test1{0}" +
1830 " Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
1831 "End Interface{0}", NewLine), code);
1835 public override void MethodReturnTypeAttributes ()
1837 string code = GenerateMethodReturnTypeAttributes (Options);
1838 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1839 "Public Interface Test1{0}" +
1843 " System.ParamArrayAttribute()> _{0}" +
1844 " Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
1845 "End Interface{0}", NewLine), code);
1849 public override void MethodNewSlotTest ()
1851 string code = GenerateMethodNewSlot (Options);
1852 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1853 "Public Interface Test1{0}" +
1855 " Shadows Function Execute() As Integer{0}" +
1856 "End Interface{0}", NewLine), code);
1860 public override void ConstructorAttributesTest ()
1862 string code = GenerateConstructorAttributes (Options);
1863 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1864 "Public Interface Test1{0}" +
1866 "End Interface{0}", NewLine), code);
1870 public override void ConstructorParametersTest ()
1872 string code = GenerateConstructorParameters (Options);
1873 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1874 "Public Interface Test1{0}" +
1876 "End Interface{0}", NewLine), code);
1880 public override void ConstructorParameterAttributesTest ()
1882 string code = GenerateConstructorParameterAttributes (Options);
1883 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1884 "Public Interface Test1{0}" +
1886 "End Interface{0}", NewLine), code);
1890 public override void BaseConstructorSingleArg ()
1892 string code = GenerateBaseConstructor (false, Options);
1893 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1894 "Public Interface Test1{0}" +
1896 "End Interface{0}", NewLine), code);
1900 public override void BaseConstructorMultipleArgs ()
1902 string code = GenerateBaseConstructor (true, Options);
1903 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1904 "Public Interface Test1{0}" +
1906 "End Interface{0}", NewLine), code);
1910 public override void ChainedConstructorSingleArg ()
1912 string code = GenerateChainedConstructor (false, Options);
1913 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1914 "Public Interface Test1{0}" +
1916 "End Interface{0}", NewLine), code);
1920 public override void ChainedConstructorMultipleArgs ()
1922 string code = GenerateChainedConstructor (true, Options);
1923 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1924 "Public Interface Test1{0}" +
1926 "End Interface{0}", NewLine), code);
1930 public override void TypeConstructorTest ()
1932 string code = GenerateTypeConstructor (Options);
1933 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1934 "Public Interface Test1{0}" +
1936 "End Interface{0}", NewLine), code);
1940 public override void EntryPointMethodTest ()
1942 string code = GenerateEntryPointMethod (Options);
1943 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1944 "Public Interface Test1{0}" +
1947 " Public Shared Sub Main(){0}" +
1948 " Dim x As Test.InnerType{0}" +
1950 "End Interface{0}", NewLine), code);
1954 public override void PartialTypeTest ()
1956 string code = GeneratePartialType (Options);
1957 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1958 "Partial Public Interface Test1{0}" +
1959 "End Interface{0}", NewLine), code);
1964 public class CodeGeneratorFromTypeTest_Struct : CodeGeneratorFromTypeTestBase
1966 private CodeTypeDeclaration _typeDeclaration;
1967 private ICodeGenerator _codeGenerator;
1969 protected override ICodeGenerator CodeGenerator
1971 get { return _codeGenerator; }
1974 protected override CodeTypeDeclaration TypeDeclaration
1976 get { return _typeDeclaration; }
1980 public override void SetUp ()
1983 _typeDeclaration = new CodeTypeDeclaration ();
1984 _typeDeclaration.IsStruct = true;
1986 CodeDomProvider provider = new VBCodeProvider ();
1987 _codeGenerator = provider.CreateGenerator ();
1991 public override void DefaultTypeTest ()
1993 string code = GenerateDefaultType (Options);
1994 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1995 "Public Structure {0}" +
1996 "End Structure{0}", NewLine), code);
2000 [ExpectedException (typeof (NullReferenceException))]
2001 public override void NullTypeTest ()
2003 GenerateNullType (Options);
2007 public override void SimpleTypeTest ()
2009 string code = GenerateSimpleType (Options);
2010 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2011 "Public Structure Test1{0}" +
2012 "End Structure{0}", NewLine), code);
2016 public override void DerivedTypeTest ()
2018 string code = GenerateDerivedType (Options);
2019 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2020 "Friend Structure Test1{0}" +
2021 " Implements Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
2022 "End Structure{0}", NewLine), code);
2026 public override void AttributesAndTypeTest ()
2028 string code = GenerateAttributesAndType (Options);
2029 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2032 "Public Structure Test1{0}" +
2033 "End Structure{0}", NewLine), code);
2037 public override void EventMembersTypeTest1 ()
2039 string code = GenerateEventMembersType1 (Options);
2040 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2041 "Public Structure Test1{0}" +
2045 " Private Event __exception As System.Void{0}" +
2046 "End Structure{0}", NewLine), code);
2050 public override void EventMembersTypeTest2 ()
2052 string code = GenerateEventMembersType2 (Options);
2053 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2054 "Public Structure Test1{0}" +
2056 " Public Event Click As Integer{0}" +
2057 "End Structure{0}", NewLine), code);
2061 public override void EventImplementationTypes ()
2063 string code = GenerateEventImplementationTypes (Options);
2064 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2065 "Public Structure Test1{0}" +
2067 " Friend Event Click As Integer Implements IPolicy.Click , IWhatever.Click{0}" +
2068 "End Structure{0}", NewLine), code);
2072 public override void EventPrivateImplementationType ()
2074 string code = GenerateEventPrivateImplementationType (Options);
2075 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2076 "Public Structure Test1{0}" +
2078 " Protected Event System_Int32_Click As Integer Implements Integer.Click{0}" +
2079 "End Structure{0}", NewLine), code);
2083 public override void EventImplementationTypeOrder ()
2085 string code = GenerateEventImplementationTypeOrder (Options);
2086 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2087 "Public Structure Test1{0}" +
2089 " Public Event System_Int32_Click As Integer Implements IPolicy.Click{0}" +
2090 "End Structure{0}", NewLine), code);
2094 public override void FieldMembersAttributesTest ()
2096 string code = GenerateFieldMembersAttributes (Options);
2097 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2098 "Public Structure Test1{0}" +
2102 " Private __exception As System.Void{0}" +
2103 "End Structure{0}", NewLine), code);
2107 public override void FieldMembersTypeTest ()
2109 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
2110 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2111 "Public Structure Test1{0}" +
2113 " Public Name As Integer = 2{0}" +
2114 "End Structure{0}", NewLine), code);
2118 public override void FieldNewSlotTest ()
2120 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
2121 MemberAttributes.New, Options);
2122 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2123 "Public Structure Test1{0}" +
2125 " Friend Shadows Name As Integer = 2{0}" +
2126 "End Structure{0}", NewLine), code);
2130 public override void PropertyMembersTypeTest1 ()
2132 string code = GeneratePropertyMembersAttributes (Options);
2133 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2134 "Public Structure Test1{0}" +
2138 " Private Property () As System.Void{0}" +
2139 " End Property{0}" +
2140 "End Structure{0}", NewLine), code);
2144 public override void PropertyMembersTypeTest2 ()
2146 string code = GeneratePropertyMembersType (MemberAttributes.Public,
2147 false, false, Options);
2148 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2149 "Public Structure Test1{0}" +
2151 " Public Overridable Property Name() As Integer{0}" +
2152 " End Property{0}" +
2153 "End Structure{0}", NewLine), code);
2157 public override void PropertyMembersTypeGetOnly ()
2159 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2160 true, false, Options);
2161 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2162 "Public Structure Test1{0}" +
2164 " Protected Overridable ReadOnly Property Name() As Integer{0}" +
2167 " End Property{0}" +
2168 "End Structure{0}", NewLine), code);
2172 public override void PropertyMembersTypeSetOnly ()
2174 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2175 false, true, Options);
2176 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2177 "Public Structure Test1{0}" +
2179 " Friend Overridable WriteOnly Property Name() As Integer{0}" +
2182 " End Property{0}" +
2183 "End Structure{0}", NewLine), code);
2187 public override void PropertyMembersTypeGetSet ()
2189 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2190 true, true, Options);
2191 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2192 "Public Structure Test1{0}" +
2194 " Protected Overridable Property Name() As Integer{0}" +
2199 " End Property{0}" +
2200 "End Structure{0}", NewLine), code);
2204 public override void PropertyMembersTypeFamilyOrAssembly ()
2206 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
2207 false, false, Options);
2208 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2209 "Public Structure Test1{0}" +
2211 " Protected Friend Property Name() As Integer{0}" +
2212 " End Property{0}" +
2213 "End Structure{0}", NewLine), code);
2217 public override void PropertyMembersTypeAssembly ()
2219 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2220 false, false, Options);
2221 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2222 "Public Structure Test1{0}" +
2224 " Friend Overridable Property Name() As Integer{0}" +
2225 " End Property{0}" +
2226 "End Structure{0}", NewLine), code);
2230 public override void PropertyParametersTest ()
2232 string code = GeneratePropertyParameters (Options);
2233 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2234 "Public Structure Test1{0}" +
2236 " Public Overridable Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2237 " End Property{0}" +
2238 "End Structure{0}", NewLine), code);
2242 public override void PropertyIndexerTest1 ()
2244 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2245 false, false, true, Options);
2246 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2247 "Public Structure Test1{0}" +
2249 " Public Overridable Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2250 " End Property{0}" +
2251 "End Structure{0}", NewLine), code);
2255 public override void PropertyIndexerTest2 ()
2257 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2258 false, false, false, Options);
2259 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2260 "Public Structure Test1{0}" +
2262 " Public Overridable Property iTem() As Integer{0}" +
2263 " End Property{0}" +
2264 "End Structure{0}", NewLine), code);
2268 public override void PropertyIndexerGetOnly ()
2270 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2271 true, false, true, Options);
2272 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2273 "Public Structure Test1{0}" +
2275 " Protected Overridable Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2278 " End Property{0}" +
2279 "End Structure{0}", NewLine), code);
2283 public override void PropertyIndexerSetOnly ()
2285 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2286 false, true, true, Options);
2287 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2288 "Public Structure Test1{0}" +
2290 " Protected Overridable Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2293 " End Property{0}" +
2294 "End Structure{0}", NewLine), code);
2298 public override void PropertyImplementationTypes ()
2300 string code = GeneratePropertyImplementationTypes (Options);
2301 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2302 "Public Structure Test1{0}" +
2304 " Public Overridable Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
2305 " End Property{0}" +
2306 "End Structure{0}", NewLine), code);
2310 public override void PropertyOverloadsTest1 ()
2312 string code = GeneratePropertyOverloads1 (Options);
2313 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2314 "Public Structure Test1{0}" +
2316 " Protected Overloads Overridable Property Name() As Integer{0}" +
2317 " End Property{0}" +
2318 "End Structure{0}", NewLine), code);
2322 public override void PropertyOverloadsTest2 ()
2324 string code = GeneratePropertyOverloads2 (Options);
2325 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2326 "Public Structure Test1{0}" +
2328 " Public Overloads Overridable Property Name() As Integer{0}" +
2329 " End Property{0}" +
2331 " Private Overloads Property Name(ByVal value1 As Object) As Integer{0}" +
2332 " End Property{0}" +
2333 "End Structure{0}", NewLine), code);
2337 public override void PropertyOverloadsTest3 ()
2339 string code = GeneratePropertyOverloads3 (Options);
2340 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2341 "Public Structure Test1{0}" +
2343 " Public Overridable Property Name() As Integer{0}" +
2344 " End Property{0}" +
2346 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
2347 " End Property{0}" +
2348 "End Structure{0}", NewLine), code);
2352 public override void PropertyPrivateImplementationType ()
2354 string code = GeneratePropertyPrivateImplementationType (Options);
2355 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2356 "Public Structure Test1{0}" +
2358 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
2359 " End Property{0}" +
2360 "End Structure{0}", NewLine), code);
2364 public override void PropertyImplementationTypeOrder ()
2366 string code = GeneratePropertyImplementationTypeOrder (Options);
2367 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2368 "Public Structure Test1{0}" +
2370 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
2371 " End Property{0}" +
2372 "End Structure{0}", NewLine), code);
2376 public override void PropertyNewSlotTest ()
2378 string code = GeneratePropertyMembersType (MemberAttributes.Private |
2379 MemberAttributes.New, true, true, Options);
2380 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2381 "Public Structure Test1{0}" +
2383 " Private Shadows Property Name() As Integer{0}" +
2388 " End Property{0}" +
2389 "End Structure{0}", NewLine), code);
2393 public override void MethodMembersTypeTest1 ()
2395 string code = GenerateMethodMembersType1 (Options);
2396 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2397 "Public Structure Test1{0}" +
2401 " Private Sub (){0}" +
2403 "End Structure{0}", NewLine), code);
2407 public override void MethodMembersTypeTest2 ()
2409 string code = GenerateMethodMembersType2 (Options);
2410 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2411 "Public Structure Test1{0}" +
2413 " Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
2414 " End Function{0}" +
2415 "End Structure{0}", NewLine), code);
2419 public override void MethodMembersTypeTest3 ()
2421 string code = GenerateMethodMembersType3 (Options);
2422 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2423 "Public Structure Test1{0}" +
2425 " Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
2426 " End Function{0}" +
2427 "End Structure{0}", NewLine), code);
2431 public override void MethodImplementationTypes ()
2433 string code = GenerateMethodImplementationTypes (Options);
2434 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2435 "Public Structure Test1{0}" +
2437 " Friend Overridable Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
2438 " End Function{0}" +
2439 "End Structure{0}", NewLine), code);
2443 public override void MethodOverloadsTest1 ()
2445 string code = GenerateMethodOverloads1 (Options);
2446 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2447 "Public Structure Test1{0}" +
2449 " Friend Overloads Overridable Function Execute() As Integer{0}" +
2450 " End Function{0}" +
2451 "End Structure{0}", NewLine), code);
2455 public override void MethodOverloadsTest2 ()
2457 string code = GenerateMethodOverloads2 (Options);
2458 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2459 "Public Structure Test1{0}" +
2461 " Public Overloads Overridable Sub Execute(){0}" +
2464 " Private Overloads Function Execute(ByVal value1 As Object) As Integer{0}" +
2465 " End Function{0}" +
2466 "End Structure{0}", NewLine), code);
2470 public override void MethodOverloadsTest3 ()
2472 string code = GenerateMethodOverloads3 (Options);
2473 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2474 "Public Structure Test1{0}" +
2476 " Public Overridable Sub Execute(){0}" +
2479 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
2480 " End Function{0}" +
2481 "End Structure{0}", NewLine), code);
2485 public override void MethodPrivateImplementationType ()
2487 string code = GenerateMethodPrivateImplementationType (Options);
2488 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2489 "Public Structure Test1{0}" +
2491 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
2492 " End Function{0}" +
2493 "End Structure{0}", NewLine), code);
2497 public override void MethodImplementationTypeOrder ()
2499 string code = GenerateMethodImplementationTypeOrder (Options);
2500 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2501 "Public Structure Test1{0}" +
2503 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
2504 " End Function{0}" +
2505 "End Structure{0}", NewLine), code);
2509 public override void MethodParamArrayAttribute ()
2511 string code = GenerateMethodParamArrayAttribute (Options);
2512 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2513 "Public Structure Test1{0}" +
2515 " Public Overridable Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
2516 " End Function{0}" +
2517 "End Structure{0}", NewLine), code);
2521 public override void MethodReturnTypeAttributes ()
2523 string code = GenerateMethodReturnTypeAttributes (Options);
2524 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2525 "Public Structure Test1{0}" +
2529 " System.ParamArrayAttribute()> _{0}" +
2530 " Public Overridable Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
2531 " End Function{0}" +
2532 "End Structure{0}", NewLine), code);
2536 public override void MethodNewSlotTest ()
2538 string code = GenerateMethodNewSlot (Options);
2539 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2540 "Public Structure Test1{0}" +
2542 " Public Shadows Overridable Function Execute() As Integer{0}" +
2543 " End Function{0}" +
2544 "End Structure{0}", NewLine), code);
2548 public override void ConstructorAttributesTest ()
2550 // FIXME: updated to reflect mbas workaround
2551 string code = GenerateConstructorAttributes (Options);
2552 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2553 "Public Structure Test1{0}" +
2557 " Private Sub New(){0}" +
2559 "End Structure{0}", NewLine), code);
2563 public override void ConstructorParametersTest ()
2565 // FIXME: updated to reflect mbas workaround
2566 string code = GenerateConstructorParameters (Options);
2567 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2568 "Public Structure Test1{0}" +
2570 " Public Sub New(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer){0}" +
2572 "End Structure{0}", NewLine), code);
2576 public override void ConstructorParameterAttributesTest ()
2578 // FIXME: updated to reflect mbas workaround
2579 string code = GenerateConstructorParameterAttributes (Options);
2580 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2581 "Public Structure Test1{0}" +
2583 " Private Sub New(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer){0}" +
2585 "End Structure{0}", NewLine), code);
2589 public override void BaseConstructorSingleArg ()
2591 string code = GenerateBaseConstructor (false, Options);
2592 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2593 "Public Structure Test1{0}" +
2595 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2596 " MyBase.New(value1){0}" +
2598 "End Structure{0}", NewLine), code);
2602 public override void BaseConstructorMultipleArgs ()
2604 string code = GenerateBaseConstructor (true, Options);
2605 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2606 "Public Structure Test1{0}" +
2608 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2609 " MyBase.New(value1, value2){0}" +
2611 "End Structure{0}", NewLine), code);
2615 public override void ChainedConstructorSingleArg ()
2617 string code = GenerateChainedConstructor (false, Options);
2618 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2619 "Public Structure Test1{0}" +
2621 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2622 " Me.New(value1){0}" +
2624 "End Structure{0}", NewLine), code);
2628 public override void ChainedConstructorMultipleArgs ()
2630 string code = GenerateChainedConstructor (true, Options);
2631 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2632 "Public Structure Test1{0}" +
2634 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2635 " Me.New(value1, value2){0}" +
2637 "End Structure{0}", NewLine), code);
2641 public override void TypeConstructorTest ()
2643 string code = GenerateTypeConstructor (Options);
2644 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2645 "Public Structure Test1{0}" +
2649 " Shared Sub New(){0}" +
2651 "End Structure{0}", NewLine), code);
2655 public override void EntryPointMethodTest ()
2657 string code = GenerateEntryPointMethod (Options);
2658 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2659 "Public Structure Test1{0}" +
2662 " Public Shared Sub Main(){0}" +
2663 " Dim x As Test.InnerType{0}" +
2665 "End Structure{0}", NewLine), code);
2669 public override void PartialTypeTest ()
2671 string code = GeneratePartialType (Options);
2672 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2673 "Partial Public Structure Test1{0}" +
2674 "End Structure{0}", NewLine), code);
2679 public class CodeGeneratorFromTypeTest_Enum : CodeGeneratorFromTypeTestBase
2681 private CodeTypeDeclaration _typeDeclaration;
2682 private ICodeGenerator _codeGenerator;
2684 protected override ICodeGenerator CodeGenerator
2686 get { return _codeGenerator; }
2689 protected override CodeTypeDeclaration TypeDeclaration
2691 get { return _typeDeclaration; }
2695 public override void SetUp ()
2698 _typeDeclaration = new CodeTypeDeclaration ();
2699 _typeDeclaration.IsEnum = true;
2701 CodeDomProvider provider = new VBCodeProvider ();
2702 _codeGenerator = provider.CreateGenerator ();
2706 public override void DefaultTypeTest ()
2708 string code = GenerateDefaultType (Options);
2709 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2711 "End Enum{0}", NewLine), code);
2715 [ExpectedException (typeof (NullReferenceException))]
2716 public override void NullTypeTest ()
2718 GenerateNullType (Options);
2722 public override void SimpleTypeTest ()
2724 string code = GenerateSimpleType (Options);
2725 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2726 "Public Enum Test1{0}" +
2727 "End Enum{0}", NewLine), code);
2731 public override void DerivedTypeTest ()
2733 string code = GenerateDerivedType (Options);
2734 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2735 "Friend Enum Test1 As Integer{0}" +
2736 "End Enum{0}", NewLine), code);
2740 public override void AttributesAndTypeTest ()
2742 string code = GenerateAttributesAndType (Options);
2743 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2746 "Public Enum Test1{0}" +
2747 "End Enum{0}", NewLine), code);
2751 public override void EventMembersTypeTest1 ()
2753 string code = GenerateEventMembersType1 (Options);
2754 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2755 "Public Enum Test1{0}" +
2757 "End Enum{0}", NewLine), code);
2761 public override void EventMembersTypeTest2 ()
2763 string code = GenerateEventMembersType2 (Options);
2764 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2765 "Public Enum Test1{0}" +
2767 "End Enum{0}", NewLine), code);
2771 public override void EventImplementationTypes ()
2773 string code = GenerateEventImplementationTypes (Options);
2774 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2775 "Public Enum Test1{0}" +
2777 "End Enum{0}", NewLine), code);
2781 public override void EventPrivateImplementationType ()
2783 string code = GenerateEventPrivateImplementationType (Options);
2784 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2785 "Public Enum Test1{0}" +
2787 "End Enum{0}", NewLine), code);
2791 public override void EventImplementationTypeOrder ()
2793 string code = GenerateEventImplementationTypeOrder (Options);
2794 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2795 "Public Enum Test1{0}" +
2797 "End Enum{0}", NewLine), code);
2801 public override void FieldMembersAttributesTest ()
2803 string code = GenerateFieldMembersAttributes (Options);
2804 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2805 "Public Enum Test1{0}" +
2810 "End Enum{0}", NewLine), code);
2814 public override void FieldMembersTypeTest ()
2816 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
2817 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2818 "Public Enum Test1{0}" +
2821 "End Enum{0}", NewLine), code);
2825 public override void FieldNewSlotTest ()
2827 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
2828 MemberAttributes.New, Options);
2829 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2830 "Public Enum Test1{0}" +
2833 "End Enum{0}", NewLine), code);
2837 public override void PropertyMembersTypeTest1 ()
2839 string code = GeneratePropertyMembersAttributes (Options);
2840 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2841 "Public Enum Test1{0}" +
2843 "End Enum{0}", NewLine), code);
2847 public override void PropertyMembersTypeTest2 ()
2849 string code = GeneratePropertyMembersType (MemberAttributes.Public,
2850 false, false, Options);
2851 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2852 "Public Enum Test1{0}" +
2854 "End Enum{0}", NewLine), code);
2858 public override void PropertyMembersTypeGetOnly ()
2860 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2861 true, false, Options);
2862 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2863 "Public Enum Test1{0}" +
2865 "End Enum{0}", NewLine), code);
2869 public override void PropertyMembersTypeSetOnly ()
2871 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2872 false, true, Options);
2873 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2874 "Public Enum Test1{0}" +
2876 "End Enum{0}", NewLine), code);
2880 public override void PropertyMembersTypeGetSet ()
2882 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2883 true, true, Options);
2884 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2885 "Public Enum Test1{0}" +
2887 "End Enum{0}", NewLine), code);
2891 public override void PropertyMembersTypeFamilyOrAssembly ()
2893 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
2894 false, false, Options);
2895 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2896 "Public Enum Test1{0}" +
2898 "End Enum{0}", NewLine), code);
2902 public override void PropertyMembersTypeAssembly ()
2904 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2905 false, false, Options);
2906 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2907 "Public Enum Test1{0}" +
2909 "End Enum{0}", NewLine), code);
2913 public override void PropertyParametersTest ()
2915 string code = GeneratePropertyParameters (Options);
2916 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2917 "Public Enum Test1{0}" +
2919 "End Enum{0}", NewLine), code);
2923 public override void PropertyIndexerTest1 ()
2925 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2926 false, false, true, Options);
2927 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2928 "Public Enum Test1{0}" +
2930 "End Enum{0}", NewLine), code);
2934 public override void PropertyIndexerTest2 ()
2936 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2937 false, false, false, Options);
2938 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2939 "Public Enum Test1{0}" +
2941 "End Enum{0}", NewLine), code);
2945 public override void PropertyIndexerGetOnly ()
2947 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2948 true, false, true, Options);
2949 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2950 "Public Enum Test1{0}" +
2952 "End Enum{0}", NewLine), code);
2956 public override void PropertyIndexerSetOnly ()
2958 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2959 false, true, true, Options);
2960 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2961 "Public Enum Test1{0}" +
2963 "End Enum{0}", NewLine), code);
2967 public override void PropertyImplementationTypes ()
2969 string code = GeneratePropertyImplementationTypes (Options);
2970 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2971 "Public Enum Test1{0}" +
2973 "End Enum{0}", NewLine), code);
2977 public override void PropertyOverloadsTest1 ()
2979 string code = GeneratePropertyOverloads1 (Options);
2980 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2981 "Public Enum Test1{0}" +
2983 "End Enum{0}", NewLine), code);
2987 public override void PropertyOverloadsTest2 ()
2989 string code = GeneratePropertyOverloads2 (Options);
2990 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2991 "Public Enum Test1{0}" +
2994 "End Enum{0}", NewLine), code);
2998 public override void PropertyOverloadsTest3 ()
3000 string code = GeneratePropertyOverloads3 (Options);
3001 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3002 "Public Enum Test1{0}" +
3005 "End Enum{0}", NewLine), code);
3009 public override void PropertyPrivateImplementationType ()
3011 string code = GeneratePropertyPrivateImplementationType (Options);
3012 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3013 "Public Enum Test1{0}" +
3015 "End Enum{0}", NewLine), code);
3019 public override void PropertyImplementationTypeOrder ()
3021 string code = GeneratePropertyImplementationTypeOrder (Options);
3022 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3023 "Public Enum Test1{0}" +
3025 "End Enum{0}", NewLine), code);
3029 public override void PropertyNewSlotTest ()
3031 string code = GeneratePropertyMembersType (MemberAttributes.Private |
3032 MemberAttributes.New, true, true, Options);
3033 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3034 "Public Enum Test1{0}" +
3036 "End Enum{0}", NewLine), code);
3040 public override void MethodMembersTypeTest1 ()
3042 string code = GenerateMethodMembersType1 (Options);
3043 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3044 "Public Enum Test1{0}" +
3046 "End Enum{0}", NewLine), code);
3050 public override void MethodMembersTypeTest2 ()
3052 string code = GenerateMethodMembersType2 (Options);
3053 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3054 "Public Enum Test1{0}" +
3056 "End Enum{0}", NewLine), code);
3060 public override void MethodMembersTypeTest3 ()
3062 string code = GenerateMethodMembersType3 (Options);
3063 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3064 "Public Enum Test1{0}" +
3066 "End Enum{0}", NewLine), code);
3070 public override void MethodImplementationTypes ()
3072 string code = GenerateMethodImplementationTypes (Options);
3073 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3074 "Public Enum Test1{0}" +
3076 "End Enum{0}", NewLine), code);
3080 public override void MethodOverloadsTest1 ()
3082 string code = GenerateMethodOverloads1 (Options);
3083 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3084 "Public Enum Test1{0}" +
3086 "End Enum{0}", NewLine), code);
3090 public override void MethodOverloadsTest2 ()
3092 string code = GenerateMethodOverloads2 (Options);
3093 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3094 "Public Enum Test1{0}" +
3097 "End Enum{0}", NewLine), code);
3101 public override void MethodOverloadsTest3 ()
3103 string code = GenerateMethodOverloads3 (Options);
3104 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3105 "Public Enum Test1{0}" +
3108 "End Enum{0}", NewLine), code);
3112 public override void MethodPrivateImplementationType ()
3114 string code = GenerateMethodPrivateImplementationType (Options);
3115 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3116 "Public Enum Test1{0}" +
3118 "End Enum{0}", NewLine), code);
3122 public override void MethodImplementationTypeOrder ()
3124 string code = GenerateMethodImplementationTypeOrder (Options);
3125 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3126 "Public Enum Test1{0}" +
3128 "End Enum{0}", NewLine), code);
3132 public override void MethodParamArrayAttribute ()
3134 string code = GenerateMethodParamArrayAttribute (Options);
3135 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3136 "Public Enum Test1{0}" +
3138 "End Enum{0}", NewLine), code);
3142 public override void MethodReturnTypeAttributes ()
3144 string code = GenerateMethodReturnTypeAttributes (Options);
3145 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3146 "Public Enum Test1{0}" +
3148 "End Enum{0}", NewLine), code);
3152 public override void MethodNewSlotTest ()
3154 string code = GenerateMethodNewSlot (Options);
3155 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3156 "Public Enum Test1{0}" +
3158 "End Enum{0}", NewLine), code);
3162 public override void ConstructorAttributesTest ()
3164 string code = GenerateConstructorAttributes (Options);
3165 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3166 "Public Enum Test1{0}" +
3168 "End Enum{0}", NewLine), code);
3172 public override void ConstructorParametersTest ()
3174 string code = GenerateConstructorParameters (Options);
3175 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3176 "Public Enum Test1{0}" +
3178 "End Enum{0}", NewLine), code);
3182 public override void ConstructorParameterAttributesTest ()
3184 string code = GenerateConstructorParameterAttributes (Options);
3185 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3186 "Public Enum Test1{0}" +
3188 "End Enum{0}", NewLine), code);
3192 public override void BaseConstructorSingleArg ()
3194 string code = GenerateBaseConstructor (false, Options);
3195 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3196 "Public Enum Test1{0}" +
3198 "End Enum{0}", NewLine), code);
3202 public override void BaseConstructorMultipleArgs ()
3204 string code = GenerateBaseConstructor (true, Options);
3205 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3206 "Public Enum Test1{0}" +
3208 "End Enum{0}", NewLine), code);
3212 public override void ChainedConstructorSingleArg ()
3214 string code = GenerateChainedConstructor (false, Options);
3215 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3216 "Public Enum Test1{0}" +
3218 "End Enum{0}", NewLine), code);
3222 public override void ChainedConstructorMultipleArgs ()
3224 string code = GenerateChainedConstructor (true, Options);
3225 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3226 "Public Enum Test1{0}" +
3228 "End Enum{0}", NewLine), code);
3232 public override void TypeConstructorTest ()
3234 string code = GenerateTypeConstructor (Options);
3235 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3236 "Public Enum Test1{0}" +
3238 "End Enum{0}", NewLine), code);
3242 public override void EntryPointMethodTest ()
3244 string code = GenerateEntryPointMethod (Options);
3245 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3246 "Public Enum Test1{0}" +
3249 " Public Shared Sub Main(){0}" +
3250 " Dim x As Test.InnerType{0}" +
3252 "End Enum{0}", NewLine), code);
3256 public override void PartialTypeTest ()
3258 string code = GeneratePartialType (Options);
3259 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3260 "Partial Public Enum Test1{0}" +
3261 "End Enum{0}", NewLine), code);