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

Dynamics NAV: version helpers #900

Merged
merged 2 commits into from
Aug 10, 2015
Merged
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
30 changes: 30 additions & 0 deletions src/app/FakeLib/DynamicsNavFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,33 @@ let splitNavisionFiles fileNames destDir =
use outputFile = new StreamWriter(Path.Combine(destDir, targetFile), false)
outputFile.Write(x.Source)
outputFile.Close()

/// Gets the version number for the specified version tag in a Dynamics NAV version tag list
let getTagVersionInVersionTagList (versionTag : string) (tagList : string) =
let versionTag = versionTag.ToUpper()
if tagList.ToUpper().Contains versionTag then
let tag = splitVersionTags tagList
|> Seq.find (fun x -> x.StartsWith versionTag)
tag.Replace(versionTag, "")
else
""

/// Gets the version number for the specified version tag in a Dynamics NAV object
let getTagVersionInObject (versionTag : string) sourceCode =
let tagList = getVersionTagList sourceCode
getTagVersionInVersionTagList versionTag tagList

/// Gets the highest version number for a specified version tag in a number of Dynamics NAV objects
let getHighestTagVersionInObjects (versionTag : string) sourceCode =
objectsInObjectString sourceCode
|> Seq.map (fun objectSourcecode -> getTagVersionInObject versionTag objectSourcecode.Source)
|> Seq.filter (fun version -> not (String.IsNullOrWhiteSpace(version)))
|> Seq.max

/// Gets the highest version number for a specified version tag in a number of Dynamics NAV objects in a set of object files
let getHighestTagVersionInFiles (versionTag : string) fileNames =
fileNames
|> Seq.map (fun fileName -> File.ReadAllText(fileName))
|> Seq.map (fun sourceCode -> getTagVersionInObject versionTag sourceCode)
|> Seq.filter (fun version -> not (String.IsNullOrWhiteSpace(version)))
|> Seq.max
20 changes: 20 additions & 0 deletions src/test/Test.FAKECore/NAVFiles/NAVVersionTagsSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ static IEnumerable<string> GetMissingRequiredTags(IEnumerable<string> requiredTa
}
}

public class CanGetVersionNumbers
{
It should_find_version_number = () =>
DynamicsNavFile.getTagVersionInVersionTagList("VU", "VU2.40.03,NTI.Nienburg,ARC5.10,MCN,NIW,PRE,AUS01").ShouldEqual("2.40.03");

It should_not_find_version_for_non_existing_tag = () =>
DynamicsNavFile.getTagVersionInVersionTagList("NAVW1", "VU2.40.03,NTI.Nienburg,ARC5.10,MCN,NIW,PRE,AUS01").ShouldBeEmpty();

It should_find_the_highest_version_number = () => {
var sourceCode = File.ReadAllText(@"NAVFiles/Table_3_and_4.txt");
DynamicsNavFile.getHighestTagVersionInObjects("NAVW1", sourceCode).ShouldEqual("7.10");
};

It should_find_the_highest_version_number_in_files = () =>
{
var files = new[] { @"NAVFiles/Codeunit_1.txt", @"NAVFiles/Table_3.txt" };
DynamicsNavFile.getHighestTagVersionInFiles("NAVW1", files).ShouldEqual("7.00");
};
}

public class CanDetectInvalidTags
{
It should_find_invalid_IssueNo = () =>
Expand Down