AddResouceItem() public method

public AddResouceItem ( IContextualResourceModel resourceModel ) : void
resourceModel IContextualResourceModel
return void
        protected static StudioResourceRepository CreateModels(bool isChecked, out IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm)
        {
            Mock<IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, Guid.NewGuid());

            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            var env = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>());
            env.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            environmentModel = env.Object;
            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 = mockEnvironmentModel.Object.ID };

            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;
        }
        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);
        }