Skip to content

Commit cb66dcc

Browse files
committed
Binary with -logFile
1 parent f8aed31 commit cb66dcc

8 files changed

Lines changed: 117 additions & 99 deletions

File tree

BrowserStack/BrowserStack Unit Tests/BrowserStack Unit Tests.csproj

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,24 @@
3939
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
4040
<Private>True</Private>
4141
</Reference>
42-
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
43-
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
42+
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
43+
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
47+
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
51+
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
52+
<Private>True</Private>
53+
</Reference>
54+
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
55+
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
56+
<Private>True</Private>
57+
</Reference>
58+
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
59+
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
4460
<Private>True</Private>
4561
</Reference>
4662
<Reference Include="System" />
@@ -71,7 +87,9 @@
7187
</ProjectReference>
7288
</ItemGroup>
7389
<ItemGroup>
74-
<None Include="packages.config" />
90+
<None Include="packages.config">
91+
<SubType>Designer</SubType>
92+
</None>
7593
</ItemGroup>
7694
<Choose>
7795
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">

BrowserStack/BrowserStack Unit Tests/BrowserStackTunnelTests.cs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
//using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using TestClass = NUnit.Framework.TestFixtureAttribute;
44
using TestMethod = NUnit.Framework.TestAttribute;
5-
using TestCleanup = NUnit.Framework.TearDownAttribute;
6-
using TestInitialize = NUnit.Framework.SetUpAttribute;
7-
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
8-
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
95

106
using NUnit.Framework;
117
using BrowserStack;
12-
using System.Collections.Generic;
13-
using Moq;
148
using System.Text;
159
using System.IO;
1610

@@ -24,15 +18,15 @@ public class BrowserStackTunnelTests
2418
public void TestInitialState()
2519
{
2620
tunnel = new TunnelClass();
27-
NUnit.Framework.Assert.AreEqual(tunnel.localState, LocalState.Idle);
28-
NUnit.Framework.Assert.NotNull(tunnel.getOutputBuilder());
21+
Assert.AreEqual(tunnel.localState, LocalState.Idle);
22+
Assert.NotNull(tunnel.getOutputBuilder());
2923
}
3024
[TestMethod]
3125
public void TestBinaryPathIsSet()
3226
{
3327
tunnel = new TunnelClass();
3428
tunnel.addBinaryPath("dummyPath");
35-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), "dummyPath");
29+
Assert.AreEqual(tunnel.getBinaryAbsolute(), "dummyPath");
3630
}
3731
[TestMethod]
3832
public void TestBinaryPathOnNull()
@@ -41,7 +35,7 @@ public void TestBinaryPathOnNull()
4135
tunnel.addBinaryPath(null);
4236
string expectedPath = Path.Combine(Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"), ".browserstack");
4337
expectedPath = Path.Combine(expectedPath, "BrowserStackLocal.exe");
44-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
38+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
4539
}
4640
[TestMethod]
4741
public void TestBinaryPathOnEmpty()
@@ -50,30 +44,30 @@ public void TestBinaryPathOnEmpty()
5044
tunnel.addBinaryPath("");
5145
string expectedPath = Path.Combine(Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"), ".browserstack");
5246
expectedPath = Path.Combine(expectedPath, "BrowserStackLocal.exe");
53-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
47+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
5448
}
5549
[TestMethod]
5650
public void TestBinaryPathOnFallback()
5751
{
5852
string expectedPath = "dummyPath";
5953
tunnel = new TunnelClass();
6054
tunnel.addBinaryPath("dummyPath");
61-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
55+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
6256

6357
tunnel.fallbackPaths();
6458
expectedPath = Path.Combine(Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"), ".browserstack");
6559
expectedPath = Path.Combine(expectedPath, "BrowserStackLocal.exe");
66-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
60+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
6761

6862
tunnel.fallbackPaths();
6963
expectedPath = Directory.GetCurrentDirectory();
7064
expectedPath = Path.Combine(expectedPath, "BrowserStackLocal.exe");
71-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
65+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
7266

7367
tunnel.fallbackPaths();
7468
expectedPath = Path.GetTempPath();
7569
expectedPath = Path.Combine(expectedPath, "BrowserStackLocal.exe");
76-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
70+
Assert.AreEqual(tunnel.getBinaryAbsolute(), expectedPath);
7771
}
7872
[TestMethod]
7973
public void TestBinaryPathOnNoMoreFallback()
@@ -83,7 +77,7 @@ public void TestBinaryPathOnNoMoreFallback()
8377
tunnel.fallbackPaths();
8478
tunnel.fallbackPaths();
8579
tunnel.fallbackPaths();
86-
NUnit.Framework.Assert.Throws(typeof(Exception),
80+
Assert.Throws(typeof(Exception),
8781
new TestDelegate(testFallbackException),
8882
"No More Paths to try. Please specify a binary path in options."
8983
);
@@ -93,14 +87,14 @@ public void TestBinaryArguments()
9387
{
9488
tunnel = new TunnelClass();
9589
tunnel.addBinaryArguments("dummyArguments");
96-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryArguments(), "dummyArguments");
90+
Assert.AreEqual(tunnel.getBinaryArguments(), "dummyArguments");
9791
}
9892
[TestMethod]
9993
public void TestBinaryArgumentsAreEmptyOnNull()
10094
{
10195
tunnel = new TunnelClass();
10296
tunnel.addBinaryArguments(null);
103-
NUnit.Framework.Assert.AreEqual(tunnel.getBinaryArguments(), "");
97+
Assert.AreEqual(tunnel.getBinaryArguments(), "");
10498
}
10599

106100

@@ -123,20 +117,5 @@ public string getBinaryArguments()
123117
return binaryArguments;
124118
}
125119
}
126-
[SetUpFixture]
127-
public class SetupClass
128-
{
129-
[SetUp]
130-
public void beforeEveryTest()
131-
{
132-
133-
}
134-
135-
[TearDown]
136-
public void afterEveryTest()
137-
{
138-
139-
}
140-
}
141120
}
142121
}

BrowserStack/BrowserStack Unit Tests/LocalTests.cs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,44 @@
44
using TestMethod = NUnit.Framework.TestAttribute;
55
using TestCleanup = NUnit.Framework.TearDownAttribute;
66
using TestInitialize = NUnit.Framework.SetUpAttribute;
7-
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
8-
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
97

108
using NUnit.Framework;
119
using BrowserStack;
1210
using System.Collections.Generic;
1311
using Moq;
12+
using System.IO;
1413

1514
namespace BrowserStack_Unit_Tests
1615
{
1716
[TestClass]
1817
public class LocalTests
1918
{
19+
static readonly string logAbsolute = Path.Combine(Directory.GetCurrentDirectory(), "local.log");
20+
private string user = "";
21+
private string accessKey = "";
22+
private LocalClass local;
23+
private List<KeyValuePair<String, String>> options;
24+
2025
public class LocalClass : Local
2126
{
2227
public void setTunnel(BrowserStackTunnel tunnel)
2328
{
2429
this.tunnel = tunnel;
2530
}
2631
}
27-
private LocalClass local;
28-
private List<KeyValuePair<String, String>> options;
32+
2933
[TestMethod]
3034
public void TestThrowsWithNoAccessKey()
3135
{
3236
options = new List<KeyValuePair<string, string>>();
37+
options.Add(new KeyValuePair<string, string>("key", ""));
3338
local = new LocalClass();
34-
NUnit.Framework.Assert.Throws(typeof(Exception),
39+
40+
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
41+
tunnelMock.Setup(mock => mock.Run("", "", logAbsolute));
42+
local.setTunnel(tunnelMock.Object);
43+
44+
Assert.Throws(typeof(Exception),
3545
new TestDelegate(startWithOptions),
3646
"BROWSERSTACK_ACCESS_KEY cannot be empty. Specify one by adding key to options or adding to the environment variable BROWSERSTACK_KEY.");
3747
local.stop();
@@ -45,10 +55,10 @@ public void TestWorksWithAccessKeyInOptions()
4555
local = new LocalClass();
4656
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
4757
local.setTunnel(tunnelMock.Object);
48-
NUnit.Framework.Assert.DoesNotThrow(new TestDelegate(startWithOptions),
58+
Assert.DoesNotThrow(new TestDelegate(startWithOptions),
4959
"BROWSERSTACK_ACCESS_KEY cannot be empty. Specify one by adding key to options or adding to the environment variable BROWSERSTACK_KEY.");
50-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
51-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Once());
60+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
61+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Once());
5262
local.stop();
5363
}
5464

@@ -59,11 +69,12 @@ public void TestWorksWithAccessKeyNotInOptions()
5969
options = new List<KeyValuePair<string, string>>();
6070
local = new LocalClass();
6171
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
72+
tunnelMock.Setup(mock => mock.Run("envDummyKey", "", logAbsolute));
6273
local.setTunnel(tunnelMock.Object);
63-
NUnit.Framework.Assert.DoesNotThrow(new TestDelegate(startWithOptions),
74+
Assert.DoesNotThrow(new TestDelegate(startWithOptions),
6475
"BROWSERSTACK_ACCESS_KEY cannot be empty. Specify one by adding key to options or adding to the environment variable BROWSERSTACK_KEY.");
65-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
66-
tunnelMock.Verify(mock => mock.Run("envDummyKey", ""), Times.Once());
76+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
77+
tunnelMock.Verify(mock => mock.Run("envDummyKey", "", logAbsolute), Times.Once());
6778
local.stop();
6879
}
6980

@@ -76,10 +87,11 @@ public void TestWorksForFolderTesting()
7687

7788
local = new LocalClass();
7889
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
90+
tunnelMock.Setup(mock => mock.Run("dummyKey", "dummyFolderPath", logAbsolute));
7991
local.setTunnel(tunnelMock.Object);
8092
local.start(options);
81-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
82-
tunnelMock.Verify(mock => mock.Run("dummyKey", "dummyFolderPath"), Times.Once());
93+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
94+
tunnelMock.Verify(mock => mock.Run("dummyKey", "dummyFolderPath", logAbsolute), Times.Once());
8395
local.stop();
8496
}
8597

@@ -92,11 +104,12 @@ public void TestWorksForBinaryPath()
92104

93105
local = new LocalClass();
94106
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
107+
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute));
95108
local.setTunnel(tunnelMock.Object);
96109
local.start(options);
97110
tunnelMock.Verify(mock => mock.addBinaryPath("dummyPath"), Times.Once);
98-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
99-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Once());
111+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
112+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Once());
100113
local.stop();
101114
}
102115

@@ -112,11 +125,12 @@ public void TestWorksWithBooleanOptions()
112125

113126
local = new LocalClass();
114127
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
128+
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute));
115129
local.setTunnel(tunnelMock.Object);
116130
local.start(options);
117131
tunnelMock.Verify(mock => mock.addBinaryPath(""), Times.Once);
118132
tunnelMock.Verify(mock => mock.addBinaryArguments(It.IsRegex("-vvv.*-force.*-forcelocal.*-onlyAutomate")), Times.Once());
119-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Once());
133+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Once());
120134
local.stop();
121135
}
122136

@@ -134,13 +148,14 @@ public void TestWorksWithValueOptions()
134148

135149
local = new LocalClass();
136150
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
151+
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute));
137152
local.setTunnel(tunnelMock.Object);
138153
local.start(options);
139154
tunnelMock.Verify(mock => mock.addBinaryPath(""), Times.Once);
140155
tunnelMock.Verify(mock => mock.addBinaryArguments(
141156
It.IsRegex("-localIdentifier.*dummyIdentifier.*dummyHost.*-proxyHost.*dummyHost.*-proxyPort.*dummyPort.*-proxyUser.*dummyUser.*-proxyPass.*dummyPass")
142157
), Times.Once());
143-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Once());
158+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Once());
144159
local.stop();
145160
}
146161

@@ -153,7 +168,7 @@ public void TestCallsFallbackOnFailure()
153168
local = new LocalClass();
154169
int count = 0;
155170
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
156-
tunnelMock.Setup(mock => mock.Run("dummyKey", "")).Callback(() =>
171+
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute)).Callback(() =>
157172
{
158173
count++;
159174
if (count == 1)
@@ -162,8 +177,8 @@ public void TestCallsFallbackOnFailure()
162177
local.setTunnel(tunnelMock.Object);
163178
local.start(options);
164179
tunnelMock.Verify(mock => mock.addBinaryPath(""), Times.Once);
165-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
166-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Exactly(2));
180+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
181+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Exactly(2));
167182
tunnelMock.Verify(mock => mock.fallbackPaths(), Times.Once());
168183
local.stop();
169184
}
@@ -176,27 +191,22 @@ public void TestKillsTunnel()
176191

177192
local = new LocalClass();
178193
Mock<BrowserStackTunnel> tunnelMock = new Mock<BrowserStackTunnel>();
194+
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute));
179195
local.setTunnel(tunnelMock.Object);
180196
local.start(options);
181197
local.stop();
182198
tunnelMock.Verify(mock => mock.addBinaryPath(""), Times.Once);
183-
tunnelMock.Verify(mock => mock.addBinaryArguments(""), Times.Once());
184-
tunnelMock.Verify(mock => mock.Run("dummyKey", ""), Times.Once());
199+
tunnelMock.Verify(mock => mock.addBinaryArguments("-logFile " + logAbsolute), Times.Once());
200+
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute), Times.Once());
185201
tunnelMock.Verify(mock => mock.Kill(), Times.Once());
186202
}
187203

188204
public void startWithOptions()
189205
{
190206
local.start(options);
191207
}
192-
}
193208

194-
[SetUpFixture]
195-
public class SetupClass
196-
{
197-
private string user = "";
198-
private string accessKey = "";
199-
[SetUp]
209+
[TestInitialize]
200210
public void beforeEveryTest()
201211
{
202212
user = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
@@ -205,7 +215,7 @@ public void beforeEveryTest()
205215
Environment.SetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY", "");
206216
}
207217

208-
[TearDown]
218+
[TestCleanup]
209219
public void afterEveryTest()
210220
{
211221
Environment.SetEnvironmentVariable("BROWSERSTACK_USERNAME", user);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
4-
<package id="NUnit" version="3.0.1" targetFramework="net45" />
4+
<package id="NUnit" version="2.6.0.12054" targetFramework="net45" />
5+
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" />
56
</packages>

0 commit comments

Comments
 (0)