Esempio n. 1
0
        public void PackV0Test(int packed, int episode, int release)
        {
            var packer = new PackedId(release, episode);
            var boxed  = (object)packer;

            typeof(PackedId).GetField(nameof(packer.Version), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).SetValue(boxed, 0);
            packer = (PackedId)boxed;
            var actual = packer.Pack();

            Assert.AreEqual(packed, actual, "Wrongly packed");
        }
Esempio n. 2
0
        public void RoundRobinTest()
        {
            var rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                var source = rnd.Next(int.MinValue, int.MaxValue);
                var p1     = PackedId.Unpack(source);
                var p2     = new PackedId(p1.ReleaseId, p1.EpisodeId);
                if (p1.Version == 0)
                {
                    var boxed = (object)p2;
                    typeof(PackedId).GetField(nameof(p2.Version), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).SetValue(boxed, 0);
                    p2 = (PackedId)boxed;
                }
                Assert.AreEqual(source, p1.Pack(), "Round-robin 1st iteration didn't work for " + source);
                Assert.AreEqual(p1.Version, p2.Version, "Version wrong");
                Assert.AreEqual(p1.EpisodeId, p2.EpisodeId, "EpisodeId wrong");
                Assert.AreEqual(p1.ReleaseId, p2.ReleaseId, "ReleaseId wrong");
                Assert.AreEqual(source, p2.Pack(), "Round-robin 2rd iteration didn't work for " + source);
            }
        }