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 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());
        }
Example #3
0
        public void TestRemoveNonExistentDocument()
        {
            var session = new SessionBuilder().StartDefault().Build();

              Assert.DoesNotThrow(delegate()
              {
            session.RemoveDocument(new SessionDocumentBuilder().StartDefault().Build());
              });
        }
Example #4
0
        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);
        }
Example #5
0
        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());
        }
Example #6
0
        public void TestAddDuplicatedSession()
        {
            const string DUPLICATED_NAME = "S1";

              var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session newSession = new SessionBuilder().StartDefault(DUPLICATED_NAME).Build();
              manager.AddSession(newSession);
              Session newSession2 = new SessionBuilder().StartDefault(DUPLICATED_NAME).Build();
              manager.AddSession(newSession2);
        }
Example #7
0
        public void TestGetSession()
        {
            var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session otherSession = new SessionBuilder().StartDefault("S1").Build();
              Session expectedSession = new SessionBuilder().StartDefault("S2").Build();

              manager.AddSession(otherSession);
              manager.AddSession(expectedSession);

              var actualSession = manager.GetSession(expectedSession.Name);

              Assert.AreSame(expectedSession, actualSession);
        }
Example #8
0
        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);
        }
Example #9
0
        public void TestDeleteSessions()
        {
            var sessionToDelete = new SessionBuilder().StartDefault().Build();

              var sessionManagerMock = new Mock<ISessionManager>();
              sessionManagerMock.Setup(sm => sm.GetSessions()).Returns(new List<Session>());
              sessionManagerMock.Setup(sm => sm.GetSession(It.IsAny<string>())).Returns(sessionToDelete);
              sessionManagerMock.Setup(sm => sm.CurrentSession).Returns(sessionToDelete);

              var viewAdapterMock = new Mock<IViewAdapter>();
              viewAdapterMock.Setup(va => va.GetSessionsForDelete(It.IsAny<IList<SessionDto>>()))
            .Returns(new List<SessionDto>()
            {
              new SessionDto()
            });

              var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object,
            null, null);
              controller.DeleteSessions();

              sessionManagerMock.Verify(sm => sm.RemoveSession(sessionToDelete), Times.Once());
              sessionManagerMock.Verify(sm => sm.Persist(), Times.Once());
        }
Example #10
0
        public void TestGetSessionNames()
        {
            var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session newSession = new SessionBuilder().StartDefault("S1").Build();
              manager.AddSession(newSession);

              newSession = new SessionBuilder().StartDefault("S2").Build();
              manager.AddSession(newSession);

              newSession = new SessionBuilder().StartDefault("S3").Build();
              manager.AddSession(newSession);

              var names = manager.GetSessionNames();

              const int QTY_SESSIONS_ADDED = 3;

              Assert.AreEqual(QTY_SESSIONS_ADDED, names.Count());

              Assert.AreEqual(1, names.Where(n => n.Equals("S1")).Count());
              Assert.AreEqual(1, names.Where(n => n.Equals("S2")).Count());
              Assert.AreEqual(1, names.Where(n => n.Equals("S3")).Count());
        }
Example #11
0
        public void TestPersistWithRollback()
        {
            Session s1 = new SessionBuilder().StartDefault("S1").Build();

              var mockUnitOfWork = new Mock<IUnitOfWork>();
              mockUnitOfWork.Setup(uow => uow.Commit()).Throws(new Exception(STR_ExceptionOnCommitForTestingPurposes));

              var mockRepository = new Mock<ISessionRepository>();
              mockRepository.Setup(sm => sm.GetUnitOfWork()).Returns(mockUnitOfWork.Object);

              var manager = new SessionManager(mockRepository.Object);
              manager.AddSession(s1);

              manager.Persist();

              mockUnitOfWork.Verify(uow => uow.Rollback(), Times.Once());
        }
Example #12
0
        public void TestRemoveNonExistentSession()
        {
            var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session newSession = new SessionBuilder().StartDefault().Build();

              manager.RemoveSession(newSession);
        }
        public void TestSaveMoreThanOneSession()
        {
            var repo = new XmlSessionRepository();
              var uow = repo.GetUnitOfWork();
              var session1 = new SessionBuilder().StartDefault("session1").Build();
              var session2 = new SessionBuilder().StartDefault("session2").Build();
              uow.RegisterSavedOrUpdated(session1);
              uow.RegisterSavedOrUpdated(session2);
              uow.Commit();

              repo = new XmlSessionRepository();
              var sessionsInRepo = repo.GetAllSessions();
              Assert.AreEqual(2, sessionsInRepo.Count());
              Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1)));
              Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session2)));
        }
Example #14
0
        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());
        }
Example #15
0
        public void TestSimpleAddRemoveSession()
        {
            var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session newSession = new SessionBuilder().StartDefault().Build();
              manager.AddSession(newSession);

              Assert.AreEqual(1, manager.GetSessions().Count());
              Assert.AreSame(newSession, manager.GetSessions().First());

              manager.RemoveSession(newSession);

              Assert.AreEqual(0, manager.GetSessions().Count());
        }
Example #16
0
 public void TestRemoveNullDocument()
 {
     var session = new SessionBuilder().StartDefault().Build();
       session.RemoveDocument(null);
 }
Example #17
0
        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());
        }
Example #18
0
        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());
        }
Example #19
0
 public void TestAddNullDocument()
 {
     var session = new SessionBuilder().StartDefault().Build();
       session.AddDocument(null);
 }
Example #20
0
        public void TestPersist()
        {
            Session s1 = new SessionBuilder().StartDefault("S1").Build();
              Session s2 = new SessionBuilder().StartDefault("S2").Build();
              Session s3 = new SessionBuilder().StartDefault("S3").Build();

              var mockUnitOfWork = new Mock<IUnitOfWork>();
              var mockRepository = new Mock<ISessionRepository>();
              mockRepository.Setup(sm => sm.GetUnitOfWork()).Returns(mockUnitOfWork.Object);

              var manager = new SessionManager(mockRepository.Object);
              manager.AddSession(s1);
              manager.AddSession(s2);
              manager.AddSession(s3);
              manager.RemoveSession(s3);
              manager.CurrentSession = s1;

              manager.Persist();

              mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is<Session>(o => o.Equals(s1))), Times.Once());
              mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is<Session>(o => o.Equals(s2))), Times.Once());
              mockUnitOfWork.Verify(uow => uow.RegisterRemoved(It.Is<Session>(o => o.Equals(s3))), Times.Once());
              mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is<CurrentSessionInfo>(o => o.CurrentSessionName.Equals(s1.Name))), Times.Once());
              mockUnitOfWork.Verify(uow => uow.Commit(), Times.Once());
        }
Example #21
0
        public void TestLoadSession()
        {
            var sessionToLoad = new SessionBuilder().StartDefault().Build();

              var sessionManagerMock = new Mock<ISessionManager>();
              sessionManagerMock.Setup(sm => sm.GetSessions()).Returns(new List<Session>());
              sessionManagerMock.Setup(sm => sm.GetSession(It.IsAny<string>())).Returns(sessionToLoad);

              var viewAdapterMock = new Mock<IViewAdapter>();
              viewAdapterMock.Setup(va => va.GetSessionForLoading(It.IsAny<IList<SessionDto>>())).Returns(new SessionDto());

              var dteAdapterMock = new Mock<IDteAdapter>();
              dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List<IDteWindowAdapter>());

              var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object,
            dteAdapterMock.Object, null);
              controller.LoadSession();

              sessionManagerMock.VerifySet(sm => sm.CurrentSession = sessionToLoad, Times.Once());
        }
Example #22
0
        public void TestSetCurrentSessionByName()
        {
            var mock = new Mock<ISessionRepository>();
              var manager = new SessionManager(mock.Object);

              Session newSession = new SessionBuilder().StartDefault().Build();
              manager.AddSession(newSession);

              Assert.IsNull(manager.CurrentSession);

              bool result = manager.SetCurrentSessionByName(newSession.Name);

              Assert.AreSame(newSession, manager.CurrentSession);
              Assert.IsTrue(result);

              result = manager.SetCurrentSessionByName(newSession.Name);
              Assert.IsFalse(result);
        }
Example #23
0
        public void TestSaveSession()
        {
            var sessionToSave = new SessionBuilder().StartDefault().Build();

              var sessionManagerMock = new Mock<ISessionManager>();
              sessionManagerMock.Setup(sm => sm.CurrentSession).Returns(sessionToSave);

              var dsmSettings = new DsmSettingsBuilder().StartDefault().Build();
              var settingsManagerMock = new Mock<IDsmSettingsManager>();
              settingsManagerMock.Setup(st => st.DsmSettings).Returns(dsmSettings);

              var dteAdapterMock = new Mock<IDteAdapter>();
              dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List<IDteWindowAdapter>());

              var controller = new AddinController(sessionManagerMock.Object, settingsManagerMock.Object, null, dteAdapterMock.Object, null);
              controller.SaveSession();

              sessionManagerMock.Verify(sm => sm.Persist(), Times.Once());
        }
Example #24
0
        public void TestSaveSessionAsWithReplace()
        {
            const string SESSION_TO_REPLACE_NAME = "SESSION_TO_REPLACE_NAME";

              var sessionToReplace = new SessionBuilder().StartDefault(SESSION_TO_REPLACE_NAME).Build();
              var sessions = new List<Session>() { sessionToReplace };

              var sessionManagerMock = new Mock<ISessionManager>();
              sessionManagerMock.Setup(sm => sm.GetSessions()).Returns(sessions);
              sessionManagerMock.Setup(sm => sm.GetSession(SESSION_TO_REPLACE_NAME)).Returns(sessionToReplace);
              Session sessionToSave = null;
              sessionManagerMock.SetupSet(sm => sm.CurrentSession).Callback(delegate(Session s)
                                                                    {
                                                                      sessionToSave = s;
                                                                    });
              sessionManagerMock.Setup(sm => sm.CurrentSession).Returns(delegate()
                                                                {
                                                                  return sessionToSave;
                                                                });

              var viewAdapterMock = new Mock<IViewAdapter>();
              viewAdapterMock.Setup(va => va.GetSessionForSaveAs(It.IsAny<IList<SessionDto>>()))
            .Returns((IList<SessionDto> dtoList) => dtoList[0]); //<-- first session (sessionToReplace)

              var dteAdapterMock = new Mock<IDteAdapter>();
              dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List<IDteWindowAdapter>());

              var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object, dteAdapterMock.Object, null);
              controller.SaveSessionAs();

              sessionManagerMock.VerifySet(sm => sm.CurrentSession = sessionToSave, Times.Once());
              sessionManagerMock.Verify(sm => sm.Persist(), Times.Once());
        }
Example #25
0
        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());
        }
Example #26
0
        public void TestLoad()
        {
            Session s1 = new SessionBuilder().StartDefault("S1").Build();
              Session s2 = new SessionBuilder().StartDefault("S2").Build();
              Session s3 = new SessionBuilder().StartDefault("S3").Build();

              var mock = new Mock<ISessionRepository>();
              mock.Setup(repo => repo.GetAllSessions()).Returns(new List<Session>() { s1, s2, s3 });
              mock.Setup(repo => repo.GetCurrentSessionName()).Returns("S2");

              var manager = new SessionManager(mock.Object);

              manager.Load();

              var sessions = manager.GetSessions();

              Assert.AreEqual(3, sessions.Count());

              Assert.AreEqual(1, sessions.Where(s => s.Equals(s1)).Count());
              Assert.AreEqual(1, sessions.Where(s => s.Equals(s2)).Count());
              Assert.AreEqual(1, sessions.Where(s => s.Equals(s3)).Count());

              Assert.AreSame(s2, manager.CurrentSession);
        }