本文整理汇总了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);
}
示例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());
}
示例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: 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);
}
示例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);
}
示例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;
});
}
示例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: 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;
});
}
示例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);
}
示例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);
}