本文整理汇总了C#中TestScheduler.RunToMilliseconds方法的典型用法代码示例。如果您正苦于以下问题:C# TestScheduler.RunToMilliseconds方法的具体用法?C# TestScheduler.RunToMilliseconds怎么用?C# TestScheduler.RunToMilliseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.RunToMilliseconds方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsyncCommandSmokeTest
public void AsyncCommandSmokeTest()
{
var sched = new TestScheduler();
IObservable<int> async_data;
ReactiveAsyncCommand fixture;
using (TestUtils.WithTestScheduler(sched)) {
fixture = new ReactiveAsyncCommand(null, 1);
async_data = fixture
.Delay(TimeSpan.FromSeconds(5), RxApp.TaskpoolScheduler)
.Select(_ => 5)
.Do(_ => fixture.AsyncCompletedNotification.OnNext(new Unit()));
}
var inflight_results = new List<int>();
fixture.ItemsInflight.Subscribe(inflight_results.Add);
var output = new List<int>();
async_data.Subscribe(output.Add);
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(output);
}
示例2: StopwatchSchedulerShouldFailLongrunningTasks
public void StopwatchSchedulerShouldFailLongrunningTasks()
{
var sched = new TestScheduler();
var fixture = new StopwatchScheduler(TimeSpan.FromMilliseconds(500), null, sched);
fixture.Schedule(() => Console.WriteLine("Shouldn't fail"));
bool should_die = true;
try {
fixture.Schedule(() => Observable.Return(4).Delay(TimeSpan.FromMilliseconds(2000)));
} catch {
should_die = false;
}
sched.RunToMilliseconds(2500);
Assert.IsFalse(should_die);
}
示例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);
}
示例4: 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);
}
示例5: MultipleSubscribersShouldntDecrementRefcountBelowZero
public void MultipleSubscribersShouldntDecrementRefcountBelowZero()
{
var sched = new TestScheduler();
var fixture = new ReactiveAsyncCommand(null, 1, sched);
var results = new List<int>();
bool[] subscribers = new[] { false, false, false, false, false };
var output = fixture.RegisterAsyncObservable(_ =>
Observable.Return(5).Delay(TimeSpan.FromMilliseconds(5000), sched));
output.Subscribe(x => results.Add(x));
Enumerable.Range(0, 5).Run(x => output.Subscribe(_ => subscribers[x] = true));
Assert.IsTrue(fixture.CanExecute(null));
fixture.Execute(null);
sched.RunToMilliseconds(2000);
Assert.IsFalse(fixture.CanExecute(null));
sched.RunToMilliseconds(6000);
Assert.IsTrue(fixture.CanExecute(null));
Assert.IsTrue(results.Count == 1);
Assert.IsTrue(results[0] == 5);
Assert.IsTrue(subscribers.All(x => x == true));
}
示例6: MultipleSubscribesShouldntResultInMultipleNotifications
public void MultipleSubscribesShouldntResultInMultipleNotifications()
{
var input = new[] { 1, 2, 1, 2 };
var sched = new TestScheduler();
var fixture = new ReactiveCommand(null, sched);
var odd_list = new List<int>();
var even_list = new List<int>();
fixture.Where(x => ((int)x) % 2 != 0).Subscribe(x => odd_list.Add((int)x));
fixture.Where(x => ((int)x) % 2 == 0).Subscribe(x => even_list.Add((int)x));
input.Run(x => fixture.Execute(x));
sched.RunToMilliseconds(1000);
new[]{1,1}.AssertAreEqual(odd_list);
new[]{2,2}.AssertAreEqual(even_list);
}
示例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);
}
示例8: CreateCollectionWithTimer
public void CreateCollectionWithTimer()
{
var input = new[] {"Foo", "Bar", "Baz", "Bamf"};
var sched = new TestScheduler();
using (TestUtils.WithScheduler(sched)) {
ReactiveCollection<string> fixture;
fixture = input.ToObservable(sched).CreateCollection(TimeSpan.FromSeconds(0.5));
sched.RunToMilliseconds(1005);
fixture.AssertAreEqual(input.Take(2));
sched.RunToMilliseconds(1505);
fixture.AssertAreEqual(input.Take(3));
sched.RunToMilliseconds(10000);
fixture.AssertAreEqual(input);
}
}