Beispiel #1
0
        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);
        }
Beispiel #2
0
        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"));
        }
Beispiel #3
0
        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.");
        }
Beispiel #4
0
        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));
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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>();
        }
Beispiel #10
0
 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);
             }
         }
     }
 }
Beispiel #11
0
        public static Stream GetDatafileStream(this string datafileName, BattleScribeVersion version = null)
        {
            var path = GetDatafilePath(datafileName, version);

            return(File.OpenRead(path));
        }
Beispiel #12
0
        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));
        }
Beispiel #13
0
        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));
        }