public void TestResourceNameLocalhostSource() { //arrange _warewolfServerName = "localhost"; _updateManagerMock.SetupGet(it => it.ServerName).Returns(_warewolfServerName); _changedPropertiesSource = new List <string>(); _targetSource = new ManagePluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _pluginSourceMock.Object, _asyncWorkerMock.Object); _targetSource.PropertyChanged += (sender, args) => { _changedPropertiesSource.Add(args.PropertyName); }; const string ExpectedValue = "someResourceName"; const string PluginSourceName = "pluginSourceName"; _pluginSourceMock.SetupGet(it => it.Name).Returns(PluginSourceName); const string ExpectedHeader = PluginSourceName + " *"; const string ExpectedHeaderText = PluginSourceName; _changedPropertiesSource.Clear(); //act _targetSource.ResourceName = ExpectedValue; var value = _targetSource.ResourceName; //asert Assert.AreEqual(ExpectedValue, value); Assert.IsTrue(_changedPropertiesSource.Contains(ExpectedValue)); Assert.AreEqual(ExpectedHeader, _targetSource.Header); Assert.AreEqual(ExpectedHeaderText, _targetSource.HeaderText); }
public void GivenIOpenPluginSource(string name) { var pluginSrc = new PluginSourceDefinition { Name = name, Id = Guid.NewGuid(), Path = "", SelectedDll = name.Equals("Test", StringComparison.OrdinalIgnoreCase) ? _dllListingForGac : _dllListingForFile, }; pluginSrc.GACAssemblyName = _dllListingForGac.FullName; pluginSrc.FileSystemAssemblyName = _dllListingForFile.FullName; var managePluginSourceControl = ScenarioContext.Current.Get <ManagePluginSourceControl>(Utils.ViewNameKey); var mockStudioUpdateManager = FeatureContext.Current.Get <Mock <IManagePluginSourceModel> >("updateManager").Object; var mockEventAggregator = FeatureContext.Current.Get <Mock <IEventAggregator> >("eventAggregator").Object; var mockSynchronousAsyncWorker = FeatureContext.Current.Get <Mock <SynchronousAsyncWorker> >("synchronousAsyncWorker").Object; try { var managePluginSourceViewModel = new ManagePluginSourceViewModel(mockStudioUpdateManager, mockEventAggregator, pluginSrc, new SynchronousAsyncWorker()); managePluginSourceControl.DataContext = managePluginSourceViewModel; ScenarioContext.Current.Remove("viewModel"); ScenarioContext.Current.Add("viewModel", managePluginSourceViewModel); } catch (Exception) { // ignored } }
public static void SetupForSystem() { Utils.SetupResourceDictionary(); var sourceControl = new ManagePluginSourceControl(); var pluginSourceModel = new Mock <IManagePluginSourceModel>(); pluginSourceModel.Setup(model => model.FetchSource(It.IsAny <Guid>())) .Returns(new PluginSourceDefinition() { Name = "Test", GACAssemblyName = "GAC:AuditPolicyGPManagedStubs, Version=6.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }); pluginSourceModel.Setup(model => model.ServerName).Returns("localhost"); pluginSourceModel.Setup(model => model.GetDllListings(null)).Returns(BuildBaseListing()); var mockRequestServiceNameViewModel = new Mock <IRequestServiceNameViewModel>(); var mockEventAggregator = new Mock <IEventAggregator>(); var mockExecutor = new Mock <IExternalProcessExecutor>(); var mockSynchronousAsyncWorker = new Mock <SynchronousAsyncWorker>(); var task = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object); task.Start(); var viewModel = new ManagePluginSourceViewModel(pluginSourceModel.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", pluginSourceModel); FeatureContext.Current.Add("requestServiceNameViewModel", mockRequestServiceNameViewModel); FeatureContext.Current.Add("externalProcessExecutor", mockExecutor); FeatureContext.Current.Add("eventAggregator", mockEventAggregator); FeatureContext.Current.Add("synchronousAsyncWorker", mockSynchronousAsyncWorker); }
public void TestInitialize() { _updateManagerMock = new Mock <IManagePluginSourceModel>(); _requestServiceNameViewModelMock = new Mock <IRequestServiceNameViewModel>(); _aggregatorMock = new Mock <IEventAggregator>(); _asyncWorkerMock = new Mock <IAsyncWorker>(); _pluginSourceMock = new Mock <IPluginSource>(); _selectedDllMock = new Mock <IFileListing>(); _pluginSourceName = "someName"; _warewolfServerName = "warewolfServerName"; _selectedDllFullName = "selectedDllFullName"; _updateManagerMock.SetupGet(it => it.ServerName).Returns(_warewolfServerName); _updateManagerMock.Setup(it => it.GetDllListings(null)).Returns(new List <IFileListing>()); _pluginSourceMock.SetupGet(it => it.Name).Returns(_pluginSourceName); _pluginSourceMock.SetupGet(it => it.Name).Returns(_pluginSourceName); _pluginSourceMock.SetupGet(it => it.SelectedDll).Returns(_selectedDllMock.Object); _updateManagerMock.Setup(model => model.FetchSource(It.IsAny <Guid>())) .Returns(_pluginSourceMock.Object); _requestServiceNameViewModelTask = Task.FromResult(_requestServiceNameViewModelMock.Object); _selectedDllMock.SetupGet(it => it.FullName).Returns(_selectedDllFullName); _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 <IPluginSource> >(), It.IsAny <Action <IPluginSource> >())) .Callback <Func <IPluginSource>, Action <IPluginSource> >((func, action) => { var dbSource = func.Invoke(); action?.Invoke(dbSource); }); _changedProperties = new List <string>(); _target = new ManagePluginSourceViewModel(_updateManagerMock.Object, _requestServiceNameViewModelTask, _aggregatorMock.Object, _asyncWorkerMock.Object); _target.PropertyChanged += (sender, e) => { _changedProperties.Add(e.PropertyName); }; _changedPropertiesSource = new List <string>(); _targetSource = new ManagePluginSourceViewModel(_updateManagerMock.Object, _aggregatorMock.Object, _pluginSourceMock.Object, _asyncWorkerMock.Object); _targetSource.PropertyChanged += (sender, e) => { _changedPropertiesSource.Add(e.PropertyName); }; _changedPropertiesRequestServiceNameViewModel = new List <string>(); _targetRequestServiceNameViewModel = new ManagePluginSourceViewModel(_updateManagerMock.Object, _requestServiceNameViewModelTask, _aggregatorMock.Object, new SynchronousAsyncWorker()); _targetRequestServiceNameViewModel.PropertyChanged += (sender, args) => { _changedPropertiesRequestServiceNameViewModel.Add(args.PropertyName); }; }
public void TestDispose() { var vm = new ManagePluginSourceViewModel(); var ns = new Mock <IRequestServiceNameViewModel>(); vm.SetRequestServiceNameViewModel(ns.Object); vm.Dispose(); ns.Verify(a => a.Dispose()); }
public void Cleanup() { var mockExecutor = new Mock <IExternalProcessExecutor>(); var mockUpdateManager = ScenarioContext.Current.Get <Mock <IManagePluginSourceModel> >("updateManager"); mockUpdateManager.Setup(model => model.GetDllListings(null)).Returns(BuildBaseListing()); var mockRequestServiceNameViewModel = ScenarioContext.Current.Get <Mock <IRequestServiceNameViewModel> >("requestServiceNameViewModel"); var mockEventAggregator = new Mock <IEventAggregator>(); var mockViewModel = ScenarioContext.Current.Get <ManagePluginSourceViewModel>(Utils.ViewModelNameKey); var task = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object); task.Start(); var viewModel = new ManagePluginSourceViewModel(mockUpdateManager.Object, task, mockEventAggregator.Object, new SynchronousAsyncWorker()); var managePluginSourceControl = ScenarioContext.Current.Get <ManagePluginSourceControl>(Utils.ViewNameKey); managePluginSourceControl.DataContext = viewModel; FeatureContext.Current.Remove("viewModel"); FeatureContext.Current.Add("viewModel", viewModel); FeatureContext.Current.Remove("externalProcessExecutor"); FeatureContext.Current.Add("externalProcessExecutor", mockExecutor); }