public void TestResourceNameLocalhostSource() { //arrange _warewolfServerName = "localhost"; _updateManagerMock.SetupGet(it => it.ServerName).Returns(_warewolfServerName); _changedPropertiesPluginSource = new List <string>(); _targetPluginSource = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _pluginSourceMock.Object, _asyncWorkerMock.Object); _targetPluginSource.DispatcherAction = action => action?.Invoke(); _targetPluginSource.PropertyChanged += (sender, args) => { _changedPropertiesPluginSource.Add(args.PropertyName); }; var expectedValue = "someResourceName"; var pluginSourceName = "pluginSourceName"; _pluginSourceMock.SetupGet(it => it.ResourceName).Returns(pluginSourceName); var expectedHeader = pluginSourceName + " *"; var expectedHeaderText = pluginSourceName; _changedPropertiesPluginSource.Clear(); //act _targetPluginSource.ResourceName = expectedValue; var value = _targetPluginSource.ResourceName; //asert Assert.AreEqual(expectedValue, value); Assert.IsTrue(_changedPropertiesPluginSource.Contains(expectedValue)); Assert.AreEqual(expectedHeader, _targetPluginSource.Header); Assert.AreEqual(expectedHeaderText, _targetPluginSource.HeaderText); }
public static void SetupForSystem() { Utils.SetupResourceDictionary(); var sourceControl = CreateSourceControl(); var mockStudioUpdateManager = new Mock <IManageComPluginSourceModel>(); mockStudioUpdateManager.Setup(model => model.ServerName).Returns("localhost"); mockStudioUpdateManager.Setup(model => model.GetComDllListings(null)).Returns(BuildBaseListing()); var mockRequestServiceNameViewModel = new Mock <IRequestServiceNameViewModel>(); var mockEventAggregator = new Mock <Microsoft.Practices.Prism.PubSubEvents.IEventAggregator>(); var mockExecutor = new Mock <IExternalProcessExecutor>(); var mockSynchronousAsyncWorker = new Mock <SynchronousAsyncWorker>(); var task = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object); task.Start(); var viewModel = new ManageComPluginSourceViewModel(mockStudioUpdateManager.Object, task, mockEventAggregator.Object, new SynchronousAsyncWorker()); sourceControl.DataContext = viewModel; Utils.ShowTheViewForTesting(sourceControl); FeatureContext.Current.Add(Utils.ViewNameKey, sourceControl); FeatureContext.Current.Add(Utils.ViewModelNameKey, viewModel); FeatureContext.Current.Add("updateManager", mockStudioUpdateManager); FeatureContext.Current.Add("requestServiceNameViewModel", mockRequestServiceNameViewModel); FeatureContext.Current.Add("externalProcessExecutor", mockExecutor); FeatureContext.Current.Add("eventAggregator", mockEventAggregator); FeatureContext.Current.Add("synchronousAsyncWorker", mockSynchronousAsyncWorker); }
public void TestDispose() { var vm = new ManageComPluginSourceViewModel(); var ns = new Mock <IRequestServiceNameViewModel>(); vm.SetRequestServiceNameViewModel(ns.Object); vm.Dispose(); ns.Verify(a => a.Dispose()); }
public void GivenIOpenPluginSource(string name) { var pluginSrc = new ComPluginSourceDefinition { ResourceName = name, Id = Guid.NewGuid(), ResourcePath = "", ClsId = Guid.NewGuid().ToString(), Is32Bit = true, SelectedDll = new DllListing() { ClsId = Guid.NewGuid().ToString(), Name = "Object", Is32Bit = false, FullName = "System.Object", IsDirectory = false }, }; var managePluginSourceControl = ScenarioContext.Current.Get <ManageComPluginSourceControl>(Utils.ViewNameKey); var mockStudioUpdateManager = FeatureContext.Current.Get <Mock <IManageComPluginSourceModel> >("updateManager").Object; var mockEventAggregator = FeatureContext.Current.Get <Mock <IEventAggregator> >("eventAggregator").Object; var mockSynchronousAsyncWorker = FeatureContext.Current.Get <Mock <SynchronousAsyncWorker> >("synchronousAsyncWorker").Object; try { var managePluginSourceViewModel = new ManageComPluginSourceViewModel(mockStudioUpdateManager, mockEventAggregator, pluginSrc, new SynchronousAsyncWorker(), a => { try { a.Invoke(); } catch { // ignored } }); managePluginSourceControl.DataContext = managePluginSourceViewModel; ScenarioContext.Current.Remove("viewModel"); ScenarioContext.Current.Add("viewModel", managePluginSourceViewModel); } catch (Exception) { // ignored } }
public void Cleanup() { var mockExecutor = new Mock <IExternalProcessExecutor>(); var mockUpdateManager = ScenarioContext.Current.Get <Mock <IManageComPluginSourceModel> >("updateManager"); mockUpdateManager.Setup(model => model.GetComDllListings(null)).Returns(BuildBaseListing()); var mockRequestServiceNameViewModel = ScenarioContext.Current.Get <Mock <IRequestServiceNameViewModel> >("requestServiceNameViewModel"); var mockEventAggregator = new Mock <Microsoft.Practices.Prism.PubSubEvents.IEventAggregator>(); var mockViewModel = ScenarioContext.Current.Get <ManageComPluginSourceViewModel>(Utils.ViewModelNameKey); var task = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object); task.Start(); var viewModel = new ManageComPluginSourceViewModel(mockUpdateManager.Object, task, mockEventAggregator.Object, new SynchronousAsyncWorker(), mockViewModel.DispatcherAction); var managePluginSourceControl = ScenarioContext.Current.Get <ManageComPluginSourceControl>(Utils.ViewNameKey); managePluginSourceControl.DataContext = viewModel; FeatureContext.Current.Remove("viewModel"); FeatureContext.Current.Add("viewModel", viewModel); FeatureContext.Current.Remove("externalProcessExecutor"); FeatureContext.Current.Add("externalProcessExecutor", mockExecutor); }
public void TestInitialize() { _updateManagerMock = new Mock <IManageComPluginSourceModel>(); _aggregatorMock = new Mock <IEventAggregator>(); _asyncWorkerMock = new Mock <IAsyncWorker>(); _pluginSourceMock = new Mock <IComPluginSource>(); _requestServiceNameViewModelMock = new Mock <IRequestServiceNameViewModel>(); _requestServiceNameViewModelTask = Task.FromResult(_requestServiceNameViewModelMock.Object); _pluginSourceName = "someName"; _warewolfServerName = "warewolfServerName"; _selectedDllFullName = "selectedDllFullName"; _selectedDllMock = new Mock <IFileListing>(); _dispatcherAction = action => action?.Invoke(); _updateManagerMock.SetupGet(it => it.ServerName).Returns(_warewolfServerName); _pluginSourceMock.SetupGet(it => it.ResourceName).Returns(_pluginSourceName); _pluginSourceMock.SetupGet(it => it.SelectedDll).Returns(_selectedDllMock.Object); _selectedDllMock.SetupGet(it => it.FullName).Returns(_selectedDllFullName); _updateManagerMock.Setup(model => model.GetComDllListings(It.IsAny <IFileListing>())).Returns(new List <IFileListing> { _selectedDllMock.Object }); _asyncWorkerMock.Setup( it => it.Start(It.IsAny <Action>(), It.IsAny <Action>(), It.IsAny <Action <Exception> >())) .Callback <Action, Action, Action <Exception> >( (start, finish, exception) => { try { start?.Invoke(); finish?.Invoke(); } catch (Exception e) { exception?.Invoke(e); } }); _updateManagerMock.Setup(model => model.FetchSource(It.IsAny <Guid>())) .Returns(_pluginSourceMock.Object); _asyncWorkerMock.Setup(worker => worker.Start( It.IsAny <Func <Tuple <IComPluginSource, List <DllListingModel> > > >(), It.IsAny <Action <Tuple <IComPluginSource, List <DllListingModel> > > >())) .Callback <Func <Tuple <IComPluginSource, List <DllListingModel> > >, Action <Tuple <IComPluginSource, List <DllListingModel> > > >((func, action) => { var dbSource = func.Invoke(); action?.Invoke(dbSource); }); _changedPropertiesParameterless = new List <string>(); _targetParameterless = new ManageComPluginSourceViewModel { DispatcherAction = action => action?.Invoke() }; _targetParameterless.PropertyChanged += (sender, args) => { _changedPropertiesParameterless.Add(args.PropertyName); }; _changedProperties = new List <string>(); _target = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _asyncWorkerMock.Object) { DispatcherAction = action => action?.Invoke() }; _target.PropertyChanged += (sender, args) => { _changedProperties.Add(args.PropertyName); }; _changedPropertiesPluginSource = new List <string>(); _targetPluginSource = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _pluginSourceMock.Object, _asyncWorkerMock.Object) { DispatcherAction = action => action?.Invoke() }; _targetPluginSource.PropertyChanged += (sender, args) => { _changedPropertiesPluginSource.Add(args.PropertyName); }; _changedPropertiesRequestServiceNameViewModel = new List <string>(); _targetRequestServiceNameViewModel = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _requestServiceNameViewModelTask, _aggregatorMock.Object, _asyncWorkerMock.Object) { DispatcherAction = action => action?.Invoke() }; _targetRequestServiceNameViewModel.PropertyChanged += (sender, args) => { _changedPropertiesRequestServiceNameViewModel.Add(args.PropertyName); }; _changedPropertiesPluginSourceAction = new List <string>(); _updateManagerMock.Setup(model => model.FetchSource(It.IsAny <Guid>())) .Returns(_pluginSourceMock.Object); _targetPluginSourceAction = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _pluginSourceMock.Object, _asyncWorkerMock.Object, _dispatcherAction); _targetPluginSourceAction.PropertyChanged += (sender, args) => { _changedPropertiesPluginSourceAction.Add(args.PropertyName); }; _changedPropertiesRequestServiceNameViewModelAction = new List <string>(); _targetRequestServiceNameViewModelAction = new ManageComPluginSourceViewModel(_updateManagerMock.Object, _requestServiceNameViewModelTask, _aggregatorMock.Object, _asyncWorkerMock.Object, _dispatcherAction); _targetRequestServiceNameViewModelAction.PropertyChanged += (sender, args) => { _changedPropertiesRequestServiceNameViewModelAction.Add(args.PropertyName); }; }