示例#1
0
        public static void SetupForSystem()
        {
            Utils.SetupResourceDictionary();
            var manageDatabaseSourceControl = new ManageDatabaseSourceControl();
            var mockStudioUpdateManager     = new Mock <IManageDatabaseSourceModel>();

            mockStudioUpdateManager.Setup(model => model.GetComputerNames()).Returns(new List <string> {
                "TEST", "RSAKLFSVRDEV", "RSAKLFSVRPDC", "RSAKLFSVRTFSBLD", "RSAKLFSVRWRWBLD"
            });
            mockStudioUpdateManager.Setup(model => model.ServerName).Returns("localhost");
            var mockRequestServiceNameViewModel = new Mock <IRequestServiceNameViewModel>();
            var mockEventAggregator             = new Mock <IEventAggregator>();
            var mockExecutor = new Mock <IExternalProcessExecutor>();
            var task         = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object);

            task.Start();
            var manageDatabaseSourceViewModel = new ManageOracleSourceViewModel(mockStudioUpdateManager.Object, task, mockEventAggregator.Object, new SynchronousAsyncWorker());

            manageDatabaseSourceControl.DataContext = manageDatabaseSourceViewModel;
            Utils.ShowTheViewForTesting(manageDatabaseSourceControl);
            FeatureContext.Current.Add(Utils.ViewNameKey, manageDatabaseSourceControl);
            FeatureContext.Current.Add(Utils.ViewModelNameKey, manageDatabaseSourceViewModel);
            FeatureContext.Current.Add("updateManager", mockStudioUpdateManager);
            FeatureContext.Current.Add("requestServiceNameViewModel", mockRequestServiceNameViewModel);
            FeatureContext.Current.Add("externalProcessExecutor", mockExecutor);
        }
        static void CleanupResources()
        {
            var mockUpdateManager = ScenarioContext.Current.Get <Mock <IManageDatabaseSourceModel> >("updateManager");
            var mockRequestServiceNameViewModel =
                ScenarioContext.Current.Get <Mock <IRequestServiceNameViewModel> >("requestServiceNameViewModel");
            var mockEventAggregator = new Mock <IEventAggregator>();
            var task = new Task <IRequestServiceNameViewModel>(() => mockRequestServiceNameViewModel.Object);

            task.Start();
            var viewModel = new ManageOracleSourceViewModel(mockUpdateManager.Object, task, mockEventAggregator.Object,
                                                            new SynchronousAsyncWorker());
            var manageDatabaseSourceControl = ScenarioContext.Current.Get <ManageDatabaseSourceControl>(Utils.ViewNameKey);

            if (manageDatabaseSourceControl.DataContext is ManageOracleSourceViewModel manageDatabaseSourceViewModel)
            {
                Utils.ResetViewModel <ManageOracleSourceViewModel, IDbSource>(viewModel, manageDatabaseSourceViewModel);
                manageDatabaseSourceViewModel.DatabaseName = null;
            }
        }
示例#3
0
        public void GivenIOpen(string name)
        {
            var manageDatabaseSourceControl = ScenarioContext.Current.Get <ManageDatabaseSourceControl>(Utils.ViewNameKey);
            var upd   = FeatureContext.Current.Get <Mock <IManageDatabaseSourceModel> >("updateManager").Object;
            var dbsrc = new DbSourceDefinition
            {
                Name               = name,
                Id                 = Guid.NewGuid(),
                ServerName         = "RSAKLFSVRDEV",
                AuthenticationType = AuthenticationType.Windows
            };

            FeatureContext.Current["dbsrc"] = dbsrc;
            var mockEventAggregator           = new Mock <IEventAggregator>();
            var viewModel                     = new ManageOracleSourceViewModel(upd, mockEventAggregator.Object, dbsrc, new SynchronousAsyncWorker());
            var manageDatabaseSourceViewModel = manageDatabaseSourceControl.DataContext as ManageOracleSourceViewModel;

            if (manageDatabaseSourceViewModel != null)
            {
                Utils.ResetViewModel <ManageOracleSourceViewModel, IDbSource>(viewModel, manageDatabaseSourceViewModel);
            }
        }
        public void TestInitialize()
        {
            _asyncWorkerMock            = new Mock <IAsyncWorker>();
            _updateManagerMock          = new Mock <IManageDatabaseSourceModel>();
            _aggregatorMock             = new Mock <IEventAggregator>();
            _dbSourceMock               = new Mock <IDbSource>();
            _requestServiceNameViewMock = new Mock <IRequestServiceNameViewModel>();
            _requestServiceNameView     = Task.FromResult(_requestServiceNameViewMock.Object);

            _updateManagerMock.Setup(it => it.GetComputerNames())
            .Returns(new List <string>()
            {
                "someName1", "someName2"
            });

            _dbSourceMock.SetupGet(it => it.Name).Returns("someDbSourceName");
            _asyncWorkerMock.Setup(
                it =>
                it.Start(
                    It.IsAny <Func <List <ComputerName> > >(),
                    It.IsAny <Action <List <ComputerName> > >(),
                    It.IsAny <Action <Exception> >()))
            .Callback <Func <List <ComputerName> >, Action <List <ComputerName> >, Action <Exception> >(
                (progress, success, fail) =>
            {
                try
                {
                    success?.Invoke(progress?.Invoke());
                }
                catch (Exception ex)
                {
                    fail?.Invoke(ex);
                }
            });
            _updateManagerMock.Setup(model => model.FetchDbSource(It.IsAny <Guid>()))
            .Returns(_dbSourceMock.Object);
            _asyncWorkerMock.Setup(worker =>
                                   worker.Start(
                                       It.IsAny <Func <IDbSource> >(),
                                       It.IsAny <Action <IDbSource> >()))
            .Callback <Func <IDbSource>, Action <IDbSource> >((func, action) =>
            {
                var dbSource = func.Invoke();
                action?.Invoke(dbSource);
            });
            _targetAsyncWorker                  = new ManageOracleSourceViewModel(_asyncWorkerMock.Object);
            _changedPropertiesAsyncWorker       = new List <string>();
            _targetAsyncWorker.PropertyChanged += (sender, args) =>
            {
                _changedPropertiesAsyncWorker.Add(args.PropertyName);
            };


            _targetUpdateManagerAggregatorDbSource = new ManageOracleSourceViewModel(
                _updateManagerMock.Object,
                _aggregatorMock.Object,
                _dbSourceMock.Object,
                _asyncWorkerMock.Object);
            _changedPropertiesUpdateManagerAggregatorDbSource = new List <string>();

            _targetUpdateManagerAggregatorDbSource.PropertyChanged += (sender, args) =>
            {
                _changedPropertiesUpdateManagerAggregatorDbSource.Add(args.PropertyName);
            };

            _targetUpdateManagerRequestServiceName = new ManageOracleSourceViewModel(
                _updateManagerMock.Object,
                _requestServiceNameView,
                _aggregatorMock.Object,
                _asyncWorkerMock.Object);
            _changedUpdateManagerRequestServiceName = new List <string>();
            _targetUpdateManagerRequestServiceName.PropertyChanged += (sender, args) =>
            {
                _changedUpdateManagerRequestServiceName.Add(args.PropertyName);
            };
        }