本文整理汇总了C#中ObservableDummy类的典型用法代码示例。如果您正苦于以下问题:C# ObservableDummy类的具体用法?C# ObservableDummy怎么用?C# ObservableDummy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableDummy类属于命名空间,在下文中一共展示了ObservableDummy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiplyChecked_Int_Observable_Update
public void MultiplyChecked_Int_Observable_Update()
{
checked
{
var updated = false;
var dummy = new ObservableDummy<int>() { Item = 3 };
var test = new ObservingFunc<Dummy<int>, int>(d => d.Item * 7);
var result = test.Observe(dummy);
result.ValueChanged += (o, e) =>
{
Assert.AreEqual(21, e.OldValue);
updated = true;
};
Assert.AreEqual(21, result.Value);
Assert.IsFalse(updated);
dummy.Item = 6;
Assert.IsTrue(updated);
Assert.AreEqual(42, result.Value);
}
}
示例2: ArrayCreation_Observable_NoUpdatesWhenDetached
public void ArrayCreation_Observable_NoUpdatesWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<int>() { Item = 23 };
var test = new NotifyValue<int[]>(() => new int[dummy.Item]);
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(23, (test.Value as int[]).Length);
Assert.IsFalse(update);
test.Detach();
dummy.Item = 42;
Assert.IsFalse(update);
test.Attach();
Assert.IsTrue(update);
Assert.AreEqual(42, test.Value.Length);
update = false;
dummy.Item = 2;
Assert.IsTrue(update);
}
示例3: ListInit_Observable_NoUpdateWhenDetached
public void ListInit_Observable_NoUpdateWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<string>("foo");
var test = Observable.Expression(() => new List<string>() { dummy.Item });
test.ValueChanged += (o, e) => update = true;
Assert.IsTrue(test.Value.Contains("foo"));
Assert.IsFalse(update);
test.Detach();
dummy.Item = "bar";
Assert.IsFalse(update);
Assert.AreEqual(0, test.Value.Count);
test.Attach();
Assert.AreEqual(1, test.Value.Count);
Assert.IsTrue(test.Value.Contains("bar"));
dummy.Item = "42";
Assert.AreEqual(1, test.Value.Count);
Assert.IsTrue(test.Value.Contains("42"));
}
示例4: MemberInitialization_Observable_NoUpdatesWhenDetached
public void MemberInitialization_Observable_NoUpdatesWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<int>(23);
var test = Observable.Expression(() => new Dummy<int>() { Item = dummy.Item });
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(23, (test.Value as Dummy<int>).Item);
Assert.IsFalse(update);
test.Detach();
dummy.Item = 42;
Assert.IsFalse(update);
Assert.AreNotSame(dummy, test.Value);
Assert.AreEqual(23, test.Value.Item);
test.Attach();
Assert.AreEqual(42, test.Value.Item);
dummy.Item = 1;
Assert.AreEqual(1, test.Value.Item);
}
示例5: Cast_String_Observable_NoUpdatesWhenDetached
public void Cast_String_Observable_NoUpdatesWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<object>() { Item = "23" };
var test = new NotifyValue<string>(() => (string)dummy.Item);
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual("23", test.Value);
Assert.IsFalse(update);
test.Detach();
dummy.Item = "42";
Assert.IsFalse(update);
test.Attach();
Assert.IsTrue(update);
Assert.AreEqual("42", test.Value);
update = false;
dummy.Item = "1";
Assert.IsTrue(update);
}
示例6: AddChecked_Int_Observable_NoUpdateWhenDetached
public void AddChecked_Int_Observable_NoUpdateWhenDetached()
{
checked
{
var updated = false;
var dummy = new ObservableDummy<int>() { Item = 5 };
var result = Observable.Expression(() => dummy.Item + 7);
result.ValueChanged += (o, e) => updated = true;
Assert.AreEqual(12, result.Value);
Assert.IsFalse(updated);
result.Detach();
dummy.Item = 35;
Assert.AreEqual(12, result.Value);
Assert.IsFalse(updated);
result.Attach();
Assert.IsTrue(updated);
Assert.AreEqual(42, result.Value);
updated = false;
dummy.Item = 5;
Assert.IsTrue(updated);
}
}
示例7: ConditionalExpression_ObservableTest_NoUpdatesWhenDetached
public void ConditionalExpression_ObservableTest_NoUpdatesWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<bool>() { Item = false };
var test = new ObservingFunc<Dummy<bool>, string>(d => d.Item ? "42" : "23");
var result = test.Observe(dummy);
result.ValueChanged += (o, e) => update = true;
Assert.AreEqual("23", result.Value);
Assert.IsFalse(update);
result.Detach();
dummy.Item = true;
Assert.IsFalse(update);
result.Attach();
Assert.IsTrue(update);
Assert.AreEqual("42", result.Value);
update = false;
dummy.Item = false;
Assert.IsTrue(update);
}
示例8: New_Observable_NoUpdatesWhenDetached
public void New_Observable_NoUpdatesWhenDetached()
{
var update = false;
var dummy = new ObservableDummy<int>() { Item = 23 };
var test = new NotifyValue<Dummy<int>>(() => new Dummy<int>(dummy.Item));
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(23, (test.Value as Dummy<int>).Item);
Assert.IsFalse(update);
test.Detach();
dummy.Item = 42;
Assert.IsFalse(update);
test.Attach();
Assert.IsTrue(update);
Assert.AreEqual(42, test.Value.Item);
update = false;
dummy.Item = 1;
Assert.IsTrue(update);
}
示例9: OrElse_RightHandThrowsException_NoExceptionOnUpdate
public void OrElse_RightHandThrowsException_NoExceptionOnUpdate()
{
var dummy = new ObservableDummy<bool>(false);
var test = Observable.Expression(() => dummy.Item || ThrowExceptionIf(dummy.Item));
Assert.IsTrue(test.Value);
dummy.Item = true;
Assert.IsTrue(test.Value);
}
示例10: AndAlso_RightHandThrowsException_NoExceptionOnUpdate
public void AndAlso_RightHandThrowsException_NoExceptionOnUpdate()
{
var dummy = new ObservableDummy<bool>(true);
var test = Observable.Expression(() => dummy.Item && ThrowExceptionIf(!dummy.Item));
Assert.IsTrue(test.Value);
dummy.Item = false;
Assert.IsFalse(test.Value);
}
示例11: Modulo_Int_ModuloDoesNotChange_NoUpdate
public void Modulo_Int_ModuloDoesNotChange_NoUpdate()
{
var update = false;
var dummy = new ObservableDummy<int>(7);
var test = Observable.Expression(() => dummy.Item % 2);
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(1, test.Value);
Assert.IsFalse(update);
dummy.Item = 3;
Assert.IsFalse(update);
}
示例12: And_Boolean_Observable_Update
public void And_Boolean_Observable_Update()
{
var updated = false;
var dummy = new ObservableDummy<bool>() { Item = true };
var result = Observable.Expression(() => dummy.Item & true);
result.ValueChanged += (o, e) => updated = true;
Assert.IsTrue(result.Value);
Assert.IsFalse(updated);
dummy.Item = false;
Assert.IsFalse(result.Value);
Assert.IsTrue(updated);
}
示例13: GreaterThanEquals_Long_Observable_Update
public void GreaterThanEquals_Long_Observable_Update()
{
var updated = false;
var dummy = new ObservableDummy<long>() { Item = 1 };
var test = new ObservingFunc<Dummy<long>, bool>(d => d.Item >= 0);
var result = test.Observe(dummy);
result.ValueChanged += (o, e) => updated = true;
Assert.IsTrue(result.Value);
Assert.IsFalse(updated);
dummy.Item = -1;
Assert.IsFalse(result.Value);
Assert.IsTrue(updated);
}
示例14: Equals_Class_Observable_Update
public void Equals_Class_Observable_Update()
{
var updated = false;
var dummy = new ObservableDummy<string>() { Item = "42" };
var test = new ObservingFunc<Dummy<string>, bool>(d => d.Item == "42");
var result = test.Observe(dummy);
result.ValueChanged += (o, e) => updated = true;
Assert.IsTrue(result.Value);
Assert.IsFalse(updated);
dummy.Item = "23";
Assert.IsFalse(result.Value);
Assert.IsTrue(updated);
}
示例15: LessThan_Int_Observable_Update
public void LessThan_Int_Observable_Update()
{
var updated = false;
var dummy = new ObservableDummy<int>() { Item = 1 };
var test = new ObservingFunc<Dummy<int>, bool>(d => d.Item < 0);
var result = test.Observe(dummy);
result.ValueChanged += (o, e) => updated = true;
Assert.IsFalse(result.Value);
Assert.IsFalse(updated);
dummy.Item = -1;
Assert.IsTrue(result.Value);
Assert.IsTrue(updated);
}