1. Mihai Mogosanu
  2. WebActivator

Commits

Mihai Mogosanu  committed 06f73c0

Changed Order to be an int
Reformatted code with spaces

  • Participants
  • Parent commits c84b4b2
  • Branches default

Comments (0)

Files changed (5)

File TestLibrary/MyStartupCode.cs

View file
  • Ignore whitespace
 using System;
 
 [assembly: WebActivator.PreApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "Start")]
-[assembly: WebActivator.PreApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "Start2",Order = 2)]
-[assembly: WebActivator.PreApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "Start3",Order = 1)]
+[assembly: WebActivator.PreApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "Start2", Order = 2)]
+[assembly: WebActivator.PreApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "Start3", Order = 1)]
 [assembly: WebActivator.PostApplicationStartMethod(typeof(TestLibrary.MyStartupCode), "CallMeAfterAppStart")]
 [assembly: WebActivator.ApplicationShutdownMethod(typeof(TestLibrary.MyStartupCode), "CallMeWhenAppEnds")]
 
-namespace TestLibrary {
-    public static class MyStartupCode {
-       
-		public static string ExecutedOrder="";
-		public static bool StartCalled { get; set; }
+namespace TestLibrary
+{
+    public static class MyStartupCode
+    {
+
+        public static string ExecutedOrder = "";
+        public static bool StartCalled { get; set; }
         public static bool Start2Called { get; set; }
         public static bool CallMeAfterAppStartCalled { get; set; }
         public static bool CallMeWhenAppEndsCalled { get; set; }
 
-        internal static void Start() {
-            if (StartCalled) {
+        internal static void Start()
+        {
+            if (StartCalled)
+            {
                 throw new Exception("Unexpected second call to Start");
             }
 
             StartCalled = true;
-        	ExecutedOrder += "Start";
+            ExecutedOrder += "Start";
         }
 
-        public static void Start2() {
-            if (Start2Called) {
+        public static void Start2()
+        {
+            if (Start2Called)
+            {
                 throw new Exception("Unexpected second call to Start2");
             }
 
             Start2Called = true;
-			ExecutedOrder += "Start2";
+            ExecutedOrder += "Start2";
         }
 
-		public static void Start3()
-		{
-			ExecutedOrder += "Start3";
-		}
+        public static void Start3()
+        {
+            ExecutedOrder += "Start3";
+        }
 
-        public static void CallMeAfterAppStart() {
+        public static void CallMeAfterAppStart()
+        {
             // This gets called after global.asax's Application_Start
 
-            if (CallMeAfterAppStartCalled) {
+            if (CallMeAfterAppStartCalled)
+            {
                 throw new Exception("Unexpected second call to CallMeAfterAppStart");
             }
 
             CallMeAfterAppStartCalled = true;
-			ExecutedOrder += "CallMeAfterAppStart";
+            ExecutedOrder += "CallMeAfterAppStart";
         }
 
-        public static void CallMeWhenAppEnds() {
+        public static void CallMeWhenAppEnds()
+        {
             // This gets called when the app shuts down
 
-            if (CallMeWhenAppEndsCalled) {
+            if (CallMeWhenAppEndsCalled)
+            {
                 throw new Exception("Unexpected second call to CallMeWhenAppEnds");
             }
 
-            CallMeWhenAppEndsCalled = true;			
-			ExecutedOrder += "CallMeWhenAppEnds";
+            CallMeWhenAppEndsCalled = true;
+            ExecutedOrder += "CallMeWhenAppEnds";
         }
     }
 }

File TestWebApp/TestStartupCode/MyStartupCode.cs

View file
  • Ignore whitespace
 
 [assembly: WebActivator.PreApplicationStartMethod(typeof(TestWebApp.TestStartupCode.MyStartupCode), "Start",Order = 1)]
 
-namespace TestWebApp.TestStartupCode {
-    public static class MyStartupCode {
+namespace TestWebApp.TestStartupCode
+{
+    public static class MyStartupCode
+    {
         public static bool StartCalled { get; set; }
 
-        public static void Start() {
+        public static void Start()
+        {
             StartCalled = true;
-			Debug.WriteLine("MyStartUpCode1");			
+            Debug.WriteLine("MyStartUpCode1");
         }
     }
 }

File TestWebApp/TestStartupCode/MyStartupCode2.cs

View file
  • Ignore whitespace
 using System.Web.Mvc;
 using System.Web.Routing;
 
-[assembly: WebActivator.PreApplicationStartMethod(typeof(TestWebApp.TestStartupCode.MyStartupCode2), "Start",Order = 0)]
+[assembly:
+    WebActivator.PreApplicationStartMethod(typeof (TestWebApp.TestStartupCode.MyStartupCode2), "Start", Order = 0)]
 
-namespace TestWebApp.TestStartupCode {
-    public static class MyStartupCode2 {
+namespace TestWebApp.TestStartupCode
+{
+    public static class MyStartupCode2
+    {
         public static bool StartCalled { get; set; }
 
-        public static void Start() {
+        public static void Start()
+        {
             StartCalled = true;
-			Debug.WriteLine("MyStartUpCode2");
+            Debug.WriteLine("MyStartUpCode2");
         }
     }
-}
+}

File WebActivator/BaseActivationMethodAttribute.cs

View file
  • Ignore whitespace
 using System;
 using System.Reflection;
 
-namespace WebActivator {
+namespace WebActivator
+{
     // Base class of all the activation attributes
     [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
-    public abstract class BaseActivationMethodAttribute : Attribute {
+    public abstract class BaseActivationMethodAttribute : Attribute
+    {
         private Type _type;
         private string _methodName;
 
-        public BaseActivationMethodAttribute(Type type, string methodName) {
+        public BaseActivationMethodAttribute(Type type, string methodName)
+        {
             _type = type;
             _methodName = methodName;
         }
 
-        public Type Type {
-            get {
-                return _type;
-            }
+        public Type Type
+        {
+            get { return _type; }
         }
 
-        public string MethodName {
-            get {
-                return _methodName;
-            }
+        public string MethodName
+        {
+            get { return _methodName; }
         }
 
-		public byte Order { get; set; }
+        public int Order { get; set; }
 
 
-        public void InvokeMethod() {
+        public void InvokeMethod()
+        {
             // Get the method
             MethodInfo method = Type.GetMethod(
                 MethodName,
                 BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
 
-            if (method == null) {
+            if (method == null)
+            {
                 throw new ArgumentException(
                     String.Format("The type {0} doesn't have a static method named {1}",
-                        Type, MethodName));
+                                  Type, MethodName));
             }
 
             // Invoke it
             method.Invoke(null, null);
         }
     }
-}
+}

File WebActivatorTest/WebActivatorUnitTest.cs

View file
  • Ignore whitespace
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using TestLibrary;
 
-namespace WebActivatorTest {
+namespace WebActivatorTest
+{
     [TestClass]
-    public class WebActivatorUnitTest {
+    public class WebActivatorUnitTest
+    {
         [TestMethod]
-        public void TestWebActivatorAllStartMethodsGetCalled() {
+        public void TestWebActivatorAllStartMethodsGetCalled()
+        {
             MyStartupCode.StartCalled = MyStartupCode.Start2Called = MyStartupCode.CallMeAfterAppStartCalled = false;
 
             WebActivator.ActivationManager.Run();
         }
 
         [TestMethod]
-        public void TestWebActivatorPreStartMethodsGetCalled() {
+        public void TestWebActivatorPreStartMethodsGetCalled()
+        {
             MyStartupCode.StartCalled = MyStartupCode.Start2Called = MyStartupCode.CallMeAfterAppStartCalled = false;
 
             WebActivator.ActivationManager.RunPreStartMethods();
         }
 
         [TestMethod]
-        public void TestWebActivatorPostStartMethodsGetCalled() {
+        public void TestWebActivatorPostStartMethodsGetCalled()
+        {
             MyStartupCode.StartCalled = MyStartupCode.Start2Called = MyStartupCode.CallMeAfterAppStartCalled = false;
 
             WebActivator.ActivationManager.RunPostStartMethods();
         }
 
         [TestMethod]
-        public void TestWebActivatorShutdownMethodsGetCalled() {
+        public void TestWebActivatorShutdownMethodsGetCalled()
+        {
             MyStartupCode.CallMeWhenAppEndsCalled = false;
 
             WebActivator.ActivationManager.RunShutdownMethods();
             Assert.IsTrue(MyStartupCode.CallMeWhenAppEndsCalled);
         }
 
-		[TestMethod]
-		public void  TestWebActivatorMethodsCalledBySpecifiedOrder()
-		{
-			WebActivator.ActivationManager.Run();
-			WebActivator.ActivationManager.RunShutdownMethods();
-			Assert.AreEqual("StartStart3Start2CallMeAfterAppStartCallMeWhenAppEnds", MyStartupCode.ExecutedOrder);
-		}
+        [TestMethod]
+        public void TestWebActivatorMethodsCalledBySpecifiedOrder()
+        {
+            WebActivator.ActivationManager.Run();
+            WebActivator.ActivationManager.RunShutdownMethods();
+            Assert.AreEqual("StartStart3Start2CallMeAfterAppStartCallMeWhenAppEnds", MyStartupCode.ExecutedOrder);
+        }
     }
-}
+}