public void SetupForTest()
        {
            AppUsageStats.LocalHost = "http://localhost:3142";
            var mockShellViewModel = new Mock <IShellViewModel>();
            var lcl = new Mock <IServer>();

            lcl.Setup(a => a.DisplayName).Returns("Localhost");
            mockShellViewModel.Setup(x => x.LocalhostServer).Returns(lcl.Object);
            mockShellViewModel.Setup(x => x.ActiveServer).Returns(new Mock <IServer>().Object);
            var connectControlSingleton = new Mock <IConnectControlSingleton>();
            var explorerTooltips        = new Mock <IExplorerTooltips>();

            CustomContainer.Register(mockShellViewModel.Object);
            CustomContainer.Register(new Mock <Microsoft.Practices.Prism.PubSubEvents.IEventAggregator>().Object);
            CustomContainer.Register(connectControlSingleton.Object);
            CustomContainer.Register(explorerTooltips.Object);

            var targetEnv  = EnviromentRepositoryTest.CreateMockEnvironment(EnviromentRepositoryTest.Server1Source);
            var serverRepo = new Mock <IServerRepository>();

            serverRepo.Setup(r => r.All()).Returns(new[] { targetEnv.Object });
            CustomContainer.Register(serverRepo.Object);
        }
        protected static Guid SetupVmForMessages(out IEnvironmentModel server, out DeployViewModel vm, Mock <IEventAggregator> mockEventAggregator = null)
        {
            var env   = EnviromentRepositoryTest.CreateMockEnvironment();
            var envId = env.Object.ID;

            server = env.Object;

            var serverProvider = new Mock <IEnvironmentModelProvider>();

            serverProvider.Setup(s => s.Load()).Returns(new List <IEnvironmentModel> {
                server
            });
            var repo = CreateEnvironmentRepositoryMock();

            if (mockEventAggregator == null)
            {
                mockEventAggregator = new Mock <IEventAggregator>();
            }
            var studioResourceRepository = new Mock <IStudioResourceRepository>();

            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny <Func <IExplorerItemModel, bool> >())).Returns(new ObservableCollection <IExplorerItemModel>());
            vm = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo.Object, mockEventAggregator.Object, studioResourceRepository.Object, new Mock <IConnectControlViewModel>().Object, new Mock <IConnectControlViewModel>().Object);
            return(envId);
        }
Exemple #3
0
        static void TestLoad(bool useParameterless)
        {
            var targetEnv  = EnviromentRepositoryTest.CreateMockEnvironment(EnviromentRepositoryTest.Server1Source);
            var repository = new Mock <IEnvironmentRepository>();

            repository.Setup(r => r.All()).Returns(new[] { targetEnv.Object });

            if (useParameterless)
            {
                EnvironmentRepository.Instance.Clear();
                EnvironmentRepository.Instance.Save(targetEnv.Object);
                EnvironmentRepository.Instance.IsLoaded = true;  // so that we don't connect to a server!
            }

            var provider = new TestServerProvider();
            var servers  = useParameterless ? provider.Load() : provider.Load(repository.Object);

            Assert.AreEqual(1, servers.Count);

            Assert.AreSame(servers[0], targetEnv.Object);
            Assert.AreEqual(servers[0].ID, targetEnv.Object.ID);
            Assert.AreEqual(servers[0].Name, targetEnv.Object.Name);
            // remove the last two properties from mock ;)
        }
        // ReSharper disable InconsistentNaming
        public void FlowController_HandleConfigureDecisionExpressionMessageAndIsNewFalse_WizardShown()
        // ReSharper restore InconsistentNaming
        {
            #region setup first Mock ModelItem

            var env = EnviromentRepositoryTest.CreateMockEnvironment();

            var properties         = new Dictionary <string, Mock <ModelProperty> >();
            var propertyCollection = new Mock <ModelPropertyCollection>();
            var testAct            = new DsfFlowDecisionActivity {
                ExpressionText = "Not Null Test Value"
            };

            var prop = new Mock <ModelProperty>();
            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Condition", prop);

            propertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(prop.Object);

            var source = new Mock <ModelItem>();
            source.Setup(s => s.Properties).Returns(propertyCollection.Object);

            #endregion

            #region setup decision Mock ModelItem

            var crmDecision = new Mock <IContextualResourceModel>();
            crmDecision.Setup(r => r.Environment).Returns(env.Object);
            crmDecision.Setup(r => r.ResourceName).Returns("Test");
            crmDecision.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));

            var decisionProperties         = new Dictionary <string, Mock <ModelProperty> >();
            var decisionPropertyCollection = new Mock <ModelPropertyCollection>();

            var decisionProp = new Mock <ModelProperty>();
            decisionProp.Setup(p => p.ComputedValue).Returns(string.Empty);
            decisionProperties.Add("Condition", decisionProp);

            decisionPropertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(decisionProp.Object);

            var decisionModelItem = new Mock <ModelItem>();
            decisionModelItem.Setup(s => s.Properties).Returns(decisionPropertyCollection.Object);
            decisionModelItem.Setup(s => s.ItemType).Returns(typeof(FlowDecision));

            prop.Setup(p => p.Value).Returns(decisionModelItem.Object);

            #endregion

            #region setup Environment Model

            env.Setup(c => c.Connection).Returns(new Mock <IEnvironmentConnection>().Object);

            #endregion

            #region setup Start Decision Wizard

            var flowController = new Mock <FlowController>(new Mock <IPopupController>().Object);
            flowController.Protected().Setup("StartDecisionWizard", ItExpr.IsAny <IEnvironmentModel>(), ItExpr.IsAny <string>()).Verifiable();

            #endregion

            flowController.Object.Handle(new ConfigureDecisionExpressionMessage {
                ModelItem = source.Object, EnvironmentModel = env.Object, IsNew = false
            });

            flowController.Protected().Verify("StartDecisionWizard", Times.Once(), ItExpr.IsAny <IEnvironmentModel>(), ItExpr.IsAny <string>());
        }
Exemple #5
0
 public static void MyClassInitialize(TestContext testContext)
 {
     EnviromentRepositoryTest.MyClassInitialize(testContext);
 }
Exemple #6
0
        public void FlowController_ConfigureSwitch_Handle_Switch()
        {
            //------------Setup for test--------------------------
            var popupController = new Mock <IPopupController>();

            CustomContainer.Register(popupController.Object);

            var env = EnviromentRepositoryTest.CreateMockEnvironment();

            var properties         = new Dictionary <string, Mock <ModelProperty> >();
            var propertyCollection = new Mock <ModelPropertyCollection>();
            var testAct            = new DsfFlowSwitchActivity {
                ExpressionText = ""
            };

            var prop = new Mock <ModelProperty>();

            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Expression", prop);

            propertyCollection.Protected().Setup <ModelProperty>("Find", "Expression", true).Returns(prop.Object);

            var source = new Mock <ModelItem>();

            source.Setup(s => s.Properties).Returns(propertyCollection.Object);

            #region setup decision Mock ModelItem

            var crmSwitch = new Mock <IContextualResourceModel>();
            crmSwitch.Setup(r => r.Environment).Returns(env.Object);
            crmSwitch.Setup(r => r.ResourceName).Returns("Test");
            crmSwitch.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));

            var switchProperties         = new Dictionary <string, Mock <ModelProperty> >();
            var switchPropertyCollection = new Mock <ModelPropertyCollection>();

            var switchProp = new Mock <ModelProperty>();
            switchProp.Setup(p => p.ComputedValue).Returns(string.Empty);
            switchProperties.Add("Expression", switchProp);

            switchPropertyCollection.Protected().Setup <ModelProperty>("Find", "Expression", true).Returns(switchProp.Object);

            var switchModelItem = new Mock <ModelItem>();
            switchModelItem.Setup(s => s.Properties).Returns(switchPropertyCollection.Object);
            switchModelItem.Setup(s => s.ItemType).Returns(typeof(FlowSwitch <string>));

            prop.Setup(p => p.Value).Returns(switchModelItem.Object);

            #endregion

            #region setup Environment Model

            env.Setup(c => c.Connection).Returns(new Mock <IEnvironmentConnection>().Object);

            #endregion

            var flowController = new FlowController();

            var message = new ConfigureSwitchExpressionMessage
            {
                ModelItem = source.Object,
                Server    = env.Object,
                IsNew     = true
            };
            //------------Execute Test---------------------------
            flowController.Handle(message);
            //------------Assert Results-------------------------
        }
        public void SwitchDesignerViewModel_DisplayName_Setup_HasValue()
        {
            //------------Setup for test--------------------------
            #region setup first Mock ModelItem
            var popupController = new Mock <IPopupController>();
            CustomContainer.Register(popupController.Object);

            var env = EnviromentRepositoryTest.CreateMockEnvironment();

            var properties         = new Dictionary <string, Mock <ModelProperty> >();
            var propertyCollection = new Mock <ModelPropertyCollection>();
            var testAct            = new DsfFlowDecisionActivity {
                ExpressionText = "Not Null Test Value"
            };

            var prop = new Mock <ModelProperty>();
            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Condition", prop);

            propertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(prop.Object);

            var mockModelItem = new Mock <ModelItem>();
            mockModelItem.Setup(s => s.Properties).Returns(propertyCollection.Object);

            #endregion

            #region setup decision Mock ModelItem

            var crmDecision = new Mock <IContextualResourceModel>();
            crmDecision.Setup(r => r.Environment).Returns(env.Object);
            crmDecision.Setup(r => r.ResourceName).Returns("Test");
            crmDecision.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));

            var decisionProperties         = new Dictionary <string, Mock <ModelProperty> >();
            var decisionPropertyCollection = new Mock <ModelPropertyCollection>();

            var decisionProp = new Mock <ModelProperty>();
            decisionProp.Setup(p => p.ComputedValue).Returns(string.Empty);
            decisionProperties.Add("Condition", decisionProp);

            decisionPropertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(decisionProp.Object);

            var decisionModelItem = new Mock <ModelItem>();
            decisionModelItem.Setup(s => s.Properties).Returns(decisionPropertyCollection.Object);
            decisionModelItem.Setup(s => s.ItemType).Returns(typeof(FlowDecision));

            prop.Setup(p => p.Value).Returns(decisionModelItem.Object);

            #endregion

            #region setup Environment Model

            env.Setup(c => c.Connection).Returns(new Mock <IEnvironmentConnection>().Object);

            #endregion

            //------------Execute Test---------------------------
            var switchDesigner = new SwitchDesignerViewModel(mockModelItem.Object, "TrueArm");

            //------------Assert Results-------------------------
            Assert.IsNotNull(switchDesigner);
            Assert.AreEqual("TrueArm", switchDesigner.DisplayText);
        }
        public void SwitchDesignerViewModel_UpdateHelp_ShouldCallToHelpViewMode()
        {
            //------------Setup for test--------------------------
            var mockMainViewModel = new Mock <IShellViewModel>();
            var mockHelpViewModel = new Mock <IHelpWindowViewModel>();

            mockHelpViewModel.Setup(model => model.UpdateHelpText(It.IsAny <string>())).Verifiable();
            mockMainViewModel.Setup(model => model.HelpViewModel).Returns(mockHelpViewModel.Object);
            CustomContainer.Register(mockMainViewModel.Object);

            #region setup first Mock ModelItem
            var popupController = new Mock <IPopupController>();
            CustomContainer.Register(popupController.Object);

            var env = EnviromentRepositoryTest.CreateMockEnvironment();

            var properties         = new Dictionary <string, Mock <ModelProperty> >();
            var propertyCollection = new Mock <ModelPropertyCollection>();
            var testAct            = new DsfFlowDecisionActivity {
                ExpressionText = "Not Null Test Value"
            };

            var prop = new Mock <ModelProperty>();
            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Condition", prop);

            propertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(prop.Object);

            var mockModelItem = new Mock <ModelItem>();
            mockModelItem.Setup(s => s.Properties).Returns(propertyCollection.Object);

            #endregion

            #region setup decision Mock ModelItem

            var crmDecision = new Mock <IContextualResourceModel>();
            crmDecision.Setup(r => r.Environment).Returns(env.Object);
            crmDecision.Setup(r => r.ResourceName).Returns("Test");
            crmDecision.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));

            var decisionProperties         = new Dictionary <string, Mock <ModelProperty> >();
            var decisionPropertyCollection = new Mock <ModelPropertyCollection>();

            var decisionProp = new Mock <ModelProperty>();
            decisionProp.Setup(p => p.ComputedValue).Returns(string.Empty);
            decisionProperties.Add("Condition", decisionProp);

            decisionPropertyCollection.Protected().Setup <ModelProperty>("Find", "Condition", true).Returns(decisionProp.Object);

            var decisionModelItem = new Mock <ModelItem>();
            decisionModelItem.Setup(s => s.Properties).Returns(decisionPropertyCollection.Object);
            decisionModelItem.Setup(s => s.ItemType).Returns(typeof(FlowSwitch <string>));

            prop.Setup(p => p.Value).Returns(decisionModelItem.Object);

            #endregion

            #region setup Environment Model

            env.Setup(c => c.Connection).Returns(new Mock <IEnvironmentConnection>().Object);

            #endregion

            var switchDesigner = new SwitchDesignerViewModel(mockModelItem.Object, "");
            //------------Execute Test---------------------------
            switchDesigner.UpdateHelpDescriptor("help");
            //------------Assert Results-------------------------
            mockHelpViewModel.Verify(model => model.UpdateHelpText(It.IsAny <string>()), Times.Once());
        }