本文整理汇总了C#中MainViewModel.Handle方法的典型用法代码示例。如果您正苦于以下问题:C# MainViewModel.Handle方法的具体用法?C# MainViewModel.Handle怎么用?C# MainViewModel.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainViewModel
的用法示例。
在下文中一共展示了MainViewModel.Handle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Verify_HandleAddWorkSurfaceMessage_ShowDebugWindowOnLoad
static void Verify_HandleAddWorkSurfaceMessage_ShowDebugWindowOnLoad(bool showDebugWindowOnLoad)
{
//------------Setup for test--------------------------
var eventAggregator = new Mock<IEventAggregator>();
var envRepo = new Mock<IEnvironmentRepository>();
envRepo.Setup(e => e.All()).Returns(new List<IEnvironmentModel>());
var environmentModel = new Mock<IEnvironmentModel>().Object;
envRepo.Setup(e => e.Source).Returns(environmentModel);
envRepo.Setup(e => e.Source.IsConnected).Returns(false);
envRepo.Setup(e => e.Source.Connection.IsConnected).Returns(false);
var vm = new MainViewModel(eventAggregator.Object, new TestAsyncWorker(), envRepo.Object, new Mock<IVersionChecker>().Object, false, new Mock<IBrowserPopupController>().Object);
var workSurfaceContextViewModel = new Mock<WorkSurfaceContextViewModel>(eventAggregator.Object, new WorkSurfaceKey(), new Mock<IWorkSurfaceViewModel>().Object, new Mock<IPopupController>().Object, new Action<IContextualResourceModel, bool>(
(a, b) => { }));
workSurfaceContextViewModel.Setup(v => v.Debug()).Verifiable();
vm.ActiveItem = workSurfaceContextViewModel.Object;
//------------Execute Test---------------------------
vm.Handle(new AddWorkSurfaceMessage(new Mock<IWorkSurfaceObject>().Object) { ShowDebugWindowOnLoad = showDebugWindowOnLoad });
//------------Assert Results-------------------------
workSurfaceContextViewModel.Verify(v => v.Debug(), showDebugWindowOnLoad ? Times.Once() : Times.Never());
}
示例2: MainViewModel_HandleDeployResourcesMessage_PublishesSelectItemInDeployMessage
public void MainViewModel_HandleDeployResourcesMessage_PublishesSelectItemInDeployMessage()
{
SelectItemInDeployMessage actual = null;
var eventAggregator = new Mock<IEventAggregator>();
eventAggregator.Setup(e => e.Publish(It.IsAny<object>())).Callback((object msg) => actual = msg as SelectItemInDeployMessage).Verifiable();
#region Setup ImportService - GRRR!
//Barney, commented out when I removed the feedback stuff from the studio
//SetupDefaultMef();
#endregion
var resourceID = Guid.NewGuid();
var environmentID = Guid.NewGuid();
var envRepo = new Mock<IEnvironmentRepository>();
envRepo.Setup(e => e.All()).Returns(new List<IEnvironmentModel>());
Mock<IResourceRepository> mockResourceRepository = new Mock<IResourceRepository>();
Mock<IContextualResourceModel> mockResourceModel = new Mock<IContextualResourceModel>();
mockResourceModel.Setup(model => model.ID).Returns(resourceID);
mockResourceRepository.Setup(repository => repository.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Returns(mockResourceModel.Object);
Mock<IEnvironmentModel> mockEnvironmentModel = new Mock<IEnvironmentModel>();
mockEnvironmentModel.Setup(model => model.ID).Returns(environmentID);
mockEnvironmentModel.Setup(model => model.ResourceRepository).Returns(mockResourceRepository.Object);
mockEnvironmentModel.Setup(model => model.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
var environmentModel = mockEnvironmentModel.Object;
mockResourceModel.Setup(model => model.Environment).Returns(environmentModel);
envRepo.Setup(e => e.Source).Returns(environmentModel);
envRepo.Setup(e => e.FindSingle(It.IsAny<Expression<Func<IEnvironmentModel, bool>>>())).Returns(environmentModel);
envRepo.Setup(e => e.Source.IsConnected).Returns(false);
envRepo.Setup(e => e.Source.Connection.IsConnected).Returns(false);
var vm = new MainViewModel(eventAggregator.Object, new TestAsyncWorker(), envRepo.Object, new Mock<IVersionChecker>().Object, false, new Mock<IBrowserPopupController>().Object);
vm.AddDeployResourcesWorkSurface(mockResourceModel.Object);
var expected = new Mock<IExplorerItemModel>();
expected.Setup(model => model.ResourceId).Returns(resourceID);
expected.Setup(model => model.EnvironmentId).Returns(environmentModel.ID);
var deployMessage = new DeployResourcesMessage(expected.Object);
vm.Handle(deployMessage);
eventAggregator.Verify(e => e.Publish(It.IsAny<object>()), "MainViewModel Handle DeployResourcesMessage did not publish message with the selected view model.");
Assert.IsNotNull(actual, "MainViewModel Handle DeployResourcesMessage did not publish message with the selected view model.");
Assert.AreEqual(expected.Object.ResourceId, actual.ResourceID, "MainViewModel Handle DeployResourcesMessage did not publish message with the selected display name.");
Assert.AreEqual(expected.Object.EnvironmentId, actual.EnvironmentID, "MainViewModel Handle DeployResourcesMessage did not publish message with the selected environment.");
}