コード例 #1
0
        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);
            });
        }
コード例 #2
0
        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);
            });
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
0
 protected override IEnumerable <VisibilityModifierType> ResolveCore(SerializedCollection <Domain.Enums.VisibilityModifierType> source)
 {
     foreach (var visibilityModifier in source)
     {
         yield return(Mapper.Map <VisibilityModifierType>(visibilityModifier));
     }
 }
コード例 #5
0
        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);
            });
        }
コード例 #6
0
        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);
            });
        }
コード例 #7
0
        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);
            });
        }
コード例 #8
0
        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));

            this.Log().Info(json);

            // TODO: Finish this test
        }
コード例 #9
0
 protected override IEnumerable <VictoryConditionType> ResolveCore(SerializedCollection <Domain.Enums.VictoryConditionType> source)
 {
     foreach (var victoryCondition in source)
     {
         yield return(Mapper.Map <VictoryConditionType>(victoryCondition));
     }
 }
コード例 #10
0
 XElement ToXml(SerializedCollection instance)
 {
     return(new XElement(Collection,
                         ToXmlType(instance),
                         new XElement(Items, instance.Items
                                      .Select(ToXml)
                                      .ToArray())));
 }
コード例 #11
0
ファイル: Stringifier.cs プロジェクト: ylyking/Autostub
        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();
        }
コード例 #12
0
        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));

            // TODO: Finish this test
        }
コード例 #13
0
        SerializedCollection GetCollection(XElement src)
        {
            var type  = FromXmlType(src);
            var items = src.Element(Items).Elements()
                        .Select(ToObject)
                        .ToList();

            var result = new SerializedCollection()
            {
                //Name = name,
                Type = type
            };

            result.Items.AddRange(items);
            return(result);
        }
コード例 #14
0
        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
        }
コード例 #15
0
        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));

            // TODO: Finish this test
        }
コード例 #16
0
        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);
            });
        }
コード例 #17
0
        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
        }
コード例 #18
0
        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
        }
コード例 #19
0
        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);
            });
        }
コード例 #20
0
 public RoutingState(string autoSaveContract)
 {
     _NavigationStack  = new SerializedCollection <IRoutableViewModel>();
     _AutoSaveContract = autoSaveContract;
     setupRx();
 }
コード例 #21
0
 protected override IEnumerable <T> ResolveCore(SerializedCollection <T> source)
 {
     return(source);
 }