[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Internal / Commands / SetUpTearDownCommand.cs
1 // ***********************************************************************
2 // Copyright (c) 2014 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections.Generic;
31 using System.Threading;
32
33 namespace NUnit.Framework.Internal.Commands
34 {
35     using Execution;
36     using Interfaces;
37     using NUnit.Framework.TUnit;
38
39     /// <summary>
40     /// SetUpTearDownCommand runs any SetUp methods for a suite,
41     /// runs the test and then runs any TearDown methods.
42     /// </summary>
43     public class SetUpTearDownCommand : DelegatingTestCommand
44     {
45         private IList<SetUpTearDownItem> _setUpTearDownItems;
46
47         /// <summary>
48         /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class.
49         /// </summary>
50         /// <param name="innerCommand">The inner command.</param>
51         public SetUpTearDownCommand(TestCommand innerCommand)
52             : base(innerCommand)
53         {
54             Guard.ArgumentValid(innerCommand.Test is TestMethod, "SetUpTearDownCommand may only apply to a TestMethod", "innerCommand");
55             Guard.OperationValid(Test.TypeInfo != null, "TestMethod must have a non-null TypeInfo");
56
57             _setUpTearDownItems = CommandBuilder.BuildSetUpTearDownList(Test.TypeInfo.Type, typeof(SetUpAttribute), typeof(TearDownAttribute));
58         }
59
60         /// <summary>
61         /// Runs the test, saving a TestResult in the supplied TestExecutionContext.
62         /// </summary>
63         /// <param name="context">The context in which the test should run.</param>
64         /// <returns>A TestResult</returns>
65         public override TestResult Execute(TestExecutionContext context)
66         {
67             try
68             {
69                 TAsyncThreadMgr.GetInstance().ClearSetUpTearDown();
70                 for (int i = _setUpTearDownItems.Count; i > 0;)
71                     _setUpTearDownItems[--i].RunSetupForTC(context);
72
73                 for (int i = 0; i < _setUpTearDownItems.Count; i++)
74                     _setUpTearDownItems[i].RunTearDownForTC(context);
75
76                 context.CurrentResult = innerCommand.Execute(context);
77             }
78             catch (Exception ex)
79             {
80 #if !NETCF && !SILVERLIGHT && !PORTABLE
81                 if (ex is ThreadAbortException)
82                     Thread.ResetAbort();
83 #endif
84                 context.CurrentResult.RecordException(ex);
85             }
86
87             return context.CurrentResult;
88         }
89     }
90 }