1 //
2 // Unit tests for System.ObsoleteAttribute
3 //
4 // Authors:
5 //	Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 
29 using System;
30 
31 using NUnit.Framework;
32 
33 namespace MonoTests.System {
34 
35 	[TestFixture]
36 	public class ObsoleteAttributeTest {
37 
38 		[Test]
Type()39 		public void Type ()
40 		{
41 			object[] attrs = typeof (ObsoleteAttribute).GetCustomAttributes (typeof (AttributeUsageAttribute), false);
42 			AttributeUsageAttribute usage = (AttributeUsageAttribute) attrs [0];
43 
44 			Assert.IsFalse (usage.AllowMultiple, "AllowMultiple");
45 			Assert.IsFalse (usage.Inherited, "Inherited");
46 			Assert.AreEqual (usage.ValidOn, AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
47 				AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property |
48 				AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface |
49 				AttributeTargets.Delegate, "ValidOn");
50 		}
51 
Check(ObsoleteAttribute attr, string message, bool error)52 		private void Check (ObsoleteAttribute attr, string message, bool error)
53 		{
54 			Assert.AreEqual (message, attr.Message, "Message");
55 			Assert.AreEqual (error, attr.IsError, "IsError");
56 			Assert.AreEqual (typeof (ObsoleteAttribute), attr.TypeId, "TypeId");
57 		}
58 
59 		[Test]
Constructor()60 		public void Constructor ()
61 		{
62 			Check (new ObsoleteAttribute (), null, false);
63 		}
64 
65 		[Test]
ConstructorMessage_Null()66 		public void ConstructorMessage_Null ()
67 		{
68 			Check (new ObsoleteAttribute (null), null, false);
69 		}
70 
71 		[Test]
ConstructorMessage_Empty()72 		public void ConstructorMessage_Empty ()
73 		{
74 			Check (new ObsoleteAttribute (String.Empty), String.Empty, false);
75 		}
76 
77 		[Test]
ConstructorMessage()78 		public void ConstructorMessage ()
79 		{
80 			string message = "too late, stuff is long gone";
81 			Check (new ObsoleteAttribute (message), message, false);
82 		}
83 
84 		[Test]
ConstructorMessageBoolTrue()85 		public void ConstructorMessageBoolTrue ()
86 		{
87 			Check (new ObsoleteAttribute (null, true), null, true);
88 		}
89 
90 		[Test]
ConstructorMessageBoolFalse()91 		public void ConstructorMessageBoolFalse ()
92 		{
93 			string message = "too late, stuff is long gone";
94 			Check (new ObsoleteAttribute (message, false), message, false);
95 		}
96 	}
97 }
98