예제 #1
0
        public void ParseEngineXml_PopulateAllXmlRelatedFields()
        {
            XmlDocument document = new XmlDocument();

            document.Load(@"DataAccess\TestData\ValidEngineXml.xml");
            EngineGetter engineGetter = new EngineGetter("some folder");
            MethodInfo   methodInfo   = typeof(EngineGetter).GetMethod("ParseEnginePropertiesXml", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { document };

            // Method under test
            Properties engineProperties = new Properties();

            engineProperties = (Properties)methodInfo.Invoke(engineGetter, parameters);

            Assert.Equal(29, engineProperties.Boost.Duration);
            Assert.Equal(2, engineProperties.Boost.Thrust);
            Assert.Equal(10, engineProperties.Boost.Attack);
            Assert.Equal(1, engineProperties.Boost.Release);
            Assert.Equal(20, engineProperties.Travel.Charge);
            Assert.Equal(31, engineProperties.Travel.Thrust);
            Assert.Equal(75, engineProperties.Travel.Attack);
            Assert.Equal(22.5, engineProperties.Travel.Release);
            Assert.Equal(4206, engineProperties.Thrust.Forward);
            Assert.Equal(4627, engineProperties.Thrust.Reverse);
            Assert.Equal(4033, engineProperties.Hull.Max);
            Assert.Equal(0.3, engineProperties.Hull.Threshold);
        }
예제 #2
0
        public void PopulateEngine_AllFieldsAndPropertiesPopulated()
        {
            string engineFilePath = $@"{Environment.CurrentDirectory}\DataAccess\TestData\engine_arg_m_allround_01_mk1_macro.xml";

            EngineGetter engineGetter = new EngineGetter("some folder");
            EngineModel  engine       = engineGetter.PopulateEngine(engineFilePath);

            Assert.Equal(FactionType.ARG, engine.Faction);
            Assert.Equal(EngineSize.m, engine.Size);
            Assert.Equal(EngineType.allround, engine.Type);
            Assert.Equal(1, engine.Version);
            Assert.Equal(EngineGrade.mk1, engine.Grade);

            Assert.Equal(7, engine.Properties.Boost.Duration);
            Assert.Equal(8, engine.Properties.Boost.Thrust);
            Assert.Equal(0.25, engine.Properties.Boost.Attack);
            Assert.Equal(1, engine.Properties.Boost.Release);

            Assert.Equal(1, engine.Properties.Travel.Charge);
            Assert.Equal(9, engine.Properties.Travel.Thrust);
            Assert.Equal(30, engine.Properties.Travel.Attack);
            Assert.Equal(20, engine.Properties.Travel.Release);

            Assert.Equal(1002, engine.Properties.Thrust.Forward);
            Assert.Equal(952, engine.Properties.Thrust.Reverse);

            Assert.Equal(1, engine.Properties.Hull.Integrated);

            Assert.Equal("M ARG Allround Engine Mk1", engine.Name);
        }
예제 #3
0
        public void GenerateEngineName_EngineHasVersion02()
        {
            EngineModel engine = new EngineModel {
                Faction = FactionType.BUC, Grade = EngineGrade.mk3, Name = "Some Engine Name", Size = EngineSize.xl, Type = EngineType.combat, Version = 2
            };
            EngineGetter engineGetter = new EngineGetter("some folder");
            MethodInfo   methodInfo   = typeof(EngineGetter).GetMethod("GenerateEngineName", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engine };

            // Method under test
            string engineName = (string)methodInfo.Invoke(engineGetter, parameters);

            Assert.Equal("XL BUC Combat Engine Mk3 02", engineName);
        }
예제 #4
0
        public void ParseEngineSubstring_VersionFound()
        {
            const string engineSubstring = "02";
            EngineModel  engine          = new EngineModel();
            EngineGetter engineGetter    = new EngineGetter("some folder");
            MethodInfo   methodInfo      = typeof(EngineGetter).GetMethod("ParseEngineSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engine, engineSubstring };

            // Method under test
            engine = (EngineModel)methodInfo.Invoke(engineGetter, parameters);

            Assert.Null(engine.Faction);
            Assert.Null(engine.Size);
            Assert.Null(engine.Type);
            Assert.Null(engine.Grade);
            Assert.Equal(2, engine.Version);
        }
예제 #5
0
        public void ParseEngineSubstring_VersionFound_AllOthersPreviouslyPopulated()
        {
            const string engineSubstring = "01";
            EngineModel  engine          = new EngineModel {
                Faction = FactionType.BUC, Grade = EngineGrade.mk3, Name = "Some Engine Name", Size = EngineSize.xl, Type = EngineType.combat
            };
            EngineGetter engineGetter = new EngineGetter("some folder");
            MethodInfo   methodInfo   = typeof(EngineGetter).GetMethod("ParseEngineSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engine, engineSubstring };

            // Method under test
            engine = (EngineModel)methodInfo.Invoke(engineGetter, parameters);

            Assert.Equal(FactionType.BUC, engine.Faction);
            Assert.Equal(EngineSize.xl, engine.Size);
            Assert.Equal(EngineType.combat, engine.Type);
            Assert.Equal(EngineGrade.mk3, engine.Grade);
            Assert.Equal(1, engine.Version);
        }
예제 #6
0
        public void RemoveMultitermEngineFileNameParameters_HasMultitermParameters_MissileDumbfire()
        {
            const string  engineFileName         = "engine_missile_dumbfire_mk1_macro.xml";
            List <string> engineFileNameSubParts = engineFileName.Split('_').ToList();

            engineFileNameSubParts.Remove("engine");
            engineFileNameSubParts.Remove("macro.xml");
            EngineGetter engineGetter = new EngineGetter("some folder");
            MethodInfo   methodInfo   = typeof(EngineGetter).GetMethod("RemoveMultitermEngineFileNameParameters", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engineFileNameSubParts };

            // Method under test
            List <string> engineFileNameSubPartsAfterMethodCall = new List <string>();

            engineFileNameSubPartsAfterMethodCall = (List <string>)methodInfo.Invoke(engineGetter, parameters);

            Assert.Equal(engineFileNameSubParts.Count, engineFileNameSubPartsAfterMethodCall.Count + 1);
            Assert.Equal("MissileDumbfire", engineFileNameSubPartsAfterMethodCall[0]);
            Assert.Equal("mk1", engineFileNameSubPartsAfterMethodCall[1]);
        }
예제 #7
0
        public void RemoveMultitermEngineFileNameParameters_HasNoMultitermParameters()
        {
            const string  engineFileName         = "engine_arg_m_travel_01_mk3_macro.xml";
            List <string> engineFileNameSubParts = engineFileName.Split('_').ToList();

            engineFileNameSubParts.Remove("engine");
            engineFileNameSubParts.Remove("macro.xml");
            EngineGetter engineGetter = new EngineGetter("some folder");
            MethodInfo   methodInfo   = typeof(EngineGetter).GetMethod("RemoveMultitermEngineFileNameParameters", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engineFileNameSubParts };

            // Method under test
            List <string> engineFileNameSubPartsAfterMethodCall = new List <string>();

            engineFileNameSubPartsAfterMethodCall = (List <string>)methodInfo.Invoke(engineGetter, parameters);

            Assert.Equal(engineFileNameSubParts.Count, engineFileNameSubPartsAfterMethodCall.Count);
            for (int i = 0; i < engineFileNameSubParts.Count; i++)
            {
                Assert.Equal(engineFileNameSubParts[i], engineFileNameSubPartsAfterMethodCall[i]);
            }
        }
예제 #8
0
        public void ParseEngineSubstring_AllParsingFails()
        {
            const string engineSubstring = "invalid string to parse";
            EngineModel  engine          = new EngineModel();
            EngineGetter engineGetter    = new EngineGetter("some folder");
            MethodInfo   methodInfo      = typeof(EngineGetter).GetMethod("ParseEngineSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { engine, engineSubstring };


            // Method under test
            void Action() => engine = (EngineModel)methodInfo.Invoke(engineGetter, parameters);

            Exception exception = Assert.Throws <TargetInvocationException>(Action);

            Assert.Equal($"Failed to parse engine substring \"{engineSubstring}\"", exception.InnerException.Message);

            Assert.Null(engine.Faction);
            Assert.Null(engine.Size);
            Assert.Null(engine.Type);
            Assert.Null(engine.Grade);
            Assert.Null(engine.Version);
        }
예제 #9
0
        public EnginesViewModel()
        {
            const string engineFolderPath = @"C:\Program Files (x86)\Steam\steamapps\common\X4 Foundations\unpacked\assets\props\Engines\macros";

            Engines = new EngineGetter(engineFolderPath).PopulateEngines();
        }