Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use v0.00 if no version exist in workspace #300

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions yuniql-core/WorkspaceService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Yuniql.Extensibility;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Yuniql.Extensibility;

namespace Yuniql.Core
{
Expand Down Expand Up @@ -149,7 +149,7 @@ public string IncrementMajorVersion(string workspace, string sqlFileName)
{
var localVersions = GetLocalVersions(workspace);

var nextMajorVersion = new LocalVersion { Major = localVersions.First().Major + 1, Minor = 0 };
var nextMajorVersion = new LocalVersion { Major = (localVersions.FirstOrDefault()?.Major ?? -1) + 1, Minor = 0 };
localVersions.Add(nextMajorVersion);

string nextVersionPath = Path.Combine(workspace, nextMajorVersion.SemVersion);
Expand All @@ -171,7 +171,7 @@ public string IncrementMinorVersion(string workspace, string sqlFileName)
{
var localVersions = GetLocalVersions(workspace);

var nextMinorVersion = new LocalVersion { Major = localVersions.First().Major, Minor = localVersions.First().Minor + 1 };
var nextMinorVersion = new LocalVersion { Major = localVersions.FirstOrDefault()?.Major ?? 0, Minor = (localVersions.FirstOrDefault()?.Minor ?? -1) + 1 };
localVersions.Add(nextMinorVersion);

string nextVersionPath = Path.Combine(workspace, nextMinorVersion.SemVersion);
Expand Down
46 changes: 43 additions & 3 deletions yuniql-tests/unit-tests/Tests/WorkspaceServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Shouldly;
using Yuniql.Core;
using Yuniql.Extensibility;
using Shouldly;
using System.IO;

namespace Yuniql.UnitTests
{
Expand Down Expand Up @@ -134,7 +135,25 @@ public void Test_Increment_Major_Version()
directoryService.Verify(s => s.GetDirectories(workspace, "v*.*"));
directoryService.Verify(s => s.CreateDirectory(@$"{workspace}\v1.00"));
}
[TestMethod()]
public void Test_Increment_Major_Version_Without_Previous_Version()
{
//arrange
var workspace = @"c:\temp\yuniql";
var traceService = new Mock<ITraceService>();
var fileService = new Mock<IFileService>();

var directoryService = new Mock<IDirectoryService>();
directoryService.Setup(s => s.GetDirectories(workspace, "v*.*")).Returns(Array.Empty<string>());
//act
var sut = new WorkspaceService(traceService.Object, directoryService.Object, fileService.Object);
var result = sut.IncrementMajorVersion(workspace, sqlFileName: null);

//assert
result.ShouldBe("v0.00");
directoryService.Verify(s => s.GetDirectories(workspace, "v*.*"));
directoryService.Verify(s => s.CreateDirectory(@$"{workspace}\v0.00"));
}

[TestMethod()]
public void Test_Increment_Major_Version_With_Sql_File()
Expand Down Expand Up @@ -187,6 +206,27 @@ public void Test_Increment_Minor_Version()
directoryService.Verify(s => s.CreateDirectory(@$"{workspace}\v0.03"));
}

[TestMethod]
public void Test_Increment_Minor_Version_Without_Previous_Version()
{
//arrange
var workspace = @"c:\temp\yuniql";
var traceService = new Mock<ITraceService>();
var fileService = new Mock<IFileService>();

var directoryService = new Mock<IDirectoryService>();
directoryService.Setup(s => s.GetDirectories(workspace, "v*.*")).Returns(Array.Empty<string>());

//act
var sut = new WorkspaceService(traceService.Object, directoryService.Object, fileService.Object);
var result = sut.IncrementMinorVersion(workspace, sqlFileName: null);

//assert
result.ShouldBe("v0.00");
directoryService.Verify(s => s.GetDirectories(workspace, "v*.*"));
directoryService.Verify(s => s.CreateDirectory(@$"{workspace}\v0.00"));
}

[TestMethod]
public void Test_Increment_Minor_Version_With_Sql_File()
{
Expand Down