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}" +
205 "End Class{0}", NewLine), code);
209 public void StaticPropertyTest ()
211 string code = GenerateStaticProperty (Options);
212 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
213 "Public Class Test1{0}" +
215 " Public Shared WriteOnly Property Name() As String{0}" +
219 "End Class{0}", NewLine), code);
223 public override void PropertyMembersTypeTest1 ()
225 string code = GeneratePropertyMembersAttributes (Options);
226 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
227 "Public Class Test1{0}" +
231 " Private Property () As System.Void{0}" +
233 "End Class{0}", NewLine), code);
237 public override void PropertyMembersTypeTest2 ()
239 string code = GeneratePropertyMembersType (MemberAttributes.Public,
240 false, false, Options);
241 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
242 "Public Class Test1{0}" +
244 " Public Overridable Property Name() As Integer{0}" +
246 "End Class{0}", NewLine), code);
250 public override void PropertyMembersTypeGetOnly ()
252 string code = GeneratePropertyMembersType (MemberAttributes.Family,
253 true, false, Options);
254 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
255 "Public Class Test1{0}" +
257 " Protected Overridable ReadOnly Property Name() As Integer{0}" +
261 "End Class{0}", NewLine), code);
265 public override void PropertyMembersTypeSetOnly ()
267 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
268 false, true, Options);
269 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
270 "Public Class Test1{0}" +
272 " Friend Overridable WriteOnly Property Name() As Integer{0}" +
276 "End Class{0}", NewLine), code);
280 public override void PropertyMembersTypeGetSet ()
282 string code = GeneratePropertyMembersType (MemberAttributes.Family,
283 true, true, Options);
284 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
285 "Public Class Test1{0}" +
287 " Protected Overridable Property Name() As Integer{0}" +
293 "End Class{0}", NewLine), code);
297 public override void PropertyMembersTypeFamilyOrAssembly ()
299 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
300 false, false, Options);
301 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
302 "Public Class Test1{0}" +
304 " Protected Friend Property Name() As Integer{0}" +
306 "End Class{0}", NewLine), code);
310 public override void PropertyMembersTypeAssembly ()
312 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
313 false, false, Options);
314 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
315 "Public Class Test1{0}" +
317 " Friend Overridable Property Name() As Integer{0}" +
319 "End Class{0}", NewLine), code);
323 /// Apparently VB.NET CodeDOM also allows properties that aren't indexers
324 /// to have parameters.
327 public override void PropertyParametersTest ()
329 string code = GeneratePropertyParameters (Options);
330 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
331 "Public Class Test1{0}" +
333 " Public Overridable Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
335 "End Class{0}", NewLine), code);
339 public override void PropertyIndexerTest1 ()
341 string code = GeneratePropertyIndexer (MemberAttributes.Public,
342 false, false, true, Options);
343 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
344 "Public Class Test1{0}" +
346 " Public Overridable Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
348 "End Class{0}", NewLine), code);
352 /// Ensures Default keyword is only output if property is named "Item"
353 /// (case-insensitive comparison) AND parameters are defined.
356 public override void PropertyIndexerTest2 ()
358 string code = GeneratePropertyIndexer (MemberAttributes.Public,
359 false, false, false, Options);
360 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
361 "Public Class Test1{0}" +
363 " Public Overridable Property iTem() As Integer{0}" +
365 "End Class{0}", NewLine), code);
369 /// Ensures Default keyword is output after ReadOnly modifier.
372 public override void PropertyIndexerGetOnly ()
374 string code = GeneratePropertyIndexer (MemberAttributes.Family,
375 true, false, true, Options);
376 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
377 "Public Class Test1{0}" +
379 " Protected Overridable Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
383 "End Class{0}", NewLine), code);
387 /// Ensures Default keyword is output after WriteOnly modifier.
390 public override void PropertyIndexerSetOnly ()
392 string code = GeneratePropertyIndexer (MemberAttributes.Family,
393 false, true, true, Options);
394 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
395 "Public Class Test1{0}" +
397 " Protected Overridable Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
401 "End Class{0}", NewLine), code);
405 public override void PropertyImplementationTypes ()
407 string code = GeneratePropertyImplementationTypes (Options);
408 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
409 "Public Class Test1{0}" +
411 " Public Overridable Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
413 "End Class{0}", NewLine), code);
417 /// Ensure that Overloads keyword is output for a property which has
418 /// explicitly been marked as Overloaded.
421 public override void PropertyOverloadsTest1 ()
423 string code = GeneratePropertyOverloads1 (Options);
424 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
425 "Public Class Test1{0}" +
427 " Protected Overloads Overridable Property Name() As Integer{0}" +
429 "End Class{0}", NewLine), code);
433 /// Ensure that Overloads keyword is output if multiple properties with
434 /// the same name are defined.
437 public override void PropertyOverloadsTest2 ()
439 string code = GeneratePropertyOverloads2 (Options);
440 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
441 "Public Class Test1{0}" +
443 " Public Overloads Overridable Property Name() As Integer{0}" +
446 " Private Overloads Property Name(ByVal value1 As Object) As Integer{0}" +
448 "End Class{0}", NewLine), code);
452 /// Ensure that a property with a PrivateImplementationType and with
453 /// the same name does not qualify as an overload.
456 public override void PropertyOverloadsTest3 ()
458 string code = GeneratePropertyOverloads3 (Options);
459 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
460 "Public Class Test1{0}" +
462 " Public Overridable Property Name() As Integer{0}" +
465 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
467 "End Class{0}", NewLine), code);
471 /// Ensure no access modifiers are output if PrivateImplementationType
472 /// is set. Default keyword is also not output in this case.
475 public override void PropertyPrivateImplementationType ()
477 string code = GeneratePropertyPrivateImplementationType (Options);
478 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
479 "Public Class Test1{0}" +
481 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
483 "End Class{0}", NewLine), code);
487 /// If both ImplementationTypes and PrivateImplementationType are set,
488 /// then only ImplementationTypes are output.
491 public override void PropertyImplementationTypeOrder ()
493 string code = GeneratePropertyImplementationTypeOrder (Options);
494 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
495 "Public Class Test1{0}" +
497 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
499 "End Class{0}", NewLine), code);
503 public override void PropertyNewSlotTest ()
505 string code = GeneratePropertyMembersType (MemberAttributes.Private |
506 MemberAttributes.New, true, true, Options);
507 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
508 "Public Class Test1{0}" +
510 " Private Shadows Property Name() As Integer{0}" +
516 "End Class{0}", NewLine), code);
520 public override void MethodMembersTypeTest1 ()
522 string code = GenerateMethodMembersType1 (Options);
523 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
524 "Public Class Test1{0}" +
528 " Private Sub (){0}" +
530 "End Class{0}", NewLine), code);
534 public override void MethodMembersTypeTest2 ()
536 string code = GenerateMethodMembersType2 (Options);
537 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
538 "Public Class Test1{0}" +
540 " Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
542 "End Class{0}", NewLine), code);
546 public override void MethodMembersTypeTest3 ()
548 string code = GenerateMethodMembersType3 (Options);
549 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
550 "Public Class Test1{0}" +
552 " Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
554 "End Class{0}", NewLine), code);
558 public override void MethodImplementationTypes ()
560 string code = GenerateMethodImplementationTypes (Options);
561 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
562 "Public Class Test1{0}" +
564 " Friend Overridable Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
566 "End Class{0}", NewLine), code);
570 /// Ensure that Overloads keyword is output for a method which has
571 /// explicitly been marked as Overloaded.
574 public override void MethodOverloadsTest1 ()
576 string code = GenerateMethodOverloads1 (Options);
577 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
578 "Public Class Test1{0}" +
580 " Friend Overloads Overridable Function Execute() As Integer{0}" +
582 "End Class{0}", NewLine), code);
586 /// Ensure that Overloads keyword is output if multiple methods with
587 /// the same name are defined.
590 public override void MethodOverloadsTest2 ()
592 string code = GenerateMethodOverloads2 (Options);
593 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
594 "Public Class Test1{0}" +
596 " Public Overloads Overridable Sub Execute(){0}" +
599 " Private Overloads Function Execute(ByVal value1 As Object) As Integer{0}" +
601 "End Class{0}", NewLine), code);
605 /// Ensure that a method with a PrivateImplementationType and with
606 /// the same name does not qualify as an overload.
609 public override void MethodOverloadsTest3 ()
611 string code = GenerateMethodOverloads3 (Options);
612 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
613 "Public Class Test1{0}" +
615 " Public Overridable Sub Execute(){0}" +
618 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
620 "End Class{0}", NewLine), code);
624 /// Ensure no access modifiers are output if PrivateImplementationType
628 public override void MethodPrivateImplementationType ()
630 string code = GenerateMethodPrivateImplementationType (Options);
631 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
632 "Public Class Test1{0}" +
634 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
636 "End Class{0}", NewLine), code);
640 /// If both ImplementationTypes and PrivateImplementationType are set,
641 /// then only ImplementationTypes are output.
644 public override void MethodImplementationTypeOrder ()
646 string code = GenerateMethodImplementationTypeOrder (Options);
647 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
648 "Public Class Test1{0}" +
650 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
652 "End Class{0}", NewLine), code);
656 public override void MethodParamArrayAttribute ()
658 string code = GenerateMethodParamArrayAttribute (Options);
659 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
660 "Public Class Test1{0}" +
662 " Public Overridable Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
664 "End Class{0}", NewLine), code);
668 public override void MethodReturnTypeAttributes ()
670 string code = GenerateMethodReturnTypeAttributes (Options);
671 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
672 "Public Class Test1{0}" +
676 " System.ParamArrayAttribute()> _{0}" +
677 " Public Overridable Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
679 "End Class{0}", NewLine), code);
683 public override void MethodNewSlotTest ()
685 string code = GenerateMethodNewSlot (Options);
686 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
687 "Public Class Test1{0}" +
689 " Public Shadows Overridable Function Execute() As Integer{0}" +
691 "End Class{0}", NewLine), code);
695 public override void ConstructorAttributesTest ()
697 // FIXME: updated to reflect mbas workaround
698 string code = GenerateConstructorAttributes (Options);
699 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
700 "Public Class Test1{0}" +
704 " Private Sub New(){0}" +
707 "End Class{0}", NewLine), code);
711 public override void ConstructorParametersTest ()
713 // FIXME: updated to reflect mbas workaround
714 string code = GenerateConstructorParameters (Options);
715 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
716 "Public Class Test1{0}" +
718 " Public Sub New(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer){0}" +
721 "End Class{0}", NewLine), code);
725 public override void ConstructorParameterAttributesTest ()
727 // FIXME: updated to reflect mbas workaround
728 string code = GenerateConstructorParameterAttributes (Options);
729 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
730 "Public Class Test1{0}" +
732 " Private Sub New(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer){0}" +
735 "End Class{0}", NewLine), code);
739 public override void BaseConstructorSingleArg ()
741 string code = GenerateBaseConstructor (false, Options);
742 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
743 "Public Class Test1{0}" +
745 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
746 " MyBase.New(value1){0}" +
748 "End Class{0}", NewLine), code);
752 public override void BaseConstructorMultipleArgs ()
754 string code = GenerateBaseConstructor (true, Options);
755 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
756 "Public Class Test1{0}" +
758 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
759 " MyBase.New(value1, value2){0}" +
761 "End Class{0}", NewLine), code);
765 public override void ChainedConstructorSingleArg ()
767 string code = GenerateChainedConstructor (false, Options);
768 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
769 "Public Class Test1{0}" +
771 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
772 " Me.New(value1){0}" +
774 "End Class{0}", NewLine), code);
778 public override void ChainedConstructorMultipleArgs ()
780 string code = GenerateChainedConstructor (true, Options);
781 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
782 "Public Class Test1{0}" +
784 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
785 " Me.New(value1, value2){0}" +
787 "End Class{0}", NewLine), code);
791 public override void TypeConstructorTest ()
793 string code = GenerateTypeConstructor (Options);
794 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
795 "Public Class Test1{0}" +
799 " Shared Sub New(){0}" +
801 "End Class{0}", NewLine), code);
805 public override void EntryPointMethodTest ()
807 string code = GenerateEntryPointMethod (Options);
808 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
809 "Public Class Test1{0}" +
812 " Public Shared Sub Main(){0}" +
813 " Dim x As Test.InnerType{0}" +
815 "End Class{0}", NewLine), code);
819 public override void PartialTypeTest ()
821 string code = GeneratePartialType (Options);
822 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
823 "Partial Public Class Test1{0}" +
824 "End Class{0}", NewLine), code);
829 public class CodeGeneratorFromTypeTest_Delegate : CodeGeneratorFromTypeTestBase
831 private CodeTypeDeclaration _typeDeclaration;
832 private ICodeGenerator _codeGenerator;
834 protected override ICodeGenerator CodeGenerator
836 get { return _codeGenerator; }
839 protected override CodeTypeDeclaration TypeDeclaration
841 get { return _typeDeclaration; }
845 public override void SetUp ()
848 _typeDeclaration = new CodeTypeDelegate ();
850 CodeDomProvider provider = new VBCodeProvider ();
851 _codeGenerator = provider.CreateGenerator ();
855 public override void DefaultTypeTest ()
857 string code = GenerateDefaultType (Options);
858 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
859 "Public Delegate Sub (){0}", NewLine), code);
863 [ExpectedException (typeof (NullReferenceException))]
864 public override void NullTypeTest ()
866 GenerateNullType (Options);
870 public override void SimpleTypeTest ()
872 string code = GenerateSimpleType (Options);
873 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
874 "Public Delegate Sub Test1(){0}", NewLine), code);
878 public override void DerivedTypeTest ()
880 string code = GenerateDerivedType (Options);
881 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
882 "Delegate Sub Test1(){0}", NewLine), code);
886 public override void AttributesAndTypeTest ()
888 CodeTypeDelegate delegateDecl = new CodeTypeDelegate ();
889 delegateDecl.ReturnType = new CodeTypeReference (typeof (int));
891 _typeDeclaration = delegateDecl;
893 string code = GenerateAttributesAndType (Options);
894 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
897 "Public Delegate Function Test1() As Integer{0}", NewLine), code);
901 public override void EventMembersTypeTest1 ()
903 string code = GenerateEventMembersType1 (Options);
904 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
905 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
909 public override void EventMembersTypeTest2 ()
911 string code = GenerateEventMembersType2 (Options);
912 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
913 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
917 public override void EventImplementationTypes ()
919 string code = GenerateEventImplementationTypes (Options);
920 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
921 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
925 /// Ensure no access modifiers are output if PrivateImplementationType
929 public override void EventPrivateImplementationType ()
931 string code = GenerateEventPrivateImplementationType (Options);
932 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
933 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
937 /// If both ImplementationTypes and PrivateImplementationType are set,
938 /// then only ImplementationTypes are output.
941 public override void EventImplementationTypeOrder ()
943 string code = GenerateEventImplementationTypeOrder (Options);
944 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
945 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
949 public override void FieldMembersAttributesTest ()
951 string code = GenerateFieldMembersAttributes (Options);
952 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
953 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
957 public override void FieldMembersTypeTest ()
959 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
960 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
961 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
965 public override void FieldNewSlotTest ()
967 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
968 MemberAttributes.New, Options);
969 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
970 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
974 public override void PropertyMembersTypeTest1 ()
976 string code = GeneratePropertyMembersAttributes (Options);
977 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
978 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
982 public override void PropertyMembersTypeTest2 ()
984 string code = GeneratePropertyMembersType (MemberAttributes.Public,
985 false, false, Options);
986 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
987 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
991 public override void PropertyMembersTypeGetOnly ()
993 string code = GeneratePropertyMembersType (MemberAttributes.Family,
994 true, false, Options);
995 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
996 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1000 public override void PropertyMembersTypeSetOnly ()
1002 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1003 false, true, Options);
1004 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1005 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1009 public override void PropertyMembersTypeGetSet ()
1011 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1012 true, true, Options);
1013 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1014 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1018 public override void PropertyMembersTypeFamilyOrAssembly ()
1020 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
1021 false, false, Options);
1022 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1023 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1027 public override void PropertyMembersTypeAssembly ()
1029 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1030 false, false, Options);
1031 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1032 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1036 public override void PropertyParametersTest ()
1038 string code = GeneratePropertyParameters (Options);
1039 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1040 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1044 public override void PropertyIndexerTest1 ()
1046 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1047 false, false, true, Options);
1048 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1049 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1053 public override void PropertyIndexerTest2 ()
1055 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1056 false, false, false, Options);
1057 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1058 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1062 public override void PropertyIndexerGetOnly ()
1064 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1065 true, false, true, Options);
1066 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1067 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1071 public override void PropertyIndexerSetOnly ()
1073 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1074 false, true, true, Options);
1075 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1076 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1080 public override void PropertyImplementationTypes ()
1082 string code = GeneratePropertyImplementationTypes (Options);
1083 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1084 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1088 public override void PropertyOverloadsTest1 ()
1090 string code = GeneratePropertyOverloads1 (Options);
1091 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1092 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1096 public override void PropertyOverloadsTest2 ()
1098 string code = GeneratePropertyOverloads2 (Options);
1099 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1100 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1104 public override void PropertyOverloadsTest3 ()
1106 string code = GeneratePropertyOverloads3 (Options);
1107 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1108 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1112 public override void PropertyPrivateImplementationType ()
1114 string code = GeneratePropertyPrivateImplementationType (Options);
1115 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1116 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1120 public override void PropertyImplementationTypeOrder ()
1122 string code = GeneratePropertyImplementationTypeOrder (Options);
1123 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1124 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1128 public override void PropertyNewSlotTest ()
1130 string code = GeneratePropertyMembersType (MemberAttributes.Private |
1131 MemberAttributes.New, true, true, Options);
1132 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1133 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1137 public override void MethodMembersTypeTest1 ()
1139 string code = GenerateMethodMembersType1 (Options);
1140 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1141 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1145 public override void MethodMembersTypeTest2 ()
1147 string code = GenerateMethodMembersType2 (Options);
1148 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1149 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1153 public override void MethodMembersTypeTest3 ()
1155 string code = GenerateMethodMembersType3 (Options);
1156 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1157 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1161 public override void MethodImplementationTypes ()
1163 string code = GenerateMethodImplementationTypes (Options);
1164 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1165 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1169 public override void MethodOverloadsTest1 ()
1171 string code = GenerateMethodOverloads1 (Options);
1172 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1173 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1177 public override void MethodOverloadsTest2 ()
1179 string code = GenerateMethodOverloads2 (Options);
1180 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1181 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1185 public override void MethodOverloadsTest3 ()
1187 string code = GenerateMethodOverloads3 (Options);
1188 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1189 "Public Delegate Sub Test1(){0}{0}{0}", NewLine), code);
1193 public override void MethodPrivateImplementationType ()
1195 string code = GenerateMethodPrivateImplementationType (Options);
1196 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1197 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1201 public override void MethodImplementationTypeOrder ()
1203 string code = GenerateMethodImplementationTypeOrder (Options);
1204 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1205 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1209 public override void MethodParamArrayAttribute ()
1211 string code = GenerateMethodParamArrayAttribute (Options);
1212 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1213 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1217 public override void MethodReturnTypeAttributes ()
1219 string code = GenerateMethodReturnTypeAttributes (Options);
1220 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1221 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1225 public override void MethodNewSlotTest ()
1227 string code = GenerateMethodNewSlot (Options);
1228 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1229 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1233 public override void ConstructorAttributesTest ()
1235 string code = GenerateConstructorAttributes (Options);
1236 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1237 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1241 public override void ConstructorParametersTest ()
1243 string code = GenerateConstructorParameters (Options);
1244 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1245 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1249 public override void ConstructorParameterAttributesTest ()
1251 string code = GenerateConstructorParameterAttributes (Options);
1252 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1253 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1257 public override void BaseConstructorSingleArg ()
1259 string code = GenerateBaseConstructor (false, Options);
1260 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1261 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1265 public override void BaseConstructorMultipleArgs ()
1267 string code = GenerateBaseConstructor (true, Options);
1268 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1269 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1273 public override void ChainedConstructorSingleArg ()
1275 string code = GenerateChainedConstructor (false, Options);
1276 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1277 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1281 public override void ChainedConstructorMultipleArgs ()
1283 string code = GenerateChainedConstructor (true, Options);
1284 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1285 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1289 public override void TypeConstructorTest ()
1291 string code = GenerateTypeConstructor (Options);
1292 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1293 "Public Delegate Sub Test1(){0}{0}", NewLine), code);
1297 public override void EntryPointMethodTest ()
1299 string code = GenerateEntryPointMethod (Options);
1300 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1301 "Public Delegate Sub Test1(){0}{0}" +
1303 "Public Shared Sub Main(){0}" +
1304 " Dim x As Test.InnerType{0}" +
1305 "End Sub{0}", NewLine), code);
1309 public void DelegateWithParametersTest ()
1311 CodeTypeDelegate type = new CodeTypeDelegate("A");
1312 type.Parameters.Add (new CodeParameterDeclarationExpression ("type", "param"));
1314 string code = GenerateCodeFromType (type, Options);
1315 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1316 "Public Delegate Sub A(ByVal param As type){0}", NewLine), code);
1320 public override void PartialTypeTest ()
1322 string code = GeneratePartialType (Options);
1323 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1324 "Public Delegate Sub Test1(){0}", NewLine), code);
1329 public class CodeGeneratorFromTypeTest_Interface : CodeGeneratorFromTypeTestBase
1331 private CodeTypeDeclaration _typeDeclaration;
1332 private ICodeGenerator _codeGenerator;
1334 protected override ICodeGenerator CodeGenerator
1336 get { return _codeGenerator; }
1339 protected override CodeTypeDeclaration TypeDeclaration
1341 get { return _typeDeclaration; }
1345 public override void SetUp ()
1348 _typeDeclaration = new CodeTypeDeclaration ();
1349 _typeDeclaration.IsInterface = true;
1351 CodeDomProvider provider = new VBCodeProvider ();
1352 _codeGenerator = provider.CreateGenerator ();
1356 public override void DefaultTypeTest ()
1358 string code = GenerateDefaultType (Options);
1359 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1360 "Public Interface {0}" +
1361 "End Interface{0}", NewLine), code);
1365 [ExpectedException (typeof (NullReferenceException))]
1366 public override void NullTypeTest ()
1368 GenerateNullType (Options);
1372 public override void SimpleTypeTest ()
1374 string code = GenerateSimpleType (Options);
1375 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1376 "Public Interface Test1{0}" +
1377 "End Interface{0}", NewLine), code);
1381 public override void DerivedTypeTest ()
1383 string code = GenerateDerivedType (Options);
1384 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1385 "Friend Interface Test1{0}" +
1386 " Inherits Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
1387 "End Interface{0}", NewLine), code);
1391 public override void AttributesAndTypeTest ()
1393 string code = GenerateAttributesAndType (Options);
1394 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1397 "Public Interface Test1{0}" +
1398 "End Interface{0}", NewLine), code);
1402 public override void EventMembersTypeTest1 ()
1404 string code = GenerateEventMembersType1 (Options);
1405 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1406 "Public Interface Test1{0}" +
1410 " Private Event __exception As System.Void{0}" +
1411 "End Interface{0}", NewLine), code);
1415 public override void EventMembersTypeTest2 ()
1417 string code = GenerateEventMembersType2 (Options);
1418 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1419 "Public Interface Test1{0}" +
1421 " Public Event Click As Integer{0}" +
1422 "End Interface{0}", NewLine), code);
1426 public override void EventImplementationTypes ()
1428 string code = GenerateEventImplementationTypes (Options);
1429 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1430 "Public Interface Test1{0}" +
1432 " Friend Event Click As Integer Implements IPolicy.Click , IWhatever.Click{0}" +
1433 "End Interface{0}", NewLine), code);
1437 public override void EventPrivateImplementationType ()
1439 string code = GenerateEventPrivateImplementationType (Options);
1440 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1441 "Public Interface Test1{0}" +
1443 " Protected Event System_Int32_Click As Integer Implements Integer.Click{0}" +
1444 "End Interface{0}", NewLine), code);
1448 public override void EventImplementationTypeOrder ()
1450 string code = GenerateEventImplementationTypeOrder (Options);
1451 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1452 "Public Interface Test1{0}" +
1454 " Public Event System_Int32_Click As Integer Implements IPolicy.Click{0}" +
1455 "End Interface{0}", NewLine), code);
1459 public override void FieldMembersAttributesTest ()
1461 string code = GenerateFieldMembersAttributes (Options);
1462 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1463 "Public Interface Test1{0}" +
1465 "End Interface{0}", NewLine), code);
1469 public override void FieldMembersTypeTest ()
1471 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
1472 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1473 "Public Interface Test1{0}" +
1475 "End Interface{0}", NewLine), code);
1479 public override void FieldNewSlotTest ()
1481 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
1482 MemberAttributes.New, Options);
1483 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1484 "Public Interface Test1{0}" +
1486 "End Interface{0}", NewLine), code);
1490 public override void PropertyMembersTypeTest1 ()
1492 string code = GeneratePropertyMembersAttributes (Options);
1493 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1494 "Public Interface Test1{0}" +
1498 " Property () As System.Void{0}" +
1499 "End Interface{0}", NewLine), code);
1503 public override void PropertyMembersTypeTest2 ()
1505 string code = GeneratePropertyMembersType (MemberAttributes.Public,
1506 false, false, Options);
1507 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1508 "Public Interface Test1{0}" +
1510 " Property Name() As Integer{0}" +
1511 "End Interface{0}", NewLine), code);
1515 public override void PropertyMembersTypeGetOnly ()
1517 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1518 true, false, Options);
1519 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1520 "Public Interface Test1{0}" +
1522 " ReadOnly Property Name() As Integer{0}" +
1523 "End Interface{0}", NewLine), code);
1527 public override void PropertyMembersTypeSetOnly ()
1529 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1530 false, true, Options);
1531 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1532 "Public Interface Test1{0}" +
1534 " WriteOnly Property Name() As Integer{0}" +
1535 "End Interface{0}", NewLine), code);
1539 public override void PropertyMembersTypeGetSet ()
1541 string code = GeneratePropertyMembersType (MemberAttributes.Family,
1542 true, true, Options);
1543 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1544 "Public Interface Test1{0}" +
1546 " Property Name() As Integer{0}" +
1547 "End Interface{0}", NewLine), code);
1551 public override void PropertyMembersTypeFamilyOrAssembly ()
1553 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
1554 false, false, Options);
1555 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1556 "Public Interface Test1{0}" +
1558 " Property Name() As Integer{0}" +
1559 "End Interface{0}", NewLine), code);
1563 public override void PropertyMembersTypeAssembly ()
1565 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
1566 false, false, Options);
1567 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1568 "Public Interface Test1{0}" +
1570 " Property Name() As Integer{0}" +
1571 "End Interface{0}", NewLine), code);
1575 public override void PropertyParametersTest ()
1577 string code = GeneratePropertyParameters (Options);
1578 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1579 "Public Interface Test1{0}" +
1581 " Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1582 "End Interface{0}", NewLine), code);
1586 public override void PropertyIndexerTest1 ()
1588 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1589 false, false, true, Options);
1590 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1591 "Public Interface Test1{0}" +
1593 " Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1594 "End Interface{0}", NewLine), code);
1598 public override void PropertyIndexerTest2 ()
1600 string code = GeneratePropertyIndexer (MemberAttributes.Public,
1601 false, false, false, Options);
1602 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1603 "Public Interface Test1{0}" +
1605 " Property iTem() As Integer{0}" +
1606 "End Interface{0}", NewLine), code);
1610 public override void PropertyIndexerGetOnly ()
1612 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1613 true, false, true, Options);
1614 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1615 "Public Interface Test1{0}" +
1617 " Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1618 "End Interface{0}", NewLine), code);
1622 public override void PropertyIndexerSetOnly ()
1624 string code = GeneratePropertyIndexer (MemberAttributes.Family,
1625 false, true, true, Options);
1626 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1627 "Public Interface Test1{0}" +
1629 " Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
1630 "End Interface{0}", NewLine), code);
1634 public override void PropertyImplementationTypes ()
1636 string code = GeneratePropertyImplementationTypes (Options);
1637 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1638 "Public Interface Test1{0}" +
1640 " Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
1641 "End Interface{0}", NewLine), code);
1645 public override void PropertyOverloadsTest1 ()
1647 string code = GeneratePropertyOverloads1 (Options);
1648 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1649 "Public Interface Test1{0}" +
1651 " Property Name() As Integer{0}" +
1652 "End Interface{0}", NewLine), code);
1656 public override void PropertyOverloadsTest2 ()
1658 string code = GeneratePropertyOverloads2 (Options);
1659 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1660 "Public Interface Test1{0}" +
1662 " Property Name() As Integer{0}" +
1664 " Property Name(ByVal value1 As Object) As Integer{0}" +
1665 "End Interface{0}", NewLine), code);
1669 public override void PropertyOverloadsTest3 ()
1671 string code = GeneratePropertyOverloads3 (Options);
1672 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1673 "Public Interface Test1{0}" +
1675 " Property Name() As Integer{0}" +
1677 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
1678 "End Interface{0}", NewLine), code);
1682 public override void PropertyPrivateImplementationType ()
1684 string code = GeneratePropertyPrivateImplementationType (Options);
1685 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1686 "Public Interface Test1{0}" +
1688 " Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
1689 "End Interface{0}", NewLine), code);
1693 public override void PropertyImplementationTypeOrder ()
1695 string code = GeneratePropertyImplementationTypeOrder (Options);
1696 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1697 "Public Interface Test1{0}" +
1699 " Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
1700 "End Interface{0}", NewLine), code);
1704 public override void PropertyNewSlotTest ()
1706 string code = GeneratePropertyMembersType (MemberAttributes.Private |
1707 MemberAttributes.New, true, true, Options);
1708 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1709 "Public Interface Test1{0}" +
1711 " Shadows Property Name() As Integer{0}" +
1712 "End Interface{0}", NewLine), code);
1716 public override void MethodMembersTypeTest1 ()
1718 string code = GenerateMethodMembersType1 (Options);
1719 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1720 "Public Interface Test1{0}" +
1725 "End Interface{0}", NewLine), code);
1729 public override void MethodMembersTypeTest2 ()
1731 string code = GenerateMethodMembersType2 (Options);
1732 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1733 "Public Interface Test1{0}" +
1735 " Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
1736 "End Interface{0}", NewLine), code);
1740 public override void MethodMembersTypeTest3 ()
1742 string code = GenerateMethodMembersType3 (Options);
1743 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1744 "Public Interface Test1{0}" +
1746 " Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
1747 "End Interface{0}", NewLine), code);
1751 public override void MethodImplementationTypes ()
1753 string code = GenerateMethodImplementationTypes (Options);
1754 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1755 "Public Interface Test1{0}" +
1757 " Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
1758 "End Interface{0}", NewLine), code);
1762 public override void MethodOverloadsTest1 ()
1764 string code = GenerateMethodOverloads1 (Options);
1765 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1766 "Public Interface Test1{0}" +
1768 " Function Execute() As Integer{0}" +
1769 "End Interface{0}", NewLine), code);
1773 public override void MethodOverloadsTest2 ()
1775 string code = GenerateMethodOverloads2 (Options);
1776 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1777 "Public Interface Test1{0}" +
1779 " Sub Execute(){0}" +
1781 " Function Execute(ByVal value1 As Object) As Integer{0}" +
1782 "End Interface{0}", NewLine), code);
1786 public override void MethodOverloadsTest3 ()
1788 string code = GenerateMethodOverloads3 (Options);
1789 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1790 "Public Interface Test1{0}" +
1792 " Sub Execute(){0}" +
1794 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
1795 "End Interface{0}", NewLine), code);
1799 public override void MethodPrivateImplementationType ()
1801 string code = GenerateMethodPrivateImplementationType (Options);
1802 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1803 "Public Interface Test1{0}" +
1805 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
1806 "End Interface{0}", NewLine), code);
1810 public override void MethodImplementationTypeOrder ()
1812 string code = GenerateMethodImplementationTypeOrder (Options);
1813 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1814 "Public Interface Test1{0}" +
1816 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
1817 "End Interface{0}", NewLine), code);
1821 public override void MethodParamArrayAttribute ()
1823 string code = GenerateMethodParamArrayAttribute (Options);
1824 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1825 "Public Interface Test1{0}" +
1827 " Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
1828 "End Interface{0}", NewLine), code);
1832 public override void MethodReturnTypeAttributes ()
1834 string code = GenerateMethodReturnTypeAttributes (Options);
1835 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1836 "Public Interface Test1{0}" +
1840 " System.ParamArrayAttribute()> _{0}" +
1841 " Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
1842 "End Interface{0}", NewLine), code);
1846 public override void MethodNewSlotTest ()
1848 string code = GenerateMethodNewSlot (Options);
1849 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1850 "Public Interface Test1{0}" +
1852 " Shadows Function Execute() As Integer{0}" +
1853 "End Interface{0}", NewLine), code);
1857 public override void ConstructorAttributesTest ()
1859 string code = GenerateConstructorAttributes (Options);
1860 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1861 "Public Interface Test1{0}" +
1863 "End Interface{0}", NewLine), code);
1867 public override void ConstructorParametersTest ()
1869 string code = GenerateConstructorParameters (Options);
1870 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1871 "Public Interface Test1{0}" +
1873 "End Interface{0}", NewLine), code);
1877 public override void ConstructorParameterAttributesTest ()
1879 string code = GenerateConstructorParameterAttributes (Options);
1880 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1881 "Public Interface Test1{0}" +
1883 "End Interface{0}", NewLine), code);
1887 public override void BaseConstructorSingleArg ()
1889 string code = GenerateBaseConstructor (false, Options);
1890 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1891 "Public Interface Test1{0}" +
1893 "End Interface{0}", NewLine), code);
1897 public override void BaseConstructorMultipleArgs ()
1899 string code = GenerateBaseConstructor (true, Options);
1900 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1901 "Public Interface Test1{0}" +
1903 "End Interface{0}", NewLine), code);
1907 public override void ChainedConstructorSingleArg ()
1909 string code = GenerateChainedConstructor (false, Options);
1910 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1911 "Public Interface Test1{0}" +
1913 "End Interface{0}", NewLine), code);
1917 public override void ChainedConstructorMultipleArgs ()
1919 string code = GenerateChainedConstructor (true, Options);
1920 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1921 "Public Interface Test1{0}" +
1923 "End Interface{0}", NewLine), code);
1927 public override void TypeConstructorTest ()
1929 string code = GenerateTypeConstructor (Options);
1930 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1931 "Public Interface Test1{0}" +
1933 "End Interface{0}", NewLine), code);
1937 public override void EntryPointMethodTest ()
1939 string code = GenerateEntryPointMethod (Options);
1940 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1941 "Public Interface Test1{0}" +
1944 " Public Shared Sub Main(){0}" +
1945 " Dim x As Test.InnerType{0}" +
1947 "End Interface{0}", NewLine), code);
1951 public override void PartialTypeTest ()
1953 string code = GeneratePartialType (Options);
1954 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1955 "Partial Public Interface Test1{0}" +
1956 "End Interface{0}", NewLine), code);
1961 public class CodeGeneratorFromTypeTest_Struct : CodeGeneratorFromTypeTestBase
1963 private CodeTypeDeclaration _typeDeclaration;
1964 private ICodeGenerator _codeGenerator;
1966 protected override ICodeGenerator CodeGenerator
1968 get { return _codeGenerator; }
1971 protected override CodeTypeDeclaration TypeDeclaration
1973 get { return _typeDeclaration; }
1977 public override void SetUp ()
1980 _typeDeclaration = new CodeTypeDeclaration ();
1981 _typeDeclaration.IsStruct = true;
1983 CodeDomProvider provider = new VBCodeProvider ();
1984 _codeGenerator = provider.CreateGenerator ();
1988 public override void DefaultTypeTest ()
1990 string code = GenerateDefaultType (Options);
1991 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1992 "Public Structure {0}" +
1993 "End Structure{0}", NewLine), code);
1997 [ExpectedException (typeof (NullReferenceException))]
1998 public override void NullTypeTest ()
2000 GenerateNullType (Options);
2004 public override void SimpleTypeTest ()
2006 string code = GenerateSimpleType (Options);
2007 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2008 "Public Structure Test1{0}" +
2009 "End Structure{0}", NewLine), code);
2013 public override void DerivedTypeTest ()
2015 string code = GenerateDerivedType (Options);
2016 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2017 "Friend Structure Test1{0}" +
2018 " Implements Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
2019 "End Structure{0}", NewLine), code);
2023 public override void AttributesAndTypeTest ()
2025 string code = GenerateAttributesAndType (Options);
2026 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2029 "Public Structure Test1{0}" +
2030 "End Structure{0}", NewLine), code);
2034 public override void EventMembersTypeTest1 ()
2036 string code = GenerateEventMembersType1 (Options);
2037 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2038 "Public Structure Test1{0}" +
2042 " Private Event __exception As System.Void{0}" +
2043 "End Structure{0}", NewLine), code);
2047 public override void EventMembersTypeTest2 ()
2049 string code = GenerateEventMembersType2 (Options);
2050 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2051 "Public Structure Test1{0}" +
2053 " Public Event Click As Integer{0}" +
2054 "End Structure{0}", NewLine), code);
2058 public override void EventImplementationTypes ()
2060 string code = GenerateEventImplementationTypes (Options);
2061 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2062 "Public Structure Test1{0}" +
2064 " Friend Event Click As Integer Implements IPolicy.Click , IWhatever.Click{0}" +
2065 "End Structure{0}", NewLine), code);
2069 public override void EventPrivateImplementationType ()
2071 string code = GenerateEventPrivateImplementationType (Options);
2072 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2073 "Public Structure Test1{0}" +
2075 " Protected Event System_Int32_Click As Integer Implements Integer.Click{0}" +
2076 "End Structure{0}", NewLine), code);
2080 public override void EventImplementationTypeOrder ()
2082 string code = GenerateEventImplementationTypeOrder (Options);
2083 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2084 "Public Structure Test1{0}" +
2086 " Public Event System_Int32_Click As Integer Implements IPolicy.Click{0}" +
2087 "End Structure{0}", NewLine), code);
2091 public override void FieldMembersAttributesTest ()
2093 string code = GenerateFieldMembersAttributes (Options);
2094 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2095 "Public Structure Test1{0}" +
2099 " Private __exception As System.Void{0}" +
2100 "End Structure{0}", NewLine), code);
2104 public override void FieldMembersTypeTest ()
2106 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
2107 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2108 "Public Structure Test1{0}" +
2110 " Public Name As Integer = 2{0}" +
2111 "End Structure{0}", NewLine), code);
2115 public override void FieldNewSlotTest ()
2117 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
2118 MemberAttributes.New, Options);
2119 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2120 "Public Structure Test1{0}" +
2122 " Friend Shadows Name As Integer = 2{0}" +
2123 "End Structure{0}", NewLine), code);
2127 public override void PropertyMembersTypeTest1 ()
2129 string code = GeneratePropertyMembersAttributes (Options);
2130 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2131 "Public Structure Test1{0}" +
2135 " Private Property () As System.Void{0}" +
2136 " End Property{0}" +
2137 "End Structure{0}", NewLine), code);
2141 public override void PropertyMembersTypeTest2 ()
2143 string code = GeneratePropertyMembersType (MemberAttributes.Public,
2144 false, false, Options);
2145 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2146 "Public Structure Test1{0}" +
2148 " Public Overridable Property Name() As Integer{0}" +
2149 " End Property{0}" +
2150 "End Structure{0}", NewLine), code);
2154 public override void PropertyMembersTypeGetOnly ()
2156 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2157 true, false, Options);
2158 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2159 "Public Structure Test1{0}" +
2161 " Protected Overridable ReadOnly Property Name() As Integer{0}" +
2164 " End Property{0}" +
2165 "End Structure{0}", NewLine), code);
2169 public override void PropertyMembersTypeSetOnly ()
2171 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2172 false, true, Options);
2173 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2174 "Public Structure Test1{0}" +
2176 " Friend Overridable WriteOnly Property Name() As Integer{0}" +
2179 " End Property{0}" +
2180 "End Structure{0}", NewLine), code);
2184 public override void PropertyMembersTypeGetSet ()
2186 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2187 true, true, Options);
2188 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2189 "Public Structure Test1{0}" +
2191 " Protected Overridable Property Name() As Integer{0}" +
2196 " End Property{0}" +
2197 "End Structure{0}", NewLine), code);
2201 public override void PropertyMembersTypeFamilyOrAssembly ()
2203 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
2204 false, false, Options);
2205 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2206 "Public Structure Test1{0}" +
2208 " Protected Friend Property Name() As Integer{0}" +
2209 " End Property{0}" +
2210 "End Structure{0}", NewLine), code);
2214 public override void PropertyMembersTypeAssembly ()
2216 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2217 false, false, Options);
2218 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2219 "Public Structure Test1{0}" +
2221 " Friend Overridable Property Name() As Integer{0}" +
2222 " End Property{0}" +
2223 "End Structure{0}", NewLine), code);
2227 public override void PropertyParametersTest ()
2229 string code = GeneratePropertyParameters (Options);
2230 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2231 "Public Structure Test1{0}" +
2233 " Public Overridable Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2234 " End Property{0}" +
2235 "End Structure{0}", NewLine), code);
2239 public override void PropertyIndexerTest1 ()
2241 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2242 false, false, true, Options);
2243 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2244 "Public Structure Test1{0}" +
2246 " Public Overridable Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2247 " End Property{0}" +
2248 "End Structure{0}", NewLine), code);
2252 public override void PropertyIndexerTest2 ()
2254 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2255 false, false, false, Options);
2256 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2257 "Public Structure Test1{0}" +
2259 " Public Overridable Property iTem() As Integer{0}" +
2260 " End Property{0}" +
2261 "End Structure{0}", NewLine), code);
2265 public override void PropertyIndexerGetOnly ()
2267 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2268 true, false, true, Options);
2269 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2270 "Public Structure Test1{0}" +
2272 " Protected Overridable Default ReadOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2275 " End Property{0}" +
2276 "End Structure{0}", NewLine), code);
2280 public override void PropertyIndexerSetOnly ()
2282 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2283 false, true, true, Options);
2284 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2285 "Public Structure Test1{0}" +
2287 " Protected Overridable Default WriteOnly Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}" +
2290 " End Property{0}" +
2291 "End Structure{0}", NewLine), code);
2295 public override void PropertyImplementationTypes ()
2297 string code = GeneratePropertyImplementationTypes (Options);
2298 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2299 "Public Structure Test1{0}" +
2301 " Public Overridable Property Name() As Integer Implements IPolicy.Name , IWhatever.Name{0}" +
2302 " End Property{0}" +
2303 "End Structure{0}", NewLine), code);
2307 public override void PropertyOverloadsTest1 ()
2309 string code = GeneratePropertyOverloads1 (Options);
2310 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2311 "Public Structure Test1{0}" +
2313 " Protected Overloads Overridable Property Name() As Integer{0}" +
2314 " End Property{0}" +
2315 "End Structure{0}", NewLine), code);
2319 public override void PropertyOverloadsTest2 ()
2321 string code = GeneratePropertyOverloads2 (Options);
2322 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2323 "Public Structure Test1{0}" +
2325 " Public Overloads Overridable Property Name() As Integer{0}" +
2326 " End Property{0}" +
2328 " Private Overloads Property Name(ByVal value1 As Object) As Integer{0}" +
2329 " End Property{0}" +
2330 "End Structure{0}", NewLine), code);
2334 public override void PropertyOverloadsTest3 ()
2336 string code = GeneratePropertyOverloads3 (Options);
2337 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2338 "Public Structure Test1{0}" +
2340 " Public Overridable Property Name() As Integer{0}" +
2341 " End Property{0}" +
2343 " Property System_Int32_Name(ByVal value1 As Object) As Integer Implements Integer.Name{0}" +
2344 " End Property{0}" +
2345 "End Structure{0}", NewLine), code);
2349 public override void PropertyPrivateImplementationType ()
2351 string code = GeneratePropertyPrivateImplementationType (Options);
2352 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2353 "Public Structure Test1{0}" +
2355 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements Integer.Item{0}" +
2356 " End Property{0}" +
2357 "End Structure{0}", NewLine), code);
2361 public override void PropertyImplementationTypeOrder ()
2363 string code = GeneratePropertyImplementationTypeOrder (Options);
2364 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2365 "Public Structure Test1{0}" +
2367 " Overridable Property System_Int32_Item(ByVal value1 As Object) As Integer Implements IPolicy.Item{0}" +
2368 " End Property{0}" +
2369 "End Structure{0}", NewLine), code);
2373 public override void PropertyNewSlotTest ()
2375 string code = GeneratePropertyMembersType (MemberAttributes.Private |
2376 MemberAttributes.New, true, true, Options);
2377 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2378 "Public Structure Test1{0}" +
2380 " Private Shadows Property Name() As Integer{0}" +
2385 " End Property{0}" +
2386 "End Structure{0}", NewLine), code);
2390 public override void MethodMembersTypeTest1 ()
2392 string code = GenerateMethodMembersType1 (Options);
2393 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2394 "Public Structure Test1{0}" +
2398 " Private Sub (){0}" +
2400 "End Structure{0}", NewLine), code);
2404 public override void MethodMembersTypeTest2 ()
2406 string code = GenerateMethodMembersType2 (Options);
2407 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2408 "Public Structure Test1{0}" +
2410 " Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}" +
2411 " End Function{0}" +
2412 "End Structure{0}", NewLine), code);
2416 public override void MethodMembersTypeTest3 ()
2418 string code = GenerateMethodMembersType3 (Options);
2419 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2420 "Public Structure Test1{0}" +
2422 " Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef __exception As Integer) As Integer{0}" +
2423 " End Function{0}" +
2424 "End Structure{0}", NewLine), code);
2428 public override void MethodImplementationTypes ()
2430 string code = GenerateMethodImplementationTypes (Options);
2431 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2432 "Public Structure Test1{0}" +
2434 " Friend Overridable Function Execute() As Integer Implements IPolicy.Execute , IWhatever.Execute{0}" +
2435 " End Function{0}" +
2436 "End Structure{0}", NewLine), code);
2440 public override void MethodOverloadsTest1 ()
2442 string code = GenerateMethodOverloads1 (Options);
2443 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2444 "Public Structure Test1{0}" +
2446 " Friend Overloads Overridable Function Execute() As Integer{0}" +
2447 " End Function{0}" +
2448 "End Structure{0}", NewLine), code);
2452 public override void MethodOverloadsTest2 ()
2454 string code = GenerateMethodOverloads2 (Options);
2455 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2456 "Public Structure Test1{0}" +
2458 " Public Overloads Overridable Sub Execute(){0}" +
2461 " Private Overloads Function Execute(ByVal value1 As Object) As Integer{0}" +
2462 " End Function{0}" +
2463 "End Structure{0}", NewLine), code);
2467 public override void MethodOverloadsTest3 ()
2469 string code = GenerateMethodOverloads3 (Options);
2470 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2471 "Public Structure Test1{0}" +
2473 " Public Overridable Sub Execute(){0}" +
2476 " Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
2477 " End Function{0}" +
2478 "End Structure{0}", NewLine), code);
2482 public override void MethodPrivateImplementationType ()
2484 string code = GenerateMethodPrivateImplementationType (Options);
2485 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2486 "Public Structure Test1{0}" +
2488 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements Integer.Execute{0}" +
2489 " End Function{0}" +
2490 "End Structure{0}", NewLine), code);
2494 public override void MethodImplementationTypeOrder ()
2496 string code = GenerateMethodImplementationTypeOrder (Options);
2497 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2498 "Public Structure Test1{0}" +
2500 " Overridable Function System_Int32_Execute(ByVal value1 As Object) As Integer Implements IPolicy.Execute{0}" +
2501 " End Function{0}" +
2502 "End Structure{0}", NewLine), code);
2506 public override void MethodParamArrayAttribute ()
2508 string code = GenerateMethodParamArrayAttribute (Options);
2509 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2510 "Public Structure Test1{0}" +
2512 " Public Overridable Function Something(<A(), System.ParamArrayAttribute(), B()> ByRef value As Object, <C()> ByRef __exception As Integer) As Integer{0}" +
2513 " End Function{0}" +
2514 "End Structure{0}", NewLine), code);
2518 public override void MethodReturnTypeAttributes ()
2520 string code = GenerateMethodReturnTypeAttributes (Options);
2521 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2522 "Public Structure Test1{0}" +
2526 " System.ParamArrayAttribute()> _{0}" +
2527 " Public Overridable Function Execute() As <C(A1:=false, A2:=true), System.ParamArrayAttribute(), D()> Integer{0}" +
2528 " End Function{0}" +
2529 "End Structure{0}", NewLine), code);
2533 public override void MethodNewSlotTest ()
2535 string code = GenerateMethodNewSlot (Options);
2536 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2537 "Public Structure Test1{0}" +
2539 " Public Shadows Overridable Function Execute() As Integer{0}" +
2540 " End Function{0}" +
2541 "End Structure{0}", NewLine), code);
2545 public override void ConstructorAttributesTest ()
2547 // FIXME: updated to reflect mbas workaround
2548 string code = GenerateConstructorAttributes (Options);
2549 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2550 "Public Structure Test1{0}" +
2554 " Private Sub New(){0}" +
2556 "End Structure{0}", NewLine), code);
2560 public override void ConstructorParametersTest ()
2562 // FIXME: updated to reflect mbas workaround
2563 string code = GenerateConstructorParameters (Options);
2564 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2565 "Public Structure Test1{0}" +
2567 " Public Sub New(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer){0}" +
2569 "End Structure{0}", NewLine), code);
2573 public override void ConstructorParameterAttributesTest ()
2575 // FIXME: updated to reflect mbas workaround
2576 string code = GenerateConstructorParameterAttributes (Options);
2577 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2578 "Public Structure Test1{0}" +
2580 " Private Sub New(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer){0}" +
2582 "End Structure{0}", NewLine), code);
2586 public override void BaseConstructorSingleArg ()
2588 string code = GenerateBaseConstructor (false, Options);
2589 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2590 "Public Structure Test1{0}" +
2592 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2593 " MyBase.New(value1){0}" +
2595 "End Structure{0}", NewLine), code);
2599 public override void BaseConstructorMultipleArgs ()
2601 string code = GenerateBaseConstructor (true, Options);
2602 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2603 "Public Structure Test1{0}" +
2605 " Protected Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2606 " MyBase.New(value1, value2){0}" +
2608 "End Structure{0}", NewLine), code);
2612 public override void ChainedConstructorSingleArg ()
2614 string code = GenerateChainedConstructor (false, Options);
2615 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2616 "Public Structure Test1{0}" +
2618 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2619 " Me.New(value1){0}" +
2621 "End Structure{0}", NewLine), code);
2625 public override void ChainedConstructorMultipleArgs ()
2627 string code = GenerateChainedConstructor (true, Options);
2628 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2629 "Public Structure Test1{0}" +
2631 " Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}" +
2632 " Me.New(value1, value2){0}" +
2634 "End Structure{0}", NewLine), code);
2638 public override void TypeConstructorTest ()
2640 string code = GenerateTypeConstructor (Options);
2641 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2642 "Public Structure Test1{0}" +
2646 " Shared Sub New(){0}" +
2648 "End Structure{0}", NewLine), code);
2652 public override void EntryPointMethodTest ()
2654 string code = GenerateEntryPointMethod (Options);
2655 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2656 "Public Structure Test1{0}" +
2659 " Public Shared Sub Main(){0}" +
2660 " Dim x As Test.InnerType{0}" +
2662 "End Structure{0}", NewLine), code);
2666 public override void PartialTypeTest ()
2668 string code = GeneratePartialType (Options);
2669 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2670 "Partial Public Structure Test1{0}" +
2671 "End Structure{0}", NewLine), code);
2676 public class CodeGeneratorFromTypeTest_Enum : CodeGeneratorFromTypeTestBase
2678 private CodeTypeDeclaration _typeDeclaration;
2679 private ICodeGenerator _codeGenerator;
2681 protected override ICodeGenerator CodeGenerator
2683 get { return _codeGenerator; }
2686 protected override CodeTypeDeclaration TypeDeclaration
2688 get { return _typeDeclaration; }
2692 public override void SetUp ()
2695 _typeDeclaration = new CodeTypeDeclaration ();
2696 _typeDeclaration.IsEnum = true;
2698 CodeDomProvider provider = new VBCodeProvider ();
2699 _codeGenerator = provider.CreateGenerator ();
2703 public override void DefaultTypeTest ()
2705 string code = GenerateDefaultType (Options);
2706 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2708 "End Enum{0}", NewLine), code);
2712 [ExpectedException (typeof (NullReferenceException))]
2713 public override void NullTypeTest ()
2715 GenerateNullType (Options);
2719 public override void SimpleTypeTest ()
2721 string code = GenerateSimpleType (Options);
2722 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2723 "Public Enum Test1{0}" +
2724 "End Enum{0}", NewLine), code);
2728 public override void DerivedTypeTest ()
2730 string code = GenerateDerivedType (Options);
2731 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2732 "Friend Enum Test1 As Integer{0}" +
2733 "End Enum{0}", NewLine), code);
2737 public override void AttributesAndTypeTest ()
2739 string code = GenerateAttributesAndType (Options);
2740 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2743 "Public Enum Test1{0}" +
2744 "End Enum{0}", NewLine), code);
2748 public override void EventMembersTypeTest1 ()
2750 string code = GenerateEventMembersType1 (Options);
2751 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2752 "Public Enum Test1{0}" +
2754 "End Enum{0}", NewLine), code);
2758 public override void EventMembersTypeTest2 ()
2760 string code = GenerateEventMembersType2 (Options);
2761 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2762 "Public Enum Test1{0}" +
2764 "End Enum{0}", NewLine), code);
2768 public override void EventImplementationTypes ()
2770 string code = GenerateEventImplementationTypes (Options);
2771 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2772 "Public Enum Test1{0}" +
2774 "End Enum{0}", NewLine), code);
2778 public override void EventPrivateImplementationType ()
2780 string code = GenerateEventPrivateImplementationType (Options);
2781 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2782 "Public Enum Test1{0}" +
2784 "End Enum{0}", NewLine), code);
2788 public override void EventImplementationTypeOrder ()
2790 string code = GenerateEventImplementationTypeOrder (Options);
2791 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2792 "Public Enum Test1{0}" +
2794 "End Enum{0}", NewLine), code);
2798 public override void FieldMembersAttributesTest ()
2800 string code = GenerateFieldMembersAttributes (Options);
2801 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2802 "Public Enum Test1{0}" +
2807 "End Enum{0}", NewLine), code);
2811 public override void FieldMembersTypeTest ()
2813 string code = GenerateFieldMembersType (MemberAttributes.Public, Options);
2814 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2815 "Public Enum Test1{0}" +
2818 "End Enum{0}", NewLine), code);
2822 public override void FieldNewSlotTest ()
2824 string code = GenerateFieldMembersType (MemberAttributes.Assembly |
2825 MemberAttributes.New, Options);
2826 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2827 "Public Enum Test1{0}" +
2830 "End Enum{0}", NewLine), code);
2834 public override void PropertyMembersTypeTest1 ()
2836 string code = GeneratePropertyMembersAttributes (Options);
2837 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2838 "Public Enum Test1{0}" +
2840 "End Enum{0}", NewLine), code);
2844 public override void PropertyMembersTypeTest2 ()
2846 string code = GeneratePropertyMembersType (MemberAttributes.Public,
2847 false, false, Options);
2848 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2849 "Public Enum Test1{0}" +
2851 "End Enum{0}", NewLine), code);
2855 public override void PropertyMembersTypeGetOnly ()
2857 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2858 true, false, Options);
2859 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2860 "Public Enum Test1{0}" +
2862 "End Enum{0}", NewLine), code);
2866 public override void PropertyMembersTypeSetOnly ()
2868 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2869 false, true, Options);
2870 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2871 "Public Enum Test1{0}" +
2873 "End Enum{0}", NewLine), code);
2877 public override void PropertyMembersTypeGetSet ()
2879 string code = GeneratePropertyMembersType (MemberAttributes.Family,
2880 true, true, Options);
2881 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2882 "Public Enum Test1{0}" +
2884 "End Enum{0}", NewLine), code);
2888 public override void PropertyMembersTypeFamilyOrAssembly ()
2890 string code = GeneratePropertyMembersType (MemberAttributes.FamilyOrAssembly,
2891 false, false, Options);
2892 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2893 "Public Enum Test1{0}" +
2895 "End Enum{0}", NewLine), code);
2899 public override void PropertyMembersTypeAssembly ()
2901 string code = GeneratePropertyMembersType (MemberAttributes.Assembly,
2902 false, false, Options);
2903 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2904 "Public Enum Test1{0}" +
2906 "End Enum{0}", NewLine), code);
2910 public override void PropertyParametersTest ()
2912 string code = GeneratePropertyParameters (Options);
2913 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2914 "Public Enum Test1{0}" +
2916 "End Enum{0}", NewLine), code);
2920 public override void PropertyIndexerTest1 ()
2922 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2923 false, false, true, Options);
2924 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2925 "Public Enum Test1{0}" +
2927 "End Enum{0}", NewLine), code);
2931 public override void PropertyIndexerTest2 ()
2933 string code = GeneratePropertyIndexer (MemberAttributes.Public,
2934 false, false, false, Options);
2935 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2936 "Public Enum Test1{0}" +
2938 "End Enum{0}", NewLine), code);
2942 public override void PropertyIndexerGetOnly ()
2944 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2945 true, false, true, Options);
2946 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2947 "Public Enum Test1{0}" +
2949 "End Enum{0}", NewLine), code);
2953 public override void PropertyIndexerSetOnly ()
2955 string code = GeneratePropertyIndexer (MemberAttributes.Family,
2956 false, true, true, Options);
2957 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2958 "Public Enum Test1{0}" +
2960 "End Enum{0}", NewLine), code);
2964 public override void PropertyImplementationTypes ()
2966 string code = GeneratePropertyImplementationTypes (Options);
2967 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2968 "Public Enum Test1{0}" +
2970 "End Enum{0}", NewLine), code);
2974 public override void PropertyOverloadsTest1 ()
2976 string code = GeneratePropertyOverloads1 (Options);
2977 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2978 "Public Enum Test1{0}" +
2980 "End Enum{0}", NewLine), code);
2984 public override void PropertyOverloadsTest2 ()
2986 string code = GeneratePropertyOverloads2 (Options);
2987 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2988 "Public Enum Test1{0}" +
2991 "End Enum{0}", NewLine), code);
2995 public override void PropertyOverloadsTest3 ()
2997 string code = GeneratePropertyOverloads3 (Options);
2998 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2999 "Public Enum Test1{0}" +
3002 "End Enum{0}", NewLine), code);
3006 public override void PropertyPrivateImplementationType ()
3008 string code = GeneratePropertyPrivateImplementationType (Options);
3009 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3010 "Public Enum Test1{0}" +
3012 "End Enum{0}", NewLine), code);
3016 public override void PropertyImplementationTypeOrder ()
3018 string code = GeneratePropertyImplementationTypeOrder (Options);
3019 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3020 "Public Enum Test1{0}" +
3022 "End Enum{0}", NewLine), code);
3026 public override void PropertyNewSlotTest ()
3028 string code = GeneratePropertyMembersType (MemberAttributes.Private |
3029 MemberAttributes.New, true, true, Options);
3030 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3031 "Public Enum Test1{0}" +
3033 "End Enum{0}", NewLine), code);
3037 public override void MethodMembersTypeTest1 ()
3039 string code = GenerateMethodMembersType1 (Options);
3040 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3041 "Public Enum Test1{0}" +
3043 "End Enum{0}", NewLine), code);
3047 public override void MethodMembersTypeTest2 ()
3049 string code = GenerateMethodMembersType2 (Options);
3050 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3051 "Public Enum Test1{0}" +
3053 "End Enum{0}", NewLine), code);
3057 public override void MethodMembersTypeTest3 ()
3059 string code = GenerateMethodMembersType3 (Options);
3060 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3061 "Public Enum Test1{0}" +
3063 "End Enum{0}", NewLine), code);
3067 public override void MethodImplementationTypes ()
3069 string code = GenerateMethodImplementationTypes (Options);
3070 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3071 "Public Enum Test1{0}" +
3073 "End Enum{0}", NewLine), code);
3077 public override void MethodOverloadsTest1 ()
3079 string code = GenerateMethodOverloads1 (Options);
3080 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3081 "Public Enum Test1{0}" +
3083 "End Enum{0}", NewLine), code);
3087 public override void MethodOverloadsTest2 ()
3089 string code = GenerateMethodOverloads2 (Options);
3090 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3091 "Public Enum Test1{0}" +
3094 "End Enum{0}", NewLine), code);
3098 public override void MethodOverloadsTest3 ()
3100 string code = GenerateMethodOverloads3 (Options);
3101 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3102 "Public Enum Test1{0}" +
3105 "End Enum{0}", NewLine), code);
3109 public override void MethodPrivateImplementationType ()
3111 string code = GenerateMethodPrivateImplementationType (Options);
3112 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3113 "Public Enum Test1{0}" +
3115 "End Enum{0}", NewLine), code);
3119 public override void MethodImplementationTypeOrder ()
3121 string code = GenerateMethodImplementationTypeOrder (Options);
3122 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3123 "Public Enum Test1{0}" +
3125 "End Enum{0}", NewLine), code);
3129 public override void MethodParamArrayAttribute ()
3131 string code = GenerateMethodParamArrayAttribute (Options);
3132 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3133 "Public Enum Test1{0}" +
3135 "End Enum{0}", NewLine), code);
3139 public override void MethodReturnTypeAttributes ()
3141 string code = GenerateMethodReturnTypeAttributes (Options);
3142 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3143 "Public Enum Test1{0}" +
3145 "End Enum{0}", NewLine), code);
3149 public override void MethodNewSlotTest ()
3151 string code = GenerateMethodNewSlot (Options);
3152 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3153 "Public Enum Test1{0}" +
3155 "End Enum{0}", NewLine), code);
3159 public override void ConstructorAttributesTest ()
3161 string code = GenerateConstructorAttributes (Options);
3162 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3163 "Public Enum Test1{0}" +
3165 "End Enum{0}", NewLine), code);
3169 public override void ConstructorParametersTest ()
3171 string code = GenerateConstructorParameters (Options);
3172 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3173 "Public Enum Test1{0}" +
3175 "End Enum{0}", NewLine), code);
3179 public override void ConstructorParameterAttributesTest ()
3181 string code = GenerateConstructorParameterAttributes (Options);
3182 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3183 "Public Enum Test1{0}" +
3185 "End Enum{0}", NewLine), code);
3189 public override void BaseConstructorSingleArg ()
3191 string code = GenerateBaseConstructor (false, Options);
3192 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3193 "Public Enum Test1{0}" +
3195 "End Enum{0}", NewLine), code);
3199 public override void BaseConstructorMultipleArgs ()
3201 string code = GenerateBaseConstructor (true, Options);
3202 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3203 "Public Enum Test1{0}" +
3205 "End Enum{0}", NewLine), code);
3209 public override void ChainedConstructorSingleArg ()
3211 string code = GenerateChainedConstructor (false, Options);
3212 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3213 "Public Enum Test1{0}" +
3215 "End Enum{0}", NewLine), code);
3219 public override void ChainedConstructorMultipleArgs ()
3221 string code = GenerateChainedConstructor (true, Options);
3222 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3223 "Public Enum Test1{0}" +
3225 "End Enum{0}", NewLine), code);
3229 public override void TypeConstructorTest ()
3231 string code = GenerateTypeConstructor (Options);
3232 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3233 "Public Enum Test1{0}" +
3235 "End Enum{0}", NewLine), code);
3239 public override void EntryPointMethodTest ()
3241 string code = GenerateEntryPointMethod (Options);
3242 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3243 "Public Enum Test1{0}" +
3246 " Public Shared Sub Main(){0}" +
3247 " Dim x As Test.InnerType{0}" +
3249 "End Enum{0}", NewLine), code);
3253 public override void PartialTypeTest ()
3255 string code = GeneratePartialType (Options);
3256 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
3257 "Partial Public Enum Test1{0}" +
3258 "End Enum{0}", NewLine), code);