public void TestUnsupportedAttachments()
        {
            var unsupported = TestUtils.CreateAttachment("unsupported.vsd", "unsupported.vsd", "1");

            var model = new ProtectTaskPaneModel();
            model.AddAttachment(unsupported);
            var cache = new AttachmentsModelCache(model);

            bool attachmentAdded = false;
            model.StatusUpdate += (sender, args) =>
                                      {
                                          attachmentAdded = true;
                                      };

            SpinWait.SpinUntil(() => attachmentAdded, 30000);

            cache.ResetCache();
            Assert.IsTrue(cache.AnyAttachmentsOf(SearchModel.UnSupported));
        }
        public void TestAnyAttachmentsOfPasswordProtected()
        {
            var passwordProtected = TestUtils.CreateAttachment("password.pptx", "password.pptx", "1");
            
            var model = new ProtectTaskPaneModel();
            model.AddAttachment(passwordProtected);
            var cache = new AttachmentsModelCache(model);

            bool attachmentAdded = false;
            model.StatusUpdate += (sender, args) =>
            {
                attachmentAdded = true;
            };

            SpinWait.SpinUntil(() => attachmentAdded, 30000);

            cache.ResetCache();

            Assert.IsTrue(cache.AnyAttachmentsOf(SearchModel.PasswordProtected));
        }
        public void TestCloseTaskPaneCalled_02()
        {
            var supportsCleaning = TestUtils.CreateAttachment("SupportsCleaning.doc", "SupportsCleaning.doc", "1");

            var view = CreateViewMock();;
            view.Setup(x => x.CurrentPage).Returns(PageType.SupportedFiles);

            bool closeCalled = false;

            view.Setup(m => m.Close()).
                 Callback(() => closeCalled = true);
            var model = new ProtectTaskPaneModel();

            var presenter = new ProtectTaskPanePresenter(view.Object, model);
            presenter.AddAttachment(supportsCleaning);
            Assert.True(SpinWait.SpinUntil(() => presenter.Attachments.Count == 1, 30000));
            presenter.RemoveAttachment(supportsCleaning);

            SpinWait.SpinUntil(() => closeCalled, 30000);

            view.Verify(m => m.Close(), Times.Once());
        }
        public void TestCorrectPageShown_03()
        {
            var passwordProtected = TestUtils.CreateAttachment("password.docx", "password.docx", "1");
            var unsupported = TestUtils.CreateAttachment("unsupported.vsd", "unsupported.vsd", "3");

            var view = CreateViewMock();;
            view.Setup(x => x.CurrentPage).Returns(PageType.PasswordProtectedFiles);

            var pageShown = PageType.None;

            view.Setup(m => m.ShowPage(It.IsAny<PageType>())).
                 Callback((PageType value) => pageShown = value);

            var model = new ProtectTaskPaneModel();

            var presenter = new ProtectTaskPanePresenter(view.Object, model);
            presenter.AddAttachment(passwordProtected);
            presenter.AddAttachment(unsupported);
            Assert.True(SpinWait.SpinUntil(() => presenter.Attachments.Count == 2, 30000));
            presenter.RemoveAttachment(unsupported);

            Thread.Sleep(10000);

            view.Verify(m => m.ShowPage(PageType.SupportedFiles), Times.Never());
        }
        public void TestSupportedFilesShown_03()
        {
            var supportsCleaning1 = TestUtils.CreateAttachment("small.doc", "small.doc", "1");
            var supportsCleaning2 = TestUtils.CreateAttachment("SupportsCleaning.doc", "SupportsCleaning.doc", "2");

            var view = CreateViewMock();;
            view.Setup(x => x.CurrentPage).Returns(PageType.SupportedFiles);

            var pageShown = PageType.None;

            view.Setup(m => m.ShowPage(It.IsAny<PageType>())).
                 Callback((PageType value) => pageShown = value);

            var model = new ProtectTaskPaneModel();

            var presenter = new ProtectTaskPanePresenter(view.Object, model);
            presenter.AddAttachment(supportsCleaning1);
            presenter.AddAttachment(supportsCleaning2);

            presenter.RemoveAttachment(supportsCleaning1);

            Thread.Sleep(15000);

            view.Verify(m => m.ShowPage(PageType.SupportedFiles), Times.AtLeastOnce());
        }
        public void TestSupportedFilesShown_02()
        {
            var unsupported = TestUtils.CreateAttachment("unsupported.vsd", "unsupported.vsd", "1");
            var supportsCleaning = TestUtils.CreateAttachment("SupportsCleaning.doc", "SupportsCleaning.doc", "2");

            var view = CreateViewMock();;
            view.Setup(x => x.CurrentPage).Returns(PageType.UnsupportedFiles);

            var pageShown = PageType.None;

            view.Setup(m => m.ShowPage(It.IsAny<PageType>())).
                 Callback((PageType value) => pageShown = value);

            var model = new ProtectTaskPaneModel();

            var presenter = new ProtectTaskPanePresenter(view.Object, model);
            presenter.AddAttachment(unsupported);
            presenter.AddAttachment(supportsCleaning);
            Assert.True(SpinWait.SpinUntil(() => presenter.Attachments.Count == 2, 30000));
            presenter.RemoveAttachment(unsupported);

            SpinWait.SpinUntil(() => pageShown == PageType.SupportedFiles, 30000);

            view.Verify(m => m.ShowPage(PageType.SupportedFiles), Times.AtLeastOnce());
        }
 public AttachmentsModelCache(ProtectTaskPaneModel model)
 {
     _model = model;
 }