本文整理汇总了C#中MainWindowViewModel.LoadState方法的典型用法代码示例。如果您正苦于以下问题:C# MainWindowViewModel.LoadState方法的具体用法?C# MainWindowViewModel.LoadState怎么用?C# MainWindowViewModel.LoadState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainWindowViewModel
的用法示例。
在下文中一共展示了MainWindowViewModel.LoadState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewModelRegistersAllChanges
public void ViewModelRegistersAllChanges()
{
MainWindowViewModel emptyVm = new MainWindowViewModel();
Assert.That( emptyVm.ChangedSinceLastSave, Is.False );
Assert.That( emptyVm.OpenedFilePath, Is.Null );
MainWindowViewModel vm = CreateViewModelWithGraph001();
Assert.That( vm.ChangedSinceLastSave, Is.True );
Assert.That( vm.OpenedFilePath, Is.Null );
string tempFilePath = Path.Combine( Path.GetTempPath(), Path.GetRandomFileName() );
DetailedOperationResult r = vm.SaveState( tempFilePath );
Assert.That( r.IsSuccessful );
Assert.That( vm.OpenedFilePath == tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
MainWindowViewModel vm2 = new MainWindowViewModel();
DetailedOperationResult r2 = vm2.LoadState( tempFilePath );
Assert.That( r2.IsSuccessful );
Assert.That( vm2.ChangedSinceLastSave, Is.False );
// Monitor Configuration changes:
// Layer created
var layer = vm.LabState.Engine.Configuration.Layers.Create();
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Layer item added
var yr = layer.Items.Add( "PluginA-2", ConfigurationStatus.Disabled, "test" );
Assert.That( yr.Success );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Layer item changed
yr = layer.Items["PluginA-2"].SetStatus( ConfigurationStatus.Running );
Assert.That( yr.Success );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Layer item removed
yr = layer.Items.Remove( "PluginA-2" );
Assert.That( yr.Success );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Layer removed
yr = vm.LabState.Engine.Configuration.Layers.Remove( layer );
Assert.That( yr.Success );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Monitor DiscoveredInfo changes:
// Service added
var newService = vm.CreateNewService( "ServiceC" );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Service name changed (White box testing)
var castNewService = (ServiceInfo)newService;
castNewService.ServiceFullName = "ServiceD";
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Service generalization changed (White box testing)
castNewService.Generalization = vm.LabState.ServiceInfos.First( x => x.ServiceFullName == "ServiceB" );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Plugin added
var newPlugin = vm.CreateNewPlugin( "My New Plugin" );
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Plugin name changed (White box testing)
var castNewPlugin = (PluginInfo)newPlugin;
castNewPlugin.PluginFullName = "My New Plugin With A Better Name";
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Plugin service changed (White box testing)
castNewPlugin.Service = castNewService;
Assert.That( vm.ChangedSinceLastSave, Is.True );
r = vm.SaveState( tempFilePath );
Assert.That( vm.ChangedSinceLastSave, Is.False );
// Service reference added
vm.SetPluginDependency( newPlugin, newService, DependencyRequirement.Runnable );
//.........这里部分代码省略.........
示例2: SaveLoadViewModelTest
public void SaveLoadViewModelTest()
{
MainWindowViewModel _vm1 = CreateViewModelWithGraph001();
string tempFilePath = Path.Combine( Path.GetTempPath(), Path.GetRandomFileName() );
DetailedOperationResult r = _vm1.SaveState( tempFilePath );
Assert.That( r.IsSuccessful );
MainWindowViewModel _vm2 = new MainWindowViewModel();
DetailedOperationResult r2 = _vm2.LoadState( tempFilePath );
File.Delete( tempFilePath );
Assert.That( r2.IsSuccessful );
Assert.That( _vm1.PluginInfos.Count == _vm2.PluginInfos.Count );
foreach( var infoB in _vm2.PluginInfos )
{
Assert.That( _vm1.PluginInfos.Where( x => x.PluginFullName == infoB.PluginFullName ).Count() == 1 );
IPluginInfo infoA = _vm1.PluginInfos.Where( x => x.PluginFullName == infoB.PluginFullName ).First();
EquivalenceExtensions.AssertPluginEquivalence( infoA, infoB, true );
}
Assert.That( _vm1.ServiceInfos.Count == _vm2.ServiceInfos.Count );
foreach( var infoB in _vm2.ServiceInfos )
{
Assert.That( _vm1.ServiceInfos.Where( x => x.ServiceFullName == infoB.ServiceFullName ).Count() == 1 );
var infoA = _vm1.ServiceInfos.Where( x => x.ServiceFullName == infoB.ServiceFullName ).First();
EquivalenceExtensions.AssertServiceEquivalence( infoA, infoB, true );
}
EquivalenceExtensions.AssertManagerEquivalence( _vm1.LabState.Engine.Configuration, _vm2.LabState.Engine.Configuration );
}