[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Internal / Commands / OneTimeSetUpCommand.cs
1 // ***********************************************************************
2 // Copyright (c) 2012 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 NUnit.Framework.Interfaces;
32
33 namespace NUnit.Framework.Internal.Commands
34 {
35     /// <summary>
36     /// OneTimeSetUpCommand runs any one-time setup methods for a suite,
37     /// constructing the user test object if necessary.
38     /// </summary>
39     public class OneTimeSetUpCommand : TestCommand
40     {
41         private readonly TestSuite _suite;
42         private readonly ITypeInfo _typeInfo;
43         private readonly object[] _arguments;
44         private readonly List<SetUpTearDownItem> _setUpTearDown;
45         private readonly List<TestActionItem> _actions;
46
47         /// <summary>
48         /// Constructs a OneTimeSetUpCommand for a suite
49         /// </summary>
50         /// <param name="suite">The suite to which the command applies</param>
51         /// <param name="setUpTearDown">A SetUpTearDownList for use by the command</param>
52         /// <param name="actions">A List of TestActionItems to be run after Setup</param>
53         public OneTimeSetUpCommand(TestSuite suite, List<SetUpTearDownItem> setUpTearDown, List<TestActionItem> actions)
54             : base(suite)
55         {
56             _suite = suite;
57             _typeInfo = suite.TypeInfo;
58             _arguments = suite.Arguments;
59             _setUpTearDown = setUpTearDown;
60             _actions = actions;
61         }
62
63         /// <summary>
64         /// Overridden to run the one-time setup for a suite.
65         /// </summary>
66         /// <param name="context">The TestExecutionContext to be used.</param>
67         /// <returns>A TestResult</returns>
68         public override TestResult Execute(TestExecutionContext context)
69         {
70             if (_typeInfo != null)
71             {
72                 // Use pre-constructed fixture if available, otherwise construct it
73                 if (!_typeInfo.IsStaticClass)
74                 {
75                     context.TestObject = _suite.Fixture ?? _typeInfo.Construct(_arguments);
76                     if (_suite.Fixture == null)
77                     {
78                         _suite.Fixture = context.TestObject;
79                     }
80                     Test.Fixture = _suite.Fixture;
81                 }
82
83                 for (int i = _setUpTearDown.Count; i > 0; )
84                     _setUpTearDown[--i].RunSetUp(context);
85             }
86
87
88             for (int i = 0; i < _actions.Count; i++)
89                 _actions[i].BeforeTest(Test);
90
91             return context.CurrentResult;
92         }
93     }
94 }