public void TestSaveDocuments() { var repo = new XmlSessionRepository(); var uow = repo.GetUnitOfWork(); var session1 = new SessionBuilder().StartDefault("session1").Build(); var doc1 = new SessionDocumentBuilder().StartDefault("doc1").Build(); session1.AddDocument(doc1); var doc2 = new SessionDocumentBuilder().StartDefault("doc2").Build(); session1.AddDocument(doc2); uow.RegisterSavedOrUpdated(session1); uow.Commit(); repo = new XmlSessionRepository(); var sessionsInRepo = repo.GetAllSessions(); Assert.AreEqual(1, sessionsInRepo.Count()); Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1))); Assert.AreEqual(2, sessionsInRepo.First().GetDocuments().Count()); repo = new XmlSessionRepository(); uow = repo.GetUnitOfWork(); session1.RemoveDocument(doc1); uow.RegisterSavedOrUpdated(session1); uow.Commit(); repo = new XmlSessionRepository(); sessionsInRepo = repo.GetAllSessions(); Assert.AreEqual(1, sessionsInRepo.Count()); Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1))); Assert.AreEqual(1, sessionsInRepo.First().GetDocuments().Count()); }
public void TestAddDuplicatedDocument() { var session = new SessionBuilder().StartDefault().Build(); Assert.DoesNotThrow(delegate() { session.AddDocument(new SessionDocumentBuilder().StartDefault().Build()); session.AddDocument(new SessionDocumentBuilder().StartDefault().Build()); }); Assert.AreEqual(1, session.GetDocuments().Count()); }
public void TestCrud() { var repo = new XmlSessionRepository(); var uow = repo.GetUnitOfWork(); var session1 = new SessionBuilder().StartDefault("session1").Build(); uow.RegisterSavedOrUpdated(session1); uow.Commit(); repo = new XmlSessionRepository(); var sessionsInRepo = repo.GetAllSessions(); Assert.AreEqual(1, sessionsInRepo.Count()); Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1))); repo = new XmlSessionRepository(); uow = repo.GetUnitOfWork(); session1.AddDocument(new SessionDocumentBuilder().StartDefault("doc1").Build()); // <-- adding one document to modify something in the session uow.RegisterSavedOrUpdated(session1); uow.Commit(); repo = new XmlSessionRepository(); sessionsInRepo = repo.GetAllSessions(); Assert.AreEqual(1, sessionsInRepo.Count()); Assert.AreEqual(1, sessionsInRepo.First().GetDocuments().Count()); repo = new XmlSessionRepository(); uow = repo.GetUnitOfWork(); uow.RegisterRemoved(session1); uow.Commit(); repo = new XmlSessionRepository(); sessionsInRepo = repo.GetAllSessions(); Assert.AreEqual(0, sessionsInRepo.Count()); }
public void TestIsDirty() { var session = new SessionBuilder().StartDefault().Build(); var document = new SessionDocumentBuilder().StartDefault().Build(); session.AddDocument(document); session.IsDirty = false; session.RemoveDocument(document); Assert.IsTrue(session.IsDirty); }
public void TestRemoveAllDocuments() { var session = new SessionBuilder().StartDefault().Build(); session.IsDirty = false; session.RemoveAllDocuments(); Assert.IsFalse(session.IsDirty); var document = new SessionDocumentBuilder().StartDefault().Build(); session.AddDocument(document); session.IsDirty = false; session.RemoveAllDocuments(); Assert.AreEqual(0, session.GetDocuments().Count()); Assert.IsTrue(session.IsDirty); }
public void TestSimpleAddRemoveDocument() { var session = new SessionBuilder().StartDefault().Build(); session.AddDocument(new SessionDocumentBuilder().StartDefault("path1").Build()); session.AddDocument(new SessionDocumentBuilder().StartDefault("path2").Build()); var document = new SessionDocumentBuilder().StartDefault("path3").Build(); session.AddDocument(document); session.RemoveDocument(document); Assert.AreEqual(2, session.GetDocuments().Count()); }
public void TestAddNullDocument() { var session = new SessionBuilder().StartDefault().Build(); session.AddDocument(null); }
public void TestFillDocumentsInSession() { const string DOCUMENT_TO_ADD1 = "documentToAdd1"; const string DOCUMENT_TO_ADD2 = "documentToAdd2"; const string DOCUMENT_TO_ADD3 = "documentToAdd3"; const string DOCUMENT_DUPLICATED = "documentDuplicated"; var session = new SessionBuilder().StartDefault().Build(); session.AddDocument(new SessionDocumentBuilder().StartDefault("documentToRemove").Build()); session.AddDocument(new SessionDocumentBuilder().StartDefault(DOCUMENT_DUPLICATED).Build()); var dteWindowAdapterMock1 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock1.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD1); dteWindowAdapterMock1.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text); var dteWindowAdapterMock2 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock2.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD2); dteWindowAdapterMock2.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text); var dteWindowAdapterMock3 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock3.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD3); dteWindowAdapterMock3.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text); var dteWindowAdapterMock4 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock4.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_DUPLICATED); dteWindowAdapterMock4.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text); var dteAdapterMock = new Mock<IDteAdapter>(); dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns( new List<IDteWindowAdapter>() { dteWindowAdapterMock1.Object, dteWindowAdapterMock2.Object, dteWindowAdapterMock3.Object, dteWindowAdapterMock4.Object }); var sessionManagerMock = new Mock<ISessionManager>(); sessionManagerMock.Setup(sm => sm.CurrentSession).Returns((Session)null); var controller = new AddinController(sessionManagerMock.Object, null, null, dteAdapterMock.Object, null); controller.FillDocumentsInSession(session); IEnumerable<SessionDocument> documentsInSession = session.GetDocuments(); Assert.AreEqual(4, documentsInSession.Count()); Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD1)).Count()); Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD2)).Count()); Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD3)).Count()); Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_DUPLICATED)).Count()); }
public void TestLoadDocumentsFromSession_NonExistentDocument() { const string NON_EXISTENT_DOCUMENT = "NON_EXISTENT_DOCUMENT"; var sessionWithDocumentsToLoad = new SessionBuilder().StartDefault().Build(); var nonExistentDocument = new SessionDocumentBuilder().StartDefault(NON_EXISTENT_DOCUMENT).Build(); sessionWithDocumentsToLoad.AddDocument(nonExistentDocument); var dteAdapterMock = new Mock<IDteAdapter>(); dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List<IDteWindowAdapter>()); dteAdapterMock.Setup(da => da.FileExists(It.IsAny<string>())).Returns(false); var viewAdapterMock = new Mock<IViewAdapter>(); var sessionManagerMock = new Mock<ISessionManager>(); sessionManagerMock.Setup(sm => sm.CurrentSession).Returns((Session)null); var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object, dteAdapterMock.Object, null); controller.LoadDocumentsFromSession(sessionWithDocumentsToLoad); dteAdapterMock.Verify(da => da.OpenFile(It.IsAny<string>(), It.IsAny<DocumentType>()), Times.Never()); dteAdapterMock.Verify(da => da.FileExists(It.IsAny<string>()), Times.Once()); viewAdapterMock.Verify(va => va.ShowLongMessage(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once()); }
public void TestLoadDocumentsFromSession() { const string DOCUMENT_IN_SESSION_AND_IN_THE_IDE = "d1"; const string DOCUMENT_IN_SESSION = "d2"; const string DOCUMENT_IN_THE_IDE = "d3"; var sessionWithDocumentsToLoad = new SessionBuilder().StartDefault().Build(); var documentInSessionAndInTheIDE = new SessionDocumentBuilder().StartDefault(DOCUMENT_IN_SESSION_AND_IN_THE_IDE).Build(); sessionWithDocumentsToLoad.AddDocument(documentInSessionAndInTheIDE); var documentInSession = new SessionDocumentBuilder().StartDefault(DOCUMENT_IN_SESSION).Build(); sessionWithDocumentsToLoad.AddDocument(documentInSession); var dteWindowAdapterMock1 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock1.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_IN_SESSION_AND_IN_THE_IDE); dteWindowAdapterMock1.Setup(dwa => dwa.DocumentMatches(documentInSessionAndInTheIDE)).Returns(true); var dteWindowAdapterMock2 = new Mock<IDteWindowAdapter>(); dteWindowAdapterMock2.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_IN_THE_IDE); dteWindowAdapterMock2.Setup(dwa => dwa.DocumentMatches(It.IsAny<SessionDocument>())).Returns(false); dteWindowAdapterMock2.Setup(dwa => dwa.Close(It.Is<SaveChanges>(x => x == SaveChanges.Prompt))).Returns(true); var dteAdapterMock = new Mock<IDteAdapter>(); dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List<IDteWindowAdapter>() { dteWindowAdapterMock1.Object, dteWindowAdapterMock2.Object, }); dteAdapterMock.Setup(da => da.FileExists(It.IsAny<string>())).Returns(true); var viewAdapterMock = new Mock<IViewAdapter>(); var sessionManagerMock = new Mock<ISessionManager>(); sessionManagerMock.Setup(sm => sm.CurrentSession).Returns((Session)null); var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object, dteAdapterMock.Object, null); controller.LoadDocumentsFromSession(sessionWithDocumentsToLoad); dteAdapterMock.Verify(da => da.OpenFile(It.IsAny<string>(), It.IsAny<DocumentType>()), Times.Once()); }