public void AddingItemsShouldChangeTheContentHash(string[] toAdd)
        {
            PexAssume.IsNotNull(toAdd);
            PexAssume.AreElementsNotNull(toAdd);
            PexAssume.IsTrue(toAdd.Length > 0);

            (new TestScheduler()).With(sched => {
                var fixture = new SerializedCollection<ModelTestFixture>();
                var hashes = new List<Guid>();
                int changeCount = 0;

                fixture.Changed.Subscribe(_ => {
                    hashes.Add(fixture.ContentHash);
                    changeCount++;
                });

                foreach (var v in toAdd) {
                    fixture.Add(new ModelTestFixture() {TestString = v});
                    sched.Start();
                }

                PexAssert.AreDistinctValues(hashes.ToArray());
                PexAssert.AreEqual(toAdd.Length, fixture.Count);
                PexAssert.AreEqual(toAdd.Uniq().Count(), changeCount);
            });
        }
        public void ChangesShouldPropagateThroughMultilevelCollections()
        {
            (new TestScheduler()).With(sched => {
                var input = new ModelTestFixture() {TestString = "Foo"};
                var coll = new SerializedCollection<ISerializableItem>(new[] {input});
                var fixture =  new SerializedCollection<ISerializableList<ISerializableItem>>(new[] {(ISerializableList<ISerializableItem>)coll});

                bool inputChanging = false; bool inputChanged = false;
                bool collChanging = false; bool collChanged = false;
                bool fixtureChanging = false; bool fixtureChanged = false;
                input.Changing.Subscribe(_ => inputChanging = true);
                input.Changed.Subscribe(_ => inputChanged = true);
                coll.ItemChanging.Subscribe(_ => collChanging = true);
                coll.ItemChanging.Subscribe(_ => collChanged = true);
                fixture.ItemChanging.Subscribe(_ => fixtureChanging = true);
                fixture.ItemChanged.Subscribe(_ => fixtureChanged = true);

                input.TestString = "Bar";
                sched.RunToMilliseconds(1000);

                Assert.True(inputChanging);
                Assert.True(inputChanged);
                Assert.True(collChanging);
                Assert.True(collChanged);
                Assert.True(fixtureChanging);
                Assert.True(fixtureChanged);
            });
        }
Exemplo n.º 3
0
        static string Stringify(SerializedCollection instance, string indent, bool skipFirst)
        {
            var builder = new StringBuilder();
            builder.AppendFormat("{0}{1}{2}", NameString(instance, indent, skipFirst), TypeString(instance), Environment.NewLine);
            builder.AppendLine(indent + "{");
            foreach (var item in instance.Items)
            {
                if (item is SerializedAtom)
                    builder.AppendLine(Stringify(item as SerializedAtom, indent + "  "));
                else
                    builder.Append(Stringify(item, indent + "  "));
            }
            builder.AppendLine(indent + "}");

            return builder.ToString();
        }
        public void ItemsWithSerializedListsShouldOnlyHaveTheHashOfTheList()
        {
            var engine = new NullStorageEngine();
            var list = new SerializedCollection<ISerializableItem>(new ISerializableItem[] {
                new RootSerializationTestObject() {SubObject = new SubobjectTestObject() {SomeProperty = "Foo"}},
                new SubobjectTestObject() {SomeProperty = "Foo"},
            });
            var input = new RootObjectWithAListTestObject() {
                SomeList = list,
                RootObject = new RootSerializationTestObject() {SubObject = new SubobjectTestObject {SomeProperty = "Foo"}},
            };

            var serializer = createFixture();

            string json = serializer.SerializedDataToString(serializer.Serialize(input));

            // TODO: Finish this test
        }
        public void ChangingASerializableItemShouldChangeTheContentHash(string[] items, int toChange, string newValue)
        {
            PexAssume.IsNotNullOrEmpty(items);
            PexAssume.TrueForAll(items, x => x != null);
            PexAssume.AreDistinctReferences(items);
            PexAssume.IsTrue(toChange >= 0 && toChange < items.Length);

            (new TestScheduler()).With(sched => {

                var fixture = new SerializedCollection<ModelTestFixture>(
                    items.Select(x => new ModelTestFixture() {TestString = x}));
                bool shouldDie = true;
                var hashBefore = fixture.ContentHash;
                PexAssume.AreNotEqual(newValue, fixture[toChange].TestString);

                fixture.Changed.Subscribe(_ => shouldDie = false);
                Observable.Return(newValue, sched).Subscribe(x => fixture[toChange].TestString = x);

                sched.Start();

                PexAssert.AreNotEqual(hashBefore, fixture.ContentHash);
                PexAssert.IsFalse(shouldDie);
            });
        }
        public void RemovingItemsShouldChangeTheContentHash(string[] initialContents, int[] itemsToRemove)
        {
            PexAssume.IsNotNullOrEmpty(initialContents);
            PexAssume.IsNotNullOrEmpty(itemsToRemove);
            PexAssume.AreDistinctValues(initialContents);
            PexAssume.AreDistinctValues(itemsToRemove);
            PexAssume.TrueForAll(itemsToRemove, x => x < initialContents.Length && x > 0);

            (new TestScheduler()).With(sched => {
                var fixture = new SerializedCollection<ModelTestFixture>(initialContents.Select(x => new ModelTestFixture() { TestString = x }));
                var hashes = new List<Guid>();
                int changeCount = 0;

                fixture.Changed.Subscribe(_ => {
                    changeCount++;
                    hashes.Add(fixture.ContentHash);
                });

                var toRemove = itemsToRemove.Select(x => fixture[x]);
                foreach(var v in toRemove) {
                    fixture.Remove(v);
                }

                sched.Start();

                PexAssert.AreDistinctValues(hashes.ToArray());
                PexAssert.AreEqual(itemsToRemove.Length, changeCount);
            });
        }
        public void SerializedListShouldSerializeSubitemsOfEachListItem()
        {
            var engine = new NullStorageEngine();
            var input = new SerializedCollection<ISerializableItem>(new ISerializableItem[] {
                new RootSerializationTestObject() {SubObject = new SubobjectTestObject() {SomeProperty = "Foo"}},
                new SubobjectTestObject() {SomeProperty = "Foo"},
            });
            var serializer = createFixture();

            string json = serializer.SerializedDataToString(serializer.Serialize(input));
            this.Log().Info(json);

            // TODO: Finish this test
        }
        public void SerializedListSmokeTest()
        {
            var engine = new NullStorageEngine();
            var input = new SerializedCollection<SubobjectTestObject>(new[] {
                new SubobjectTestObject() {SomeProperty = "Foo"},
            });

            var serializer = createFixture();

            string json = serializer.SerializedDataToString(serializer.Serialize(input));
            this.Log().Info(json);

            // TODO: Finish this test
        }