Example #1
0
        public void basic_add_package()
        {
            PackageInfo pInfo0 = PLevel0V1[0];
            PackageInfo pInfo1 = PLevel0V1[1];
            PackageInfo pInfo2 = PLevel0V1[2];

            var db = new PackageDB();

            db.Instances.Should().BeEmpty();
            db.GetInstances(T0).Should().BeEmpty();

            db = db.Add(TestHelper.Monitor, pInfo0);
            db.Add(TestHelper.Monitor, pInfo0).Should().BeSameAs(db);
            db.Instances.Should().HaveCount(1);
            var p0 = db.Instances[0];

            db.Find(pInfo0.Key).Should().BeSameAs(p0);
            db.Find(pInfo1.Key).Should().BeNull();
            db.Find(pInfo2.Key).Should().BeNull();
            db.GetInstances(T0).SequenceEqual(new[] { p0 }).Should().BeTrue();

            db = db.Add(TestHelper.Monitor, pInfo2);
            db.Instances.Should().HaveCount(2);
            var p2 = db.Instances[1];

            db.Find(pInfo0.Key).Should().BeSameAs(p0);
            db.Find(pInfo1.Key).Should().BeNull();
            db.Find(pInfo2.Key).Should().BeSameAs(p2);
            db.GetInstances(T0).SequenceEqual(new[] { p0, p2 }).Should().BeTrue();

            db = db.Add(TestHelper.Monitor, pInfo1);
            db.Instances.Should().HaveCount(3);
            var p1 = db.Instances[1];

            db.Find(pInfo0.Key).Should().BeSameAs(p0);
            db.Find(pInfo1.Key).Should().BeSameAs(p1);
            db.Find(pInfo2.Key).Should().BeSameAs(p2);
            db.GetInstances(T0).SequenceEqual(new[] { p0, p1, p2 }).Should().BeTrue();

            db.GetInstances(T1).Should().BeEmpty();

            db.FindFeed("T0:F0").GetInstances(T0).SequenceEqual(db.GetInstances(T0)).Should().BeTrue();
            db.FindFeed("T0:F1").Should().BeNull();
        }