public void Create_throws_on_negative_numbers(int major, int minor, string argumentName) { Action act = () => BattleScribeVersion.Create(major, minor); act.Should().Throw <ArgumentOutOfRangeException>() .And.ParamName.Should().Be(argumentName); }
public static string GetDatafilePath(this string datafileName, BattleScribeVersion version = null) { // null version is latest: var versionResolved = version ?? BattleScribeVersion.WellKnownVersions.Last(); var versionText = versionResolved.FilepathString; return(Path.Combine(InputDir, "v" + versionText, datafileName + ".xml")); }
public void Equals_returns_true_on_same_object() { var v1 = BattleScribeVersion.Create(1, 0, "a"); var result = v1.Equals(v1); result.Should().BeTrue("it's the same object."); }
public static VersionedElementInfo ReadRootElementInfo(XmlReader reader) { reader.MoveToContent(); var rootElement = reader.LocalName.ParseRootElement(); var versionText = reader.GetAttribute(BattleScribeVersionAttributeName); var version = BattleScribeVersion.Parse(versionText); return(new VersionedElementInfo(rootElement, version)); }
private static BattleScribeVersion GetVersion(XmlReader reader) { var versionText = XDocument.Load(reader) .Root.Attribute(DataVersionManagement.BattleScribeVersionAttributeName) .Value; return(BattleScribeVersion.Parse(versionText)); }
public void Compare_returns_expected_result(string text1, string text2, int expectedResult) { var v1 = text1 is null ? null : BattleScribeVersion.Parse(text1); var v2 = text2 is null ? null : BattleScribeVersion.Parse(text2); var result = BattleScribeVersion.Compare(v1, v2); result.Should().Be(expectedResult); }
public void Equals_returns_true_on_equivalent_objects() { var v1 = BattleScribeVersion.Create(1, 0, "a"); var v2 = BattleScribeVersion.Create(1, 0, "a"); var result = v1.Equals(v2); result.Should().BeTrue("it's the same version."); }
public void ReadRootElementInfo_succeeds(RootElement rootElement, string versionText) { var elementInfo = new VersionedElementInfo( rootElement, BattleScribeVersion.Parse(versionText)); using var stream = CreateEmptyElementStream(elementInfo); var result = DataVersionManagement.ReadRootElementInfo(stream); result.Should().Be(elementInfo); }
public void DeserializeSourceNodeAuto_with_Always_or_OnFailure_mode_opens_anything( BattleScribeVersion version, MigrationMode mode, string datafile) { using var stream = datafile.GetDatafileStream(version); var result = stream.DeserializeSourceNodeAuto(mode); result .Should().NotBeNull() .And.BeAssignableTo <IRootNode>(); }
private void CheckBattleScribeVersionCompatibility(IWorkspace workspace) { foreach (var file in workspace.Datafiles) { var node = file.GetData(); if (node is IRootNode rootNode && !string.IsNullOrWhiteSpace(rootNode.BattleScribeVersion)) { var version = BattleScribeVersion.Parse(rootNode.BattleScribeVersion); var maxSupportedVersion = node.Kind.ToRootElement().Info().CurrentVersion; if (version > maxSupportedVersion) { Log.Warning( "Processing {File} which has BattleScribeVersion higher than supported" + " ({NodeVersion} > {SupportedVersion}).", file, version, maxSupportedVersion); } } } }
public static Stream GetDatafileStream(this string datafileName, BattleScribeVersion version = null) { var path = GetDatafilePath(datafileName, version); return(File.OpenRead(path)); }
public void Parse_succeeds_on_valid_strings(string text, int major, int minor, string suffix = null) { var result = BattleScribeVersion.Parse(text); result.Should().Be(BattleScribeVersion.Create(major, minor, suffix)); }
public void Parse_throws_on_invalid_strings(string text) { Action act = () => BattleScribeVersion.Parse(text); act.Should().Throw <FormatException>("parsed text is invalid."); }
private static VersionedElementInfo CreateVersionedInfo(RootElement root, string versionText) { var version = versionText is null ? null : BattleScribeVersion.Parse(versionText); return(new VersionedElementInfo(root, version)); }