Skip to content

Commit 2c900df

Browse files
committed
Wrote example test for init
1 parent 90808bd commit 2c900df

File tree

6 files changed

+101
-9
lines changed

6 files changed

+101
-9
lines changed

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<Compile Include="SemanticVersionTests.cs" />
148148
<Compile Include="TestEffectiveConfiguration.cs" />
149149
<Compile Include="TestFileSystem.cs" />
150+
<Compile Include="TestStream.cs" />
150151
<Compile Include="VariableProviderTests.cs" />
151152
<Compile Include="VersionCalculation\BaseVersionCalculatorTests.cs" />
152153
<Compile Include="VersionCalculation\NextVersionCalculatorTests.cs" />
@@ -158,7 +159,6 @@
158159
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
159160
</ItemGroup>
160161
<ItemGroup>
161-
<None Include="app.config" />
162162
<None Include="packages.config" />
163163
</ItemGroup>
164164
<ItemGroup>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
next-version: 2.0.0
2+
branches: {}

src/GitVersionCore.Tests/Init/InitScenarios.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersionCore.Tests.Init
22
{
3+
using ApprovalTests;
34
using GitVersion;
45
using GitVersion.Configuration.Init;
56
using GitVersion.Configuration.Init.Wizard;
@@ -10,6 +11,16 @@
1011
[TestFixture]
1112
public class InitScenarios
1213
{
14+
[Test]
15+
public void CanSetNextVersion()
16+
{
17+
var testFileSystem = new TestFileSystem();
18+
var testConsole = new TestConsole("3", "2.0.0", "0");
19+
ConfigurationProvider.Init("c:\\proj", testFileSystem, testConsole);
20+
21+
Approvals.Verify(testFileSystem.ReadAllText("c:\\proj\\GitVersionConfig.yaml"));
22+
}
23+
1324
[Test]
1425
public void DefaultResponsesDoNotThrow()
1526
{

src/GitVersionCore.Tests/TestFileSystem.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
using System.Collections.Generic;
2-
using System.IO;
3-
using GitVersion.Helpers;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using GitVersion.Helpers;
45

56
public class TestFileSystem : IFileSystem
67
{
78
Dictionary<string, string> fileSystem = new Dictionary<string, string>();
89

910
public void Copy(string @from, string to, bool overwrite)
1011
{
11-
throw new System.NotImplementedException();
12+
throw new NotImplementedException();
1213
}
1314

1415
public void Move(string @from, string to)
1516
{
16-
throw new System.NotImplementedException();
17+
throw new NotImplementedException();
1718
}
1819

1920
public bool Exists(string file)
@@ -23,7 +24,7 @@ public bool Exists(string file)
2324

2425
public void Delete(string path)
2526
{
26-
throw new System.NotImplementedException();
27+
throw new NotImplementedException();
2728
}
2829

2930
public string ReadAllText(string path)
@@ -41,11 +42,11 @@ public void WriteAllText(string file, string fileContents)
4142

4243
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption)
4344
{
44-
throw new System.NotImplementedException();
45+
throw new NotImplementedException();
4546
}
4647

4748
public Stream OpenWrite(string path)
4849
{
49-
throw new System.NotImplementedException();
50+
return new TestStream(path, this);
5051
}
5152
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
public class TestStream : Stream
7+
{
8+
readonly string path;
9+
readonly TestFileSystem testFileSystem;
10+
MemoryStream underlying = new MemoryStream();
11+
12+
public TestStream(string path, TestFileSystem testFileSystem)
13+
{
14+
this.path = path;
15+
this.testFileSystem = testFileSystem;
16+
}
17+
18+
protected override void Dispose(bool disposing)
19+
{
20+
Flush();
21+
base.Dispose(disposing);
22+
}
23+
24+
public override void Flush()
25+
{
26+
underlying.Position = 0;
27+
var readToEnd = new StreamReader(underlying).ReadToEnd();
28+
testFileSystem.WriteAllText(path, readToEnd);
29+
}
30+
31+
public override long Seek(long offset, SeekOrigin origin)
32+
{
33+
return underlying.Seek(offset, origin);
34+
}
35+
36+
public override void SetLength(long value)
37+
{
38+
underlying.SetLength(value);
39+
}
40+
41+
public override int Read(byte[] buffer, int offset, int count)
42+
{
43+
return underlying.Read(buffer, offset, count);
44+
}
45+
46+
public override void Write(byte[] buffer, int offset, int count)
47+
{
48+
underlying.Write(buffer, offset, count);
49+
}
50+
51+
public override void WriteByte(byte value)
52+
{
53+
base.WriteByte(value);
54+
}
55+
56+
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
57+
{
58+
return base.BeginWrite(buffer, offset, count, callback, state);
59+
}
60+
61+
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
62+
{
63+
return base.WriteAsync(buffer, offset, count, cancellationToken);
64+
}
65+
66+
public override bool CanRead { get { return underlying.CanRead; } }
67+
public override bool CanSeek { get { return underlying.CanSeek; } }
68+
public override bool CanWrite { get { return underlying.CanWrite; } }
69+
public override long Length { get { return underlying.Length; } }
70+
71+
public override long Position
72+
{
73+
get { return underlying.Position; }
74+
set { underlying.Position = value; }
75+
}
76+
}

src/GitVersionCore/SemanticVersion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ public string ToString(string format, IFormatProvider formatProvider = null)
258258
return string.Format("{0}.{1}.{2}", Major, Minor, Patch);
259259
case "s":
260260
return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag) : ToString("j");
261+
case "t":
262+
return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag.ToString("t")) : ToString("j");
261263
case "l":
262264
return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag.ToString("l")) : ToString("j");
263265
case "lp":

0 commit comments

Comments
 (0)