本文整理汇总了C#中TestScheduler.AdvanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# TestScheduler.AdvanceTo方法的具体用法?C# TestScheduler.AdvanceTo怎么用?C# TestScheduler.AdvanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.AdvanceTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_Path_Has_Null_Intermediary_Node_Then_Propagates_ProvertyValueChanged_With_HasValue_False
public void When_Path_Has_Null_Intermediary_Node_Then_Propagates_ProvertyValueChanged_With_HasValue_False()
{
// Arrange
var childOne = new TestObservableObject {Age = 5};
var childTwo = new TestObservableObject {Age = 17};
var obj = new TestObservableObject {ObservableChild = childOne};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
var expected = new[]
{
OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", childOne.Age)),
OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", 20)),
OnNext(100, PropertyValueChanged.CreateWithoutValue<TestObservableObject, int>(null, "Age")),
OnNext(300, PropertyValueChanged.CreateWithValue(childTwo, "Age", childTwo.Age)),
};
var sut = obj.When(x => x.ObservableChild.Age);
// Act
sut.Subscribe(observer);
obj.ObservableChild.Age = 20;
scheduler.AdvanceTo(100);
obj.ObservableChild = null;
scheduler.AdvanceTo(300);
obj.ObservableChild = childTwo;
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例2: When_Path_Has_Null_Intermediary_Node_Then_Skips_When_Invalid_Path
public void When_Path_Has_Null_Intermediary_Node_Then_Skips_When_Invalid_Path()
{
// Arrange
var childOne = new TestObservableObject {Age = 5};
var childTwo = new TestObservableObject {Age = 17};
var obj = new TestObservableObject {ObservableChild = childOne};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<int>();
var expected = new[]
{
OnNext(000, childOne.Age),
OnNext(000, 20),
OnNext(300, childTwo.Age),
};
var sut = obj.WhenValue(x => x.ObservableChild.Age);
// Act
sut.Subscribe(observer);
obj.ObservableChild.Age = 20;
scheduler.AdvanceTo(100);
obj.ObservableChild = null;
scheduler.AdvanceTo(300);
obj.ObservableChild = childTwo;
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例3: When_Subscribed_Then_OnNext_Changes
public void When_Subscribed_Then_OnNext_Changes()
{
// Arrange
var obj = new TestObservableObject {ObservableChild = new TestObservableObject {Age = 3}};
var replacementChild = new TestObservableObject {Age = 5};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<TestObservableObject>();
var expected = new[]
{
OnNext(000, obj.ObservableChild),
OnNext(010, replacementChild),
OnNext(010, replacementChild),
OnNext(020, replacementChild),
};
var sut = obj.WhenAny(x => x.ObservableChild).ForProperty<TestObservableObject>("Age", "Name");
// Act
sut.Subscribe(observer);
scheduler.AdvanceTo(10);
obj.ObservableChild = replacementChild;
obj.ObservableChild.Age = 17;
scheduler.AdvanceTo(20);
obj.ObservableChild.Name = "Billy";
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例4: ShouldReturnValueAfterTime
public void ShouldReturnValueAfterTime()
{
var expected = "FDA";
var scheduler = new TestScheduler();
var obs = Typing(expected, 5, scheduler);
string result = null;
obs.Subscribe(x => result = x);
scheduler.AdvanceTo(TimeSpan.FromSeconds(3).Ticks);
Assert.Equal(null, result);
scheduler.AdvanceTo(TimeSpan.FromSeconds(6).Ticks);
Assert.Equal(expected, result);
}
示例5: TimerTestStart2
public void TimerTestStart2()
{
var testScheduler = new TestScheduler();
var recorder = testScheduler.CreateObserver<long>();
var timer = new ReactiveTimer(TimeSpan.FromSeconds(1), testScheduler);
timer.Subscribe(recorder);
timer.Start();
testScheduler.AdvanceTo(TimeSpan.FromSeconds(3).Ticks + 1);
recorder.Messages.Is(
OnNext(TimeSpan.FromSeconds(0).Ticks + 1, 0L),
OnNext(TimeSpan.FromSeconds(1).Ticks + 1, 1L),
OnNext(TimeSpan.FromSeconds(2).Ticks + 1, 2L),
OnNext(TimeSpan.FromSeconds(3).Ticks + 1, 3L));
timer.Stop();
recorder.Messages.Clear();
testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);
recorder.Messages.Count.Is(0);
}
示例6: TimeSource101
public void TimeSource101()
{
TestScheduler scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(s_testData);
var timeSource = new TimeSource<long>(xs, x => new DateTimeOffset(x, TimeSpan.Zero));
timeSource.StartTime = new DateTimeOffset(101, TimeSpan.Zero);
var counts = from window in timeSource.Window(TimeSpan.FromTicks(5), timeSource.Scheduler)
from Count in window.Count()
select Count;
var list = new List<Timestamped<int>>();
counts
.Timestamp(timeSource.Scheduler)
.Subscribe(ts => list.Add(ts));
timeSource.Connect();
scheduler.AdvanceTo(120);
Assert.AreEqual(3, list.Count);
list.AssertEqual(
Result(106, 2),
Result(111, 3),
Result(115, 1));
}
示例7: ScheduleTask_Should_Call_Sample_On_Scheduler
public void ScheduleTask_Should_Call_Sample_On_Scheduler()
{
// Arrange
const int count = 5;
var scheduler = new TestScheduler();
var settings = new TaskSchedulerSettings
{
RequestDelay = TimeSpan.FromMilliseconds(250)
};
ITaskScheduler taskScheduler = new DelayTaskScheduler(settings, scheduler);
// Act
var tasks = Enumerable.Range(0, count + 1)
.Select(i => Task.Run(() => Task.FromResult(i)))
.Select(t => taskScheduler.ScheduleTask(() => t))
.ToArray();
scheduler.AdvanceTo(settings.RequestDelay.Ticks * count);
// Assert
tasks.Count(t => t.IsCompleted).Should().Be(count);
taskScheduler.Dispose();
}
示例8: SelectDisposableShouldWork
public void SelectDisposableShouldWork()
{
var scheduler = new TestScheduler();
var disposables = new List<BooleanDisposable>();
var list = new CompositeDisposable();
scheduler.CreateColdObservable(
new Recorded<Notification<long>>(100, Notification.CreateOnNext(0L)),
new Recorded<Notification<long>>(200, Notification.CreateOnNext(1L)),
new Recorded<Notification<long>>(300, Notification.CreateOnNext(2L)),
new Recorded<Notification<long>>(400, Notification.CreateOnNext(3L)),
new Recorded<Notification<long>>(400, Notification.CreateOnCompleted<long>())
)
.SelectDisposable(list, i => {
var d = new BooleanDisposable();
disposables.Add(d);
return d;
}, (i, _) => i)
.Subscribe()
.DisposeWith(list);
scheduler.AdvanceTo(300);
disposables.Count.Should().Be(3);
disposables.Select(d => d.IsDisposed).Should().NotContain(true);
list.Dispose();
disposables.Select(d => d.IsDisposed).Should().NotContain(false);
}
示例9: SetUp
public void SetUp()
{
testScheduler = new TestScheduler();
testScheduler.AdvanceTo(DateTimeOffset.UtcNow.Ticks);
nodes = TestNode.CreateCluster(scheduler: testScheduler);
nodes.Start();
leader = nodes.WaitForLeader(testScheduler).Result;
}
示例10: Clock
public void Clock()
{
var scheduler = new TestScheduler ();
Assert.AreEqual (0, scheduler.Clock, "#1"); // default
scheduler.AdvanceBy (TimeSpan.FromDays (1).Ticks);
Assert.AreEqual (TimeSpan.FromDays (1).Ticks, scheduler.Clock, "#2");
var dt = new DateTimeOffset (2012, 1, 1, 0, 0, 0, TimeSpan.Zero);
scheduler.AdvanceTo (dt.Ticks);
Assert.AreEqual (dt, new DateTimeOffset (scheduler.Clock, TimeSpan.Zero), "#3");
}
示例11: elections_are_ran_shortly_after_node_startup
public void elections_are_ran_shortly_after_node_startup()
{
var testScheduler = new TestScheduler();
testScheduler.AdvanceTo(DateTimeOffset.UtcNow.Ticks);
var nodes = TestNode.CreateCluster(scheduler: testScheduler);
nodes.Start();
testScheduler.AdvanceBy(TestNode.ElectionTimeout.Ticks);
nodes.Should().ContainSingle(n => n.State == State.Leader || n.State == State.Candidate);
}
示例12: SimpleDelay
public void SimpleDelay()
{
var receivedSignals = new List<int>();
var subject = new Subject<int>();
var scheduler = new TestScheduler();
subject.UniqueThrottle(TimeSpan.FromTicks(25), scheduler).Subscribe(x => receivedSignals.Add(x));
subject.OnNext(1);
receivedSignals.Count.Should().Be(0);
scheduler.AdvanceTo(24);
receivedSignals.Count.Should().Be(0);
scheduler.AdvanceTo(25);
receivedSignals.Count.Should().Be(1);
scheduler.AdvanceTo(100);
receivedSignals.Count.Should().Be(1);
}
示例13: SetUp
public void SetUp()
{
testScheduler = new TestScheduler();
testScheduler.AdvanceTo(DateTimeOffset.UtcNow.Ticks);
nodes = TestNode.CreateCluster(scheduler: testScheduler);
nodes.Start();
leader = nodes.WaitForLeader(testScheduler).Result;
darkNode = nodes.First(n => n != leader) as TestNode;
darkNode.SleepOnAppendEntries = true;
}
开发者ID:jonsequitur,项目名称:JollyRaft,代码行数:11,代码来源:Given_a_cluster_with_a_leader_and_one_node_that_has_gone_dark.cs
示例14: AsyncGetTest
public void AsyncGetTest()
{
var input = new[] { 1, 1, 1, 1, 1 };
var sched = new TestScheduler();
var delay = TimeSpan.FromSeconds(1.0);
var fixture = new ObservableAsyncMRUCache<int, int>(x => Observable.Return(x*5).Delay(delay, sched), 5, 2, null, sched);
int result = 0;
input.ToObservable(sched).SelectMany<int, int>(x => (IObservable<int>)fixture.AsyncGet(x)).Subscribe(x => result += x);
sched.AdvanceTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));
Assert.Equal(0, result);
sched.AdvanceTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1200)));
Assert.Equal(25, result);
sched.Start();
Assert.Equal(25, result);
}
示例15: SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes
public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes()
{
//Arrange
var eventEmitter = new MvvmLightMessenger();
var robot = Substitute.For<IRobot>();
robot.EventEmitter.Returns(eventEmitter);
var scheduler = new TestScheduler();
var jiraAggregator = new JiraAggregatorSut(robot, scheduler);
var user = new User { displayName = "Laurent Kempé", name = "laurent" };
var addCommentEvent1 = new JiraModel
{
issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
webhookEvent = "jira:issue_created",
comment = new CommentDetails(),
user = user
};
var addCommentEvent2 = new JiraModel
{
issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
webhookEvent = "jira:issue_updated",
comment = new CommentDetails(),
user = user
};
//Act
scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Emit("JiraEvent", addCommentEvent1));
scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Emit("JiraEvent", addCommentEvent2));
scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks);
robot.Received(0).SendNotification("", "", "Message", true);
scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks);
//Assert
robot.Received(1).SendNotification(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), true);
}