本文整理汇总了C#中GalaSoft.MvvmLight.Test.ViewModel.TestViewModel类的典型用法代码示例。如果您正苦于以下问题:C# TestViewModel类的具体用法?C# TestViewModel怎么用?C# TestViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestViewModel类属于GalaSoft.MvvmLight.Test.ViewModel命名空间,在下文中一共展示了TestViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate
public void SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate()
{
var value = DateTime.Now.Ticks.ToString();
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = value
}
};
var vmTarget = new TestViewModel();
var control = new UIBarButtonItemEx();
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty);
control.SetCommand(
"Clicked",
vmTarget.SetPropertyCommand,
_binding);
Assert.IsNull(vmTarget.TargetProperty);
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
value += "Test";
vmSource.Model.MyProperty = value;
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
示例2: Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue
public void Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue()
{
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue)
.ConvertSourceToTarget(
value =>
{
throw new InvalidCastException("Only for test");
});
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Model.MyProperty = "New value";
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
}
示例3: Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue
public void Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue()
{
var vmSource = new TestViewModel();
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Nested.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue);
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested = new TestViewModel();
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested.Model = new TestModel();
Assert.AreEqual(targetNullValue, vmTarget.TargetProperty);
vmSource.Nested.Model.MyProperty = DateTime.Now.Ticks.ToString();
Assert.AreEqual(vmSource.Nested.Model.MyProperty, vmTarget.TargetProperty);
}
示例4: BindingConverter_ConvertDateTimeTwoWayToText_NoError
public void BindingConverter_ConvertDateTimeTwoWayToText_NoError()
{
var now = DateTime.Now;
Vm = new TestViewModel
{
Date = now
};
#if ANDROID
Text = new EditText(Application.Context);
#elif __IOS__
Text = new UITextViewEx();
#endif
this.SetBinding(
() => Vm.Date,
() => Text.Text,
BindingMode.TwoWay)
.ConvertSourceToTarget(d => d.Date.ToShortDateString())
.ConvertTargetToSource(d => DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture));
Assert.AreEqual(now, Vm.Date);
Assert.AreEqual(now.ToShortDateString(), Text.Text);
Vm.Date += TimeSpan.FromDays(3);
Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);
var newDateString = "13/04/1971";
var newDate = new DateTime(1971, 4, 13);
Text.Text = newDateString;
Assert.AreEqual(newDateString, Text.Text);
Assert.AreEqual(newDate, Vm.Date);
}
示例5: BindingConverter_ConvertDateTimeToText_NoError
public void BindingConverter_ConvertDateTimeToText_NoError()
{
var now = DateTime.Now;
Vm = new TestViewModel
{
Date = now
};
#if ANDROID
Text = new EditText(Application.Context);
#elif __IOS__
Text = new UITextViewEx();
#endif
this.SetBinding(
() => Vm.Date,
() => Text.Text)
.ConvertSourceToTarget(d => d.Date.ToShortDateString());
Assert.AreEqual(now, Vm.Date);
Assert.AreEqual(now.ToShortDateString(), Text.Text);
Vm.Date += TimeSpan.FromDays(3);
Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);
}
示例6: SetCommand_OnBarButtonNoValueNoEventName_ClickEventShouldBeUsed
public void SetCommand_OnBarButtonNoValueNoEventName_ClickEventShouldBeUsed()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
vmTarget.Configure(value);
var control = new UIBarButtonItemEx();
control.SetCommand(vmTarget.SetPropertyWithoutValueCommand);
Assert.IsNull(vmTarget.TargetProperty);
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
示例7: SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed
public void SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
vmTarget.Configure(value);
var button = new Button(Application.Context);
button.SetCommand(vmTarget.SetPropertyWithoutValueCommand);
Assert.IsNull(vmTarget.TargetProperty);
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
示例8: BindingSource_NewBindingWithPrivateProperty_NoError
public void BindingSource_NewBindingWithPrivateProperty_NoError()
{
// For comparison only
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
var vmTarget = new TestViewModel();
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty);
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
var newValue1 = DateTime.Now.Ticks.ToString();
vmSource.Model.MyProperty = newValue1;
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
// Actual test
VmSourcePrivate = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
VmTarget = new TestViewModel();
_binding = new Binding<string, string>(
VmSourcePrivate,
() => VmSourcePrivate.Model.MyProperty,
VmTarget,
() => VmTarget.TargetProperty);
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
var newValue2 = DateTime.Now.Ticks.ToString();
VmSourcePrivate.Model.MyProperty = newValue2;
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
}
示例9: SetCommand_OnButtonExWithSimpleValue_NoError
public void SetCommand_OnButtonExWithSimpleValue_NoError()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
var button = new ButtonEx(Application.Context);
button.SetCommand(
"Click",
vmTarget.SetPropertyCommand,
value);
Assert.IsNull(vmTarget.TargetProperty);
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
示例10: Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UISwitchEx();
var binding = new Binding<bool, string>(
control1,
() => control1.On,
vm,
() => vm.Model.MyProperty);
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.On);
control1.On = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.On);
}
示例11: Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
var binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty);
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.Checked);
}
示例12: Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
_binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty)
.ObserveSourceEvent<CompoundButton.CheckedChangeEventArgs>("CheckedChange");
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.Checked);
}
示例13: Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
var binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty)
.ObserveSourceEvent(); // LostFocus doesn't work programatically with CheckBoxes
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.IsTrue(control1.Checked);
Assert.AreEqual("True", vm.Model.MyProperty);
}
示例14: BindingTarget_NewBindingWithPrivateProperty_NoError
public void BindingTarget_NewBindingWithPrivateProperty_NoError()
{
VmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
VmTargetPrivate = new TestViewModel();
_binding = new Binding<string, string>(
VmSource,
() => VmSource.Model.MyProperty,
VmTargetPrivate,
() => VmTargetPrivate.TargetProperty);
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
var newValue = DateTime.Now.Ticks.ToString();
VmSource.Model.MyProperty = newValue;
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
}
示例15: Binding_OneWayFromViewModelToCheckBox_BindingGetsUpdated
public void Binding_OneWayFromViewModelToCheckBox_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UISwitchEx();
_binding = new Binding<string, bool>(
vm,
() => vm.Model.MyProperty,
control1,
() => control1.On);
Assert.AreEqual(null, vm.Model.MyProperty);
Assert.IsFalse(control1.On);
vm.Model.MyProperty = "True";
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.On);
}