public void WorkspaceItemRepositoryWorkspaceItemsExpectedInvokesReadFirstTime() { string resourceName; Guid workspaceID; Guid serverID; var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage { HasError = false }; msg.SetMessage("Workspace item updated"); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var model = CreateModel(ResourceType.Service, mockConn, out resourceName, out workspaceID, out serverID); var repositoryPath = GetUniqueRepositoryPath(); // Create repository file with one item in it var repository = new WorkspaceItemRepository(repositoryPath); repository.AddWorkspaceItem(model.Object); // Now create a new repository from the previous file repository = new WorkspaceItemRepository(repositoryPath); // Access items for the first time var items = repository.WorkspaceItems; Assert.AreEqual(1, items.Count); Assert.AreEqual(workspaceID, items[0].WorkspaceID); Assert.AreEqual(serverID, items[0].ServerID); Assert.AreEqual(resourceName, items[0].ServiceName); Assert.AreEqual(WorkspaceItem.ServiceServiceType, items[0].ServiceType); }
public void WorkspaceItemRepositoryAddWorkspaceItemWithExistingModelExpectedDoesNothing() { string resourceName; Guid workspaceID; Guid serverID; var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage(); msg.SetMessage("Workspace item updated"); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var model = CreateModel(ResourceType.Service, mockConn, out resourceName, out workspaceID, out serverID); var repository = new WorkspaceItemRepository(GetUniqueRepositoryPath()); repository.AddWorkspaceItem(model.Object); Assert.AreEqual(1, repository.WorkspaceItems.Count); repository.AddWorkspaceItem(model.Object); Assert.AreEqual(1, repository.WorkspaceItems.Count); }
public void WorkspaceItemRepositoryRemoveWithExistingModelExpectedInvokesWrite() { string resourceName; Guid workspaceID; Guid serverID; var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage(); msg.SetMessage("Workspace item updated"); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var mockResourceRepo = new Mock<IResourceRepository>(); mockResourceRepo.Setup(resourceRepository => resourceRepository.DeleteResourceFromWorkspace(It.IsAny<IContextualResourceModel>())); var model = CreateModel(ResourceType.Service, mockConn, out resourceName, out workspaceID, out serverID, mockResourceRepo); var repositoryPath = GetUniqueRepositoryPath(); Assert.IsFalse(File.Exists(repositoryPath)); var repository = new WorkspaceItemRepository(repositoryPath); repository.AddWorkspaceItem(model.Object); if(File.Exists(repositoryPath)) { File.Delete(repositoryPath); } repository.Remove(model.Object); Assert.IsTrue(File.Exists(repositoryPath)); mockResourceRepo.Verify(resourceRepository => resourceRepository.DeleteResourceFromWorkspace(It.IsAny<IContextualResourceModel>()), Times.Once()); }
public void WorkspaceItemRepositoryUpdateWorkspaceItemWithExistingModelExpectedInvokesExecuteCommand() { const string ExpectedResult = "Workspace item updated"; string resourceName; Guid workspaceID; Guid serverID; var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage(); msg.SetMessage("Workspace item updated"); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var model = CreateModel(ResourceType.Service, mockConn, out resourceName, out workspaceID, out serverID); #region Setup ImportService - GRRR! #endregion var repository = new WorkspaceItemRepository(GetUniqueRepositoryPath()); repository.AddWorkspaceItem(model.Object); var result = repository.UpdateWorkspaceItem(model.Object, true); mockConn.Verify(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>()), Times.Once()); Assert.AreEqual(ExpectedResult, result.Message.ToString()); }
public void WorkspaceItemRepositoryUpdateWorkspaceItemWithNonExistingModelExpectedDoesNothing() { string resourceName; Guid workspaceID; Guid serverID; var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage(); msg.SetMessage(""); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var model = CreateModel(ResourceType.Service, mockConn, out resourceName, out workspaceID, out serverID); var repository = new WorkspaceItemRepository(GetUniqueRepositoryPath()); var result = repository.UpdateWorkspaceItem(model.Object, true); Assert.IsTrue(string.IsNullOrEmpty(result.Message.ToString())); }
public void WorkspaceItemRepositoryUpdateWorkspaceItemWithNullModelExpectedThrowsArgumentNullException() { var repository = new WorkspaceItemRepository(GetUniqueRepositoryPath()); repository.UpdateWorkspaceItem(null, false); }
public void WorkspaceItemRepositoryAddWorkspaceItemWithNewModelWithSameNameExpectedInvokesWrite() { Guid workspaceID = Guid.NewGuid(); Guid serverID = Guid.NewGuid(); Guid envID = Guid.NewGuid(); var mockConn = new Mock<IEnvironmentConnection>(); mockConn.Setup(c => c.IsConnected).Returns(true); ExecuteMessage msg = new ExecuteMessage(); msg.SetMessage("Workspace item updated"); var payload = JsonConvert.SerializeObject(msg); mockConn.Setup(c => c.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(payload)).Verifiable(); var model1 = CreateModel(ResourceType.Service, mockConn, workspaceID, serverID, envID); workspaceID = Guid.NewGuid(); serverID = Guid.NewGuid(); envID = Guid.NewGuid(); var model2 = CreateModel(ResourceType.Service, mockConn, workspaceID, serverID, envID); var repositoryPath = GetUniqueRepositoryPath(); Assert.IsFalse(File.Exists(repositoryPath)); var repository = new WorkspaceItemRepository(repositoryPath); repository.AddWorkspaceItem(model1.Object); repository.AddWorkspaceItem(model2.Object); Assert.IsTrue(repository.WorkspaceItems.Count == 2); Assert.IsTrue(File.Exists(repositoryPath)); }
static void SetupImportServiceForPersistenceTests(Mock<IWorkspaceItemRepository> wsiRepo) { var workspaceItemRepository = new WorkspaceItemRepository(wsiRepo.Object); CustomContainer.Register<IWorkspaceItemRepository>(workspaceItemRepository); CustomContainer.Register(new Mock<IPopupController>().Object); }