Esempio n. 1
0
        public void Count_Get()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Assert.Equal(Terraria.Main.maxProjectiles, projectileService.Count);
        }
Esempio n. 2
0
        public void Item_GetIndexOutOfRange_ThrowsIndexOutOfRangeException(int index)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Assert.Throws <IndexOutOfRangeException>(() => projectileService[index]);
        }
Esempio n. 3
0
        public void Item_GetMultipleTimes_ReturnsSameInstance()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            var projectile  = projectileService[0];
            var projectile2 = projectileService[0];

            Assert.Same(projectile, projectile2);
        }
Esempio n. 4
0
        public void Item_Get()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            var projectile = projectileService[1];

            Assert.Equal(1, projectile.Index);
            Assert.Same(Terraria.Main.projectile[1], ((OrionProjectile)projectile).Wrapped);
        }
Esempio n. 5
0
        public void GetEnumerator()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            var projectiles = projectileService.ToList();

            for (var i = 0; i < projectiles.Count; ++i)
            {
                Assert.Same(Terraria.Main.projectile[i], ((OrionProjectile)projectiles[i]).Wrapped);
            }
        }
Esempio n. 6
0
        public void ProjectileTick_EventCanceled()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <ProjectileTickEvent>(), log))
            .Callback <ProjectileTickEvent, ILogger>((evt, log) => evt.Cancel());

            Terraria.Main.projectile[0].Update(0);

            Mock.Get(events).VerifyAll();
        }
Esempio n. 7
0
        public void ProjectileTick_EventTriggered()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(
                       It.Is <ProjectileTickEvent>(
                           evt => ((OrionProjectile)evt.Projectile).Wrapped == Terraria.Main.projectile[0]),
                       log));

            Terraria.Main.projectile[0].Update(0);

            Mock.Get(events).VerifyAll();
        }
Esempio n. 8
0
        public void ProjectileDefaults_EventModified()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <ProjectileDefaultsEvent>(), log))
            .Callback <ProjectileDefaultsEvent, ILogger>((evt, log) => evt.Id = ProjectileId.WoodenArrow);

            Terraria.Main.projectile[0].SetDefaults((int)ProjectileId.CrystalBullet);

            Assert.Equal(ProjectileId.WoodenArrow, (ProjectileId)Terraria.Main.projectile[0].type);

            Mock.Get(events).VerifyAll();
        }
Esempio n. 9
0
        public void Spawn()
        {
            // Clear the projectile so that we know it's empty.
            Terraria.Main.projectile[0] = new Terraria.Projectile {
                whoAmI = 0
            };

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            var projectile = projectileService.Spawn(
                ProjectileId.CrystalBullet, Vector2f.Zero, Vector2f.Zero, 100, 0);

            Assert.Equal(Terraria.Main.projectile[0], ((OrionProjectile)projectile).Wrapped);
            Assert.Equal(ProjectileId.CrystalBullet, projectile.Id);
        }
Esempio n. 10
0
        public void ProjectileDefaults_EventTriggered()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(
                       It.Is <ProjectileDefaultsEvent>(
                           evt => ((OrionProjectile)evt.Projectile).Wrapped == Terraria.Main.projectile[0] &&
                           evt.Id == ProjectileId.CrystalBullet),
                       log));

            Terraria.Main.projectile[0].SetDefaults((int)ProjectileId.CrystalBullet);

            Assert.Equal(ProjectileId.CrystalBullet, (ProjectileId)Terraria.Main.projectile[0].type);

            Mock.Get(events).VerifyAll();
        }
Esempio n. 11
0
        public void ProjectileDefaults_EventCanceled()
        {
            // Clear the projectile so that we know it's empty.
            Terraria.Main.projectile[0] = new Terraria.Projectile {
                whoAmI = 0
            };

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var projectileService = new OrionProjectileService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <ProjectileDefaultsEvent>(), log))
            .Callback <ProjectileDefaultsEvent, ILogger>((evt, log) => evt.Cancel());

            Terraria.Main.projectile[0].SetDefaults((int)ProjectileId.CrystalBullet);

            Assert.Equal(ProjectileId.None, (ProjectileId)Terraria.Main.projectile[0].type);

            Mock.Get(events).VerifyAll();
        }