protected StudioResourceRepository CreateModels(bool isChecked, Mock<IContextualResourceModel> mockResourceModel, out IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm, out IExplorerItemModel rootItem)
        {
            Mock<IContextualResourceModel> resourceModel = mockResourceModel;

            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            rootItem = serverItemModel;
            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = ResourceType.Folder, ResourcePath = "WORKFLOWS", EnvironmentId = mockEnvironmentModel.Object.ID, ResourceId = Guid.NewGuid() };
            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, _Invoke);
            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            resourceVm = workflowsFolder.Children[0];
            resourceVm.IsChecked = isChecked;
            return studioResourceRepository;
        }
示例#2
0
        public void DeployViewModelConnectWithServerExpectedDoesNotDisconnectOtherServers()
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var sourceConn = Mock.Get(source.Object.Connection);
            sourceConn.Setup(c => c.Disconnect()).Verifiable();

            var e1 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c1 = Mock.Get(e1.Object.Connection);
            c1.Setup(c => c.Disconnect()).Verifiable();
            var s1 = e1.Object;

            var e2 = EnviromentRepositoryTest.CreateMockEnvironment();
            var c2 = Mock.Get(e2.Object.Connection);
            c2.Setup(c => c.Disconnect()).Verifiable();
            var s2 = e2.Object;

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { s1, s2 });

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var studioResourceRepository = new Mock<IStudioResourceRepository>();
            studioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>());

            var deployViewModel = new DeployViewModel(new TestAsyncWorker(), serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, null, null, null, new Mock<IConnectControlSingleton>().Object);



            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);

            deployViewModel.SelectedSourceServer = s1;
            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());

            deployViewModel.SelectedDestinationServer = s2;
            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());

            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);
        }
        protected static DeployStatsCalculator SetupDeployViewModel(out DeployViewModel deployViewModel)
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var destination = EnviromentRepositoryTest.CreateMockEnvironment();

            source.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            destination.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { source.Object, destination.Object });

            var repo = new TestEnvironmentRespository(source.Object, destination.Object);

            var deployStatsCalculator = new DeployStatsCalculator();
            IExplorerItemModel resourceVm;
            var studioResourceRepository = CreateModels(false, source.Object, out resourceVm);

            deployViewModel = new DeployViewModel(AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, deployStatsCalculator)
            {
                SelectedSourceServer = source.Object,
                SelectedDestinationServer = destination.Object
            };
            return deployStatsCalculator;
        }
        public void EnvironmentRepositoryFindWithNonMatchingCriteriaExpectedReturnsEmptyList()
        {
            var source = CreateMockEnvironment();
            var e1 = CreateMockEnvironment();
            var e2 = CreateMockEnvironment();

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var actual = repo.Find(e => e.ID == Guid.NewGuid()).ToList();

            Assert.AreEqual(0, actual.Count);
        }
        public void EnvironmentRepositorySaveWithSingleItemExpectedDoesNotInvokesWriteSession()
        {
            var source = new Mock<IEnvironmentModel>();
            var e1 = new Mock<IEnvironmentModel>();

            var repo = new TestEnvironmentRespository(source.Object);

            repo.Save(e1.Object);
            Assert.AreEqual(0, repo.WriteSessionHitCount);
        }
        public void StudioResourceRepository_AddServerNode_Existing_ItemExpandedAndSelected()
        {
            //------------Setup for test--------------------------
            Mock<IContextualResourceModel> resourceModel = new Mock<IContextualResourceModel>();
            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            var environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = ResourceType.Folder, ResourcePath = "WORKFLOWS", EnvironmentId = mockEnvironmentModel.Object.ID, ResourceId = Guid.NewGuid() };
            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, _invoke);
            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            new EnvironmentRepository(testEnvironmentRespository);
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            ExplorerItemModel serverExplorerItem = new ExplorerItemModel(studioResourceRepository, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, new Mock<IConnectControlSingleton>().Object) { EnvironmentId = Guid.NewGuid(), ResourceType = ResourceType.Server };
            studioResourceRepository.AddServerNode(serverExplorerItem);
            //------------Execute Test---------------------------
            studioResourceRepository.AddServerNode(serverExplorerItem);
            //------------Assert Results-------------------------
            Assert.AreEqual(2, studioResourceRepository.ExplorerItemModels.Count);
            Assert.IsTrue(studioResourceRepository.ExplorerItemModels[1].IsExplorerSelected);
            Assert.IsTrue(studioResourceRepository.ExplorerItemModels[1].IsExplorerExpanded);
        }
        protected static StudioResourceRepository CreateModels(bool isChecked, IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm)
        {
            Mock<IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, Guid.NewGuid());
            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = Common.Interfaces.Data.ResourceType.Server, EnvironmentId = environmentModel.ID, ResourceId = Guid.NewGuid(), ResourcePath = "" };

            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = Common.Interfaces.Data.ResourceType.Folder, ResourcePath = "WORKFLOWS", ResourceId = Guid.NewGuid(), EnvironmentId = environmentModel.ID };

            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, Invoke);

            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            resourceModel.Setup(a => a.ServerID).Returns(environmentModel.ID);
            var env = new Mock<IEnvironmentModel>();
            resourceModel.Setup(a => a.Environment).Returns(env.Object);
            env.Setup(a => a.ID).Returns(environmentModel.ID);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            resourceVm = workflowsFolder.Children[0];
            resourceVm.IsChecked = isChecked;
            return studioResourceRepository;
        }
        public void EnvironmentRepositoryFindSingleWithNullExpectedReturnsNull()
        {
            var source = CreateMockEnvironment();
            var e1 = CreateMockEnvironment();
            var e2 = CreateMockEnvironment();

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var actual = repo.FindSingle(null);
            Assert.IsNull(actual);
        }
 static Mock<IContextualResourceModel> SetupResourceModel()
 {
     RootWebSite.IsTestMode = true;
     Mock<IEnvironmentModel> environment = new Mock<IEnvironmentModel>();
     environment.SetupGet(r => r.Name).Returns("localhost");
     Mock<IEnvironmentConnection> connection = new Mock<IEnvironmentConnection>();
     connection.SetupGet(e => e.AppServerUri).Returns(new Uri("http://www.azure.com"));
     environment.SetupGet(r => r.Connection).Returns(connection.Object);
     var testEnvRepo = new TestEnvironmentRespository(environment.Object);
     // ReSharper disable ObjectCreationAsStatement
     new EnvironmentRepository(testEnvRepo);
     // ReSharper restore ObjectCreationAsStatement
     EventPublishers.Aggregator = new Mock<IEventAggregator>().Object;
     var resourceModel = new Mock<IContextualResourceModel>();
     resourceModel.SetupGet(m => m.Environment).Returns(environment.Object);
     resourceModel.SetupGet(m => m.Category).Returns("MyFolder");
     return resourceModel;
 }
        public void EnvironmentRepositoryRemoveWithSingleItemExpectedDisconnectsAndRemovesItem()
        {
            var source = new Mock<IEnvironmentModel>();
            var c1 = CreateMockConnection();
            var c2 = CreateMockConnection();
            var c3 = CreateMockConnection();

            c1.Setup(c => c.Disconnect()).Verifiable();
            c2.Setup(c => c.Disconnect()).Verifiable();
            c3.Setup(c => c.Disconnect()).Verifiable();

            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);

            var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3);

            repo.Remove(e2);
            var actual = repo.All().ToList();

            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Once());
            c3.Verify(c => c.Disconnect(), Times.Never());

            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual(1, repo.RemoveInternalHitCount);
            Assert.AreSame(source.Object, actual[0]);
            Assert.AreSame(e1, actual[1]);
            Assert.AreSame(e3, actual[2]);
        }
        public void EnvironmentRepositoryWriteSessionWithNonExistingFileExpectedCreatesFile()
        {
            var path = EnvironmentRepository.GetEnvironmentsFilePath();
            var bakPath = RetryUtility.RetryMethod(() => BackupFile(path), 15, 1000, null);

            var source = new Mock<IEnvironmentModel>();
            var repo = new TestEnvironmentRespository(source.Object) { IsReadWriteEnabled = true };
            repo.WriteSession(null);

            var exists = File.Exists(path);
            Assert.AreEqual(true, exists);

            // ReSharper disable ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => DeleteFile(path), 15, 1000);
            // ReSharper restore ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => RestoreFile(path, bakPath), 15, 1000);
        }
        public void EnvironmentRepositoryRemoveWithManyItemsExpectedDisconnectsAndRemovesItems()
        {
            // DO NOT use mock as test requires IEquatable of IEnvironmentModel

            var source = new Mock<IEnvironmentModel>();
            var c1 = CreateMockConnection();
            var c2 = CreateMockConnection();
            var c3 = CreateMockConnection();

            c1.Setup(c => c.Disconnect()).Verifiable();
            c2.Setup(c => c.Disconnect()).Verifiable();
            c3.Setup(c => c.Disconnect()).Verifiable();

            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);

            var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3);

            repo.Remove(new List<IEnvironmentModel> { e1, e3 });
            var actual = repo.All().ToList();

            c1.Verify(c => c.Disconnect(), Times.Once());
            c2.Verify(c => c.Disconnect(), Times.Never());
            c3.Verify(c => c.Disconnect(), Times.Once());

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual(2, repo.RemoveInternalHitCount);
            Assert.AreSame(source.Object, actual[0]);
            Assert.AreSame(e2, actual[1]);
        }
        public void EnvironmentRepositoryRemoveWithManyItemsExpectedDoesNotInvokesWriteSession()
        {
            var source = new Mock<IEnvironmentModel>();
            var e1 = new Mock<IEnvironmentModel>();
            var e2 = new Mock<IEnvironmentModel>();

            var repo = new TestEnvironmentRespository(source.Object);

            repo.Remove(new List<IEnvironmentModel> { e1.Object, e2.Object });
            Assert.AreEqual(0, repo.WriteSessionHitCount);
        }
        public void EnvironmentRepositoryReadSessionWithOneEnvironmentExpectedReturnsOneEnvironment()
        {
            var path = EnvironmentRepository.GetEnvironmentsFilePath();
            var bakPath = RetryUtility.RetryMethod(() => BackupFile(path), 15, 1000, null);

            var source = new Mock<IEnvironmentModel>();
            var repo = new TestEnvironmentRespository(source.Object) { IsReadWriteEnabled = true };
            repo.WriteSession(new List<Guid> { Guid.NewGuid() });
            var result = repo.ReadSession();

            Assert.AreEqual(1, result.Count);

            // ReSharper disable ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => DeleteFile(path), 15, 1000);
            // ReSharper restore ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => RestoreFile(path, bakPath), 15, 1000);
        }
        public void EnvironmentRepositoryReadSessionWithNonExistingFileExpectedReturnsEmptyList()
        {
            var path = EnvironmentRepository.GetEnvironmentsFilePath();
            var bakPath = RetryUtility.RetryMethod(() => BackupFile(path), 15, 1000, null);

            var source = new Mock<IEnvironmentModel>();
            var repo = new TestEnvironmentRespository(source.Object) { IsReadWriteEnabled = true };
            var result = repo.ReadSession();

            Assert.AreEqual(0, result.Count);

            RetryUtility.RetryAction(() => RestoreFile(path, bakPath), 15, 1000);
        }
        public void EnvironmentRepositoryFindWithNullExpectedReturnsEmptyList()
        {
            var source = CreateMockEnvironment();
            var e1 = CreateMockEnvironment();
            var e2 = CreateMockEnvironment();

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var actual = repo.Find(null);

            Assert.AreEqual(0, actual.Count);
        }
        public void EnvironmentRepositorySaveWithSingleNullExpectedDoesNothing()
        {
            var source = new Mock<IEnvironmentModel>();

            var repo = new TestEnvironmentRespository(source.Object);
            var startCount = repo.All().Count;

            repo.Save((ICollection<IEnvironmentModel>)null);
            Assert.AreEqual(startCount, repo.All().Count);
            Assert.AreEqual(0, repo.AddInternalHitCount);
            Assert.AreEqual(0, repo.WriteSessionHitCount);
        }
        public void EnvironmentRepositoryRemoveWithSingleItemExpectedDoesNotInvokesWriteSession()
        {
            var source = new Mock<IEnvironmentModel>();
            var c1 = CreateMockConnection();
            var c2 = CreateMockConnection();
            var c3 = CreateMockConnection();

            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);

            var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3);

            repo.Remove(e1);
            Assert.AreEqual(0, repo.WriteSessionHitCount);
        }
        public void EnvironmentRepositoryWriteSessionWithExistingFileExpectedOverwritesFile()
        {
            var path = EnvironmentRepository.GetEnvironmentsFilePath();
            var bakPath = RetryUtility.RetryMethod(() => BackupFile(path), 15, 1000, null);

            var c1 = CreateMockConnection();
            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var repo = new TestEnvironmentRespository(e1) { IsReadWriteEnabled = true };

            // Create file
            repo.WriteSession(new List<Guid> { Guid.NewGuid() });

            var xml = XElement.Load(path);
            var actual = xml.Descendants("Environment").Count();
            Assert.AreEqual(1, actual);

            // Overwrite file
            repo.WriteSession(new List<Guid> { Guid.NewGuid(), Guid.NewGuid() });

            xml = XElement.Load(path);
            actual = xml.Descendants("Environment").Count();
            Assert.AreEqual(2, actual);

            // ReSharper disable ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => DeleteFile(path), 15, 1000);
            // ReSharper restore ImplicitlyCapturedClosure
            RetryUtility.RetryAction(() => RestoreFile(path, bakPath), 15, 1000);
        }
        public void EnvironmentRepositoryRemoveWithSingleNonExistingItemExpectedDoesNotRemoveItem()
        {
            var source = new Mock<IEnvironmentModel>();
            var c1 = CreateMockConnection();
            var c2 = CreateMockConnection();
            var c3 = CreateMockConnection();

            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);
            var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object);

            var repo = new TestEnvironmentRespository(source.Object, e1, e2);
            var startCount = repo.All().Count;

            repo.Remove(e3);

            Assert.AreEqual(startCount, repo.All().Count);
            Assert.AreEqual(1, repo.RemoveInternalHitCount);
            Assert.AreEqual(0, repo.WriteSessionHitCount);
        }
 public void EnvironmentRepository_Fetch_NotFound_ReturnsEnvironment()
 {
     //------------Setup for test--------------------------
     var c1 = CreateMockConnection();
     var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object);
     var source = new Mock<IEnvironmentModel>();
     var repo = new TestEnvironmentRespository(source.Object);
     repo.Save(e1);
     //------------Execute Test---------------------------
     var environmentModel = repo.Fetch(new Mock<IEnvironmentModel>().Object);
     //------------Assert Results-------------------------
     Assert.IsNotNull(environmentModel);
 }
        public void EnvironmentRepositorySaveWithManyItemsExpectedAddsItems()
        {
            var source = new Mock<IEnvironmentModel>();
            var e1 = new Mock<IEnvironmentModel>();
            var e2 = new Mock<IEnvironmentModel>();

            var repo = new TestEnvironmentRespository(source.Object);
            var startCount = repo.All().Count;

            repo.Save(new List<IEnvironmentModel> { e1.Object, e2.Object });
            Assert.AreEqual(startCount + 2, repo.All().Count);
            Assert.AreEqual(2, repo.AddInternalHitCount);
        }
 public void RootWebSite_ShowFileChooser_Environment_HasCorrectUri()
 {
     //------------Setup for test--------------------------
     RootWebSite.IsTestMode = true;
     Mock<IEnvironmentModel> environment = new Mock<IEnvironmentModel>();
     environment.Setup(model => model.Name).Returns("localhost");
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.DisplayName).Returns("localhost");
     mockConnection.Setup(connection => connection.AppServerUri).Returns(new Uri("http://localhost:3142"));
     environment.Setup(model => model.Connection).Returns(mockConnection.Object);
     var testEnvRepo = new TestEnvironmentRespository(environment.Object);
     // ReSharper disable ObjectCreationAsStatement
     new EnvironmentRepository(testEnvRepo);
     // ReSharper restore ObjectCreationAsStatement
     //------------Execute Test---------------------------
     RootWebSite.ShowFileChooser(environment.Object, new FileChooserMessage());
     //------------Assert Results-------------------------
     var result = RootWebSite.TestModeRelativeUri;
     Assert.AreEqual("dialogs/filechooser?envir=localhost+(http%3a%2f%2flocalhost%3a3142%2f)", result);
 }
        public void EnvironmentRepositorySaveWithSingleExistingItemExpectedReplacesItem()
        {
            // DO NOT use mock as test requires IEquatable of IEnvironmentModel
            var c1 = CreateMockConnection();
            //var wizard = new Mock<IWizardEngine>();
            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object);

            var source = new Mock<IEnvironmentModel>();
            var repo = new TestEnvironmentRespository(source.Object, e1);
            var startCount = repo.All().Count;

            repo.Save(e1);

            Assert.AreEqual(startCount, repo.All().Count);
        }
        public void StudioResourceRepository_AddResourceItem_ItemAdded()
        {
            //------------Setup for test--------------------------
            Mock<IContextualResourceModel> resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(model => model.DisplayName).Returns("some resource name");
            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            var environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            var rootItem = serverItemModel;
            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = ResourceType.Folder, ResourcePath = "WORKFLOWS", EnvironmentId = mockEnvironmentModel.Object.ID, ResourceId = Guid.NewGuid() };
            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, _invoke);
            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            new EnvironmentRepository(testEnvironmentRespository);
            resourceModel.Setup(a => a.Environment).Returns(mockEnvironmentModel.Object);
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            //------------Execute Test---------------------------
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            //------------Assert Results-------------------------
            Assert.AreEqual(1, rootItem.Children.Count);
            Assert.AreEqual(1, rootItem.Children[0].Children.Count);
        }
        public void EnvironmentRepositoryFindSingleWithNonMatchingCriteriaExpectedReturnsNull()
        {
            var source = CreateMockEnvironment();
            var e1 = CreateMockEnvironment();
            var e2 = CreateMockEnvironment();

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var actual = repo.FindSingle(e => e.ID == Guid.NewGuid());

            Assert.IsNull(actual);
        }
 public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_SetActiveEnvironmentOnClick_PublishEventsCorrectly()
 {
     TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(new Mock<IEnvironmentModel>().Object);
     // ReSharper disable once ObjectCreationAsStatement
     new EnvironmentRepository(testEnvironmentRespository);
     Verify_OnMouseDown_SetActiveEnvironmentOnClick(0, false);
     Verify_OnMouseDown_SetActiveEnvironmentOnClick(0, false);
     Verify_OnMouseDown_SetActiveEnvironmentOnClick(1, true);
 }
        public void EnvironmentRepositorySaveWithSingleItemExpectedAddsItem()
        {
            var source = new Mock<IEnvironmentModel>();
            var e1 = new Mock<IEnvironmentModel>();

            var repo = new TestEnvironmentRespository(source.Object);
            var startCount = repo.All().Count;

            repo.Save(e1.Object);
            Assert.AreEqual(startCount + 1, repo.All().Count);
            Assert.AreEqual(1, repo.AddInternalHitCount);
        }
        public void EnvironmentRepositorySaveWithSingleExpectedDoesNotConnect()
        {
            // DO NOT use mock as test requires IEquatable of IEnvironmentModel
            var c1 = CreateMockConnection();
            c1.Setup(c => c.Connect(It.IsAny<Guid>())).Verifiable();

            //var wizard = new Mock<IWizardEngine>();
            var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object);

            var source = new Mock<IEnvironmentModel>();
            var repo = new TestEnvironmentRespository(source.Object);

            repo.Save(e1);

            c1.Verify(c => c.Connect(It.IsAny<Guid>()), Times.Never());
        }
        public void EnvironmentRepositoryFindWithMatchingCriteriaExpectedReturnsMatchingList()
        {
            var source = CreateMockEnvironment();
            var e1 = CreateMockEnvironment();
            var e2 = CreateMockEnvironment();

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);
            var actual = repo.Find(e => e.ID == e1.Object.ID).ToList();

            Assert.AreEqual(1, actual.Count);
            Assert.AreSame(e1.Object, actual[0]);
        }