当前位置: 首页>>代码示例>>C#>>正文


C# TestScheduler.With方法代码示例

本文整理汇总了C#中TestScheduler.With方法的典型用法代码示例。如果您正苦于以下问题:C# TestScheduler.With方法的具体用法?C# TestScheduler.With怎么用?C# TestScheduler.With使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestScheduler的用法示例。


在下文中一共展示了TestScheduler.With方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangesShouldPropagateThroughMultilevelCollections

        public void ChangesShouldPropagateThroughMultilevelCollections()
        {
            var sched = new TestScheduler();
            var input = sched.With(_ => new ModelTestFixture() {TestString = "Foo"});
            var coll = sched.With(_ => new SerializedCollection<ISerializableItem>(new[] {input}));
            var fixture = sched.With(_ =>
                new SerializedCollection<ISerializableList<ISerializableItem>>(new[] {(ISerializableList<ISerializableItem>)coll}));

            this.Log().DebugFormat("input = {0:X}, coll = {1:X}, fixture = {2:X}",
                input.GetHashCode(), coll.GetHashCode(), fixture.GetHashCode());

            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);

            this.Log().DebugFormat("inputChanging = {0}", inputChanging);
            this.Log().DebugFormat("inputChanged = {0}", inputChanged);
            this.Log().DebugFormat("collChanging = {0}", collChanging);
            this.Log().DebugFormat("collChanged = {0}", collChanged);
            this.Log().DebugFormat("fixtureChanging = {0}", fixtureChanging);
            this.Log().DebugFormat("fixtureChanged = {0}", fixtureChanged);

            Assert.IsTrue(inputChanging);
            Assert.IsTrue(inputChanged);
            Assert.IsTrue(collChanging);
            Assert.IsTrue(collChanged);
            Assert.IsTrue(fixtureChanging);
            Assert.IsTrue(fixtureChanged);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:38,代码来源:SerializedCollectionTest.cs

示例2: GuidsShouldBeUniqueForContent

        public void GuidsShouldBeUniqueForContent(string[] setters)
        {
            PexAssume.IsNotNull(setters);
            PexAssume.AreElementsNotNull(setters);

            var sched = new TestScheduler();
            var fixture = sched.With(_ => new ModelTestFixture());
            var output = new Dictionary<string, Guid>();

            setters.ToObservable(sched).Subscribe(x => {
                fixture.TestString = x;
                output[x] = fixture.ContentHash;
            });

            sched.Run();

            PexAssert.AreDistinctValues(output.Values.ToArray());
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:18,代码来源:ModelBaseTest.cs

示例3: ModelBaseShouldBeObservableAfterDeserialization

        public void ModelBaseShouldBeObservableAfterDeserialization()
        {
            var dse = new DictionaryStorageEngine();
            var sched = new TestScheduler();
            var input = sched.With(_ => new ModelTestFixture() {TestString = "Foo"});

            dse.Save(input);
            var fixture = dse.Load<ModelTestFixture>(input.ContentHash);

            string latest = null;
            var changed = fixture.Changed;
            this.Log().InfoFormat("Subscribing to Changed: 0x{0:X}", changed.GetHashCode());
            changed.Subscribe(Console.WriteLine);
            changed.Subscribe(x => latest = x.PropertyName);
            fixture.TestString = "Bar";

            sched.RunToMilliseconds(1000);

            Assert.AreEqual("TestString", latest);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:20,代码来源:ModelBaseTest.cs

示例4: ItemsChangedShouldFire

        public void ItemsChangedShouldFire(string[] setters)
        {
            PexAssume.IsNotNull(setters);
            PexAssume.AreElementsNotNull(setters);

            var sched = new TestScheduler();
            var output_changed = new List<object>();
            var output_changing = new List<object>();
            var fixture = sched.With(_ => new ModelTestFixture());

            fixture.Changing.Subscribe(output_changing.Add);
            fixture.Changed.Subscribe(output_changed.Add);

            setters.Run(x => fixture.TestString = x);

            sched.Run();

            PexAssert.AreEqual(setters.Distinct().Count(), output_changed.Count);
            PexAssert.AreEqual(setters.Distinct().Count(), output_changing.Count);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:20,代码来源:ModelBaseTest.cs

示例5: AddingItemsShouldChangeTheContentHash

        public void AddingItemsShouldChangeTheContentHash(string[] toAdd)
        {
            PexAssume.IsNotNull(toAdd);
            PexAssume.AreElementsNotNull(toAdd);

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

            toAdd.ToObservable(sched).Subscribe(x => fixture.Add(new ModelTestFixture() {TestString = x}));
            fixture.ItemChanged.Subscribe(_ => {
                hashes.Add(fixture.ContentHash);
                changeCount++;
            });

            sched.Run();

            PexAssert.AreDistinctValues(hashes.ToArray());
            PexAssert.AreEqual(toAdd.Length, changeCount);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:21,代码来源:SerializedCollectionTest.cs

示例6: CreateSyncPointSmokeTest

        public void CreateSyncPointSmokeTest()
        {
            var scheduler = new TestScheduler();
            var fixture = createFixture();

            scheduler.With(sched => {
                using (fixture)
                using (fixture.AsPrimaryEngine()) {
                    var input = new RootSerializationTestObject() { SubObject = new SubobjectTestObject() { SomeProperty = "Foo" } };

                    var syncPoint = fixture.CreateSyncPoint(input);

                    sched.AdvanceTo(sched.FromTimeSpan(TimeSpan.FromDays(1.0)));

                    Assert.Equal(3, fixture.GetObjectCount());
                    Assert.True(fixture.GetAllObjectHashes().Contains(input.ContentHash));
                    Assert.True(fixture.GetAllObjectHashes().Contains(input.SubObject.ContentHash));
                    Assert.True(fixture.GetAllObjectHashes().Contains(syncPoint.ContentHash));

                    Assert.Equal(1, fixture.GetOrderedRevisionList(typeof (RootSerializationTestObject)).Length);
                    Assert.Equal(0, fixture.GetOrderedRevisionList(typeof (RootSerializationTestObject), "WeirdQualifier").Length);

                    input.SomeInteger = 10;

                    syncPoint = fixture.CreateSyncPoint(input);

                    Assert.Equal(5, fixture.GetObjectCount());
                    Assert.True(fixture.GetAllObjectHashes().Contains(input.ContentHash));
                    Assert.True(fixture.GetAllObjectHashes().Contains(input.SubObject.ContentHash));
                    Assert.True(fixture.GetAllObjectHashes().Contains(syncPoint.ContentHash));

                    Assert.Equal(2, fixture.GetOrderedRevisionList(typeof (RootSerializationTestObject)).Length);
                    Assert.Equal(0, fixture.GetOrderedRevisionList(typeof (RootSerializationTestObject), "WeirdQualifier").Length);
                }

                return 0;
            });
        }
开发者ID:ruisilvestre,项目名称:ReactiveUI,代码行数:38,代码来源:IStorageEngineTest.cs

示例7: RegisterAsyncFunctionSmokeTest

        public void RegisterAsyncFunctionSmokeTest()
        {
            var sched = new TestScheduler();
            var fixture = sched.With(_ => new ReactiveAsyncCommand(null, 1));
            ReactiveCollection<int> results;

            using (TestUtils.WithTestScheduler(sched)) {
                results = fixture.RegisterAsyncObservable(_ =>
                    Observable.Return(5).Delay(TimeSpan.FromSeconds(5), sched)
                ).CreateCollection();
            }

            var inflight_results = sched.With(_ => fixture.ItemsInflight.CreateCollection());
            sched.RunToMilliseconds(10);
            Assert.IsTrue(fixture.CanExecute(null));

            fixture.Execute(null);
            sched.RunToMilliseconds(1005);
            Assert.IsFalse(fixture.CanExecute(null));

            sched.RunToMilliseconds(5005);
            Assert.IsTrue(fixture.CanExecute(null));

            new[] {0,1,0}.AssertAreEqual(inflight_results);
            new[] {5}.AssertAreEqual(results);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:26,代码来源:ReactiveCommandTest.cs

示例8: ExtendedStorageEngineGetRootObject

        public void ExtendedStorageEngineGetRootObject()
        {
            var scheduler = new TestScheduler();
            var fixture = createExtendedFixture();

            scheduler.With(sched => {
                using (fixture)
                using (fixture.AsPrimaryEngine()) {
                    var input = new RootSerializationTestObject() { SubObject = new SubobjectTestObject() { SomeProperty = "Foo" } };
                    var origHash = input.ContentHash;
                    var syncPoint = fixture.CreateSyncPoint(input, null, DateTimeOffset.Now);

                    // N.B. This doesn't appear to actually affect IScheduler.Now :-/
                    sched.AdvanceTo(sched.FromTimeSpan(TimeSpan.FromDays(1.0)));

                    Assert.Equal(input.ContentHash, fixture.GetLatestRootObject<RootSerializationTestObject>().ContentHash);
                    Assert.Equal(null, fixture.GetLatestRootObject<RootSerializationTestObject>("SomeWeirdQualifier"));
                    Assert.Equal(null, fixture.GetLatestRootObject<RootSerializationTestObject>(null, DateTimeOffset.Now - TimeSpan.FromHours(1.0)));

                    input.SomeInteger = 10;
                    syncPoint = fixture.CreateSyncPoint(input, null, DateTimeOffset.Now + TimeSpan.FromDays(1.0));
                    Assert.Equal(origHash, fixture.GetLatestRootObject<RootSerializationTestObject>(null, DateTimeOffset.Now + TimeSpan.FromSeconds(1.0)).ContentHash);
                }

                return 0;
            });
        }
开发者ID:ruisilvestre,项目名称:ReactiveUI,代码行数:27,代码来源:IStorageEngineTest.cs

示例9: ChangingASerializableItemShouldChangeTheContentHash

        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);

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

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

            sched.Run();

            Assert.AreNotEqual(hashBefore, fixture.ContentHash);
            Assert.IsFalse(shouldDie);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:22,代码来源:SerializedCollectionTest.cs

示例10: RemovingItemsShouldChangeTheContentHash

        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);

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

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

            var toRemove = itemsToRemove.Select(x => fixture[x]);
            toRemove.ToObservable(sched).Subscribe(x => fixture.Remove(x));

            sched.Run();

            PexAssert.AreDistinctValues(hashes.ToArray());
            PexAssert.AreEqual(itemsToRemove.Length, changeCount);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:27,代码来源:SerializedCollectionTest.cs


注:本文中的TestScheduler.With方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。