Ejemplo n.º 1
0
        public void ParseBulletXml_PopulateAllXmlRelatedFields()
        {
            XmlDocument document = new XmlDocument();

            document.Load(@"DataAccess\TestData\ValidBulletXml.xml");
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("ParseBulletPropertiesXml", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { document };

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

            bulletProperties = (Properties)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal(983, bulletProperties.Bullet.Speed);
            Assert.Equal(6.6, bulletProperties.Bullet.Lifetime);
            Assert.Equal(1, bulletProperties.Bullet.Amount);
            Assert.Equal(1, bulletProperties.Bullet.BarrelAmount);
            Assert.Equal(0, bulletProperties.Bullet.TimeDiff);
            Assert.Equal(0, bulletProperties.Bullet.Angle);
            Assert.Equal(1, bulletProperties.Bullet.MaxHits);
            Assert.Equal(0, bulletProperties.Bullet.Ricochet);
            Assert.Equal(0, bulletProperties.Bullet.Ricochet);
            Assert.Equal(0, bulletProperties.Bullet.Scale);
            Assert.Equal(0, bulletProperties.Bullet.Attach);
            Assert.Equal(5756, bulletProperties.Heat.Value);
            Assert.Equal(4, bulletProperties.Reload.Time);
            Assert.Equal(1841, bulletProperties.Damage.Value);
            Assert.Equal(0, bulletProperties.Damage.Repair);
        }
Ejemplo n.º 2
0
        public void GenerateBulletName_BulletHasVersion02()
        {
            BulletModel bullet = new BulletModel {
                Faction = FactionType.BUC, Grade = BulletGrade.mk1, Name = "Some Bullet Name", Size = BulletSize.s, Type = BulletType.laser, Version = 2
            };
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("GenerateBulletName", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bullet };

            // Method under test
            string bulletName = (string)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal("S BUC Laser Bullet Mk1 02", bulletName);
        }
Ejemplo n.º 3
0
        public void DetermineBulletWeaponType_IsPrimary()
        {
            const string  bulletFileName         = "bullet_arg_m_ion_01_mk1_macro.xml";
            List <string> bulletFileNameSubParts = bulletFileName.Split('_').ToList();

            bulletFileNameSubParts.Remove("bullet");
            bulletFileNameSubParts.Remove("macro.xml");
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("DetermineBulletWeaponType", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bulletFileNameSubParts };

            // Method under test
            BulletWeaponType weaponTypeResult = (BulletWeaponType)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal(BulletWeaponType.primary, weaponTypeResult);
        }
Ejemplo n.º 4
0
        public void ParseBulletSubstring_VersionFound()
        {
            const string bulletSubstring = "02";
            BulletModel  bullet          = new BulletModel();
            BulletGetter bulletGetter    = new BulletGetter("some folder");
            MethodInfo   methodInfo      = typeof(BulletGetter).GetMethod("ParseBulletSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bullet, bulletSubstring };

            // Method under test
            bullet = (BulletModel)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Null(bullet.Faction);
            Assert.Null(bullet.Size);
            Assert.Null(bullet.Type);
            Assert.Null(bullet.Grade);
            Assert.Equal(2, bullet.Version);
        }
Ejemplo n.º 5
0
        public void ParseBulletSubstring_VersionFound_AllOthersPreviouslyPopulated()
        {
            const string bulletSubstring = "01";
            BulletModel  bullet          = new BulletModel {
                Faction = FactionType.BUC, Grade = BulletGrade.mk3, Name = "Some Bullet Name", Size = BulletSize.xl, Type = BulletType.laser
            };
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("ParseBulletSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bullet, bulletSubstring };

            // Method under test
            bullet = (BulletModel)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal(FactionType.BUC, bullet.Faction);
            Assert.Equal(BulletSize.xl, bullet.Size);
            Assert.Equal(BulletType.laser, bullet.Type);
            Assert.Equal(BulletGrade.mk3, bullet.Grade);
            Assert.Equal(1, bullet.Version);
        }
Ejemplo n.º 6
0
        public void RemoveMultitermBulletFileNameParameters_HasMultitermParameters_SpacesuitLaser()
        {
            const string  bulletFileName         = "bullet_spacesuit_laser_02_mk1_macro.xml";
            List <string> bulletFileNameSubParts = bulletFileName.Split('_').ToList();

            bulletFileNameSubParts.Remove("bullet");
            bulletFileNameSubParts.Remove("macro.xml");
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("RemoveMultitermBulletFileNameParameters", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bulletFileNameSubParts };

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

            bulletFileNameSubPartsAfterMethodCall = (List <string>)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal(bulletFileNameSubParts.Count, bulletFileNameSubPartsAfterMethodCall.Count + 1);
            Assert.Equal("spacesuitlaser", bulletFileNameSubPartsAfterMethodCall[0]);
            Assert.Equal("02", bulletFileNameSubPartsAfterMethodCall[1]);
            Assert.Equal("mk1", bulletFileNameSubPartsAfterMethodCall[2]);
        }
Ejemplo n.º 7
0
        public void RemoveMultitermBulletFileNameParameters_HasNoMultitermParameters()
        {
            const string  bulletFileName         = "bullet_arg_turret_l_beam_01_mk1_macro.xml";
            List <string> bulletFileNameSubParts = bulletFileName.Split('_').ToList();

            bulletFileNameSubParts.Remove("bullet");
            bulletFileNameSubParts.Remove("macro.xml");
            BulletGetter bulletGetter = new BulletGetter("some folder");
            MethodInfo   methodInfo   = typeof(BulletGetter).GetMethod("RemoveMultitermBulletFileNameParameters", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bulletFileNameSubParts };

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

            bulletFileNameSubPartsAfterMethodCall = (List <string>)methodInfo.Invoke(bulletGetter, parameters);

            Assert.Equal(bulletFileNameSubParts.Count, bulletFileNameSubPartsAfterMethodCall.Count);
            for (int i = 0; i < bulletFileNameSubParts.Count; i++)
            {
                Assert.Equal(bulletFileNameSubParts[i], bulletFileNameSubPartsAfterMethodCall[i]);
            }
        }
Ejemplo n.º 8
0
        public void ParseBulletSubstring_AllParsingFails()
        {
            const string bulletSubstring = "invalid string to parse";
            BulletModel  bullet          = new BulletModel();
            BulletGetter bulletGetter    = new BulletGetter("some folder");
            MethodInfo   methodInfo      = typeof(BulletGetter).GetMethod("ParseBulletSubstring", BindingFlags.NonPublic | BindingFlags.Instance);

            object[] parameters = { bullet, bulletSubstring };


            // Method under test
            void Action() => bullet = (BulletModel)methodInfo.Invoke(bulletGetter, parameters);

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

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

            Assert.Null(bullet.Faction);
            Assert.Null(bullet.Size);
            Assert.Null(bullet.Type);
            Assert.Null(bullet.Grade);
            Assert.Null(bullet.Version);
        }
Ejemplo n.º 9
0
        public BulletsViewModel()
        {
            const string engineFolderPath = @"C:\Program Files (x86)\Steam\steamapps\common\X4 Foundations\unpacked\assets\fx\weaponFx\macros";

            Bullets = new BulletGetter(engineFolderPath).PopulateBullets();
        }