public void OutputDirectoryIsCreatedBeforeDataIsWritten()
        {
            // Arrange

            var directoryCreated            = false;
            var directoryCreatedBeforeWrite = false;

            using (var writer = Mock.Of <TextWriter>())
            {
                Mock.Get(writer)
                .Setup(w => w.WriteLine(It.IsAny <string>()))
                .Callback(() => directoryCreatedBeforeWrite = directoryCreated);

                var ioService = Mock.Of <IIOService>(s =>
                                                     s.GetWriter(It.IsAny <string>()) == writer);

                Mock.Get(ioService)
                .Setup(s => s.CreateDirectory(It.IsAny <string>()))
                .Callback(() => directoryCreated = true);

                var service = new PinnedItemStorageService(ioService);

                // Act

                service.Write(new DocumentMetadata[0], "FullName");

                // Assert

                Assert.IsTrue(directoryCreatedBeforeWrite);
            }
        }
        public void MetadataIsWritten()
        {
            // Arrange

            var metadata = new[]
            {
                new DocumentMetadata(
                    new DocumentMetadataInfo
                {
                    FullName           = "ItemFullName",
                    ProjectDisplayName = "ItemProjectDisplayName",
                    ProjectFullName    = "ItemProjectFullName"
                }, null, null)
            };

            using (var writer = new TestingTextWriter())
            {
                var ioService = Mock.Of <IIOService>(s =>
                                                     s.GetWriter(It.IsAny <string>()) == writer);

                var service = new PinnedItemStorageService(ioService);

                // Act

                service.Write(metadata, "FullName");

                // Assert

                Assert.AreEqual(
                    "[{\"FullName\":\"ItemFullName\",\"ProjectDisplayName\":\"ItemProjectDisplayName\",\"ProjectFullName\":\"ItemProjectFullName\"}]\r\n",
                    writer.WrittenData);
            }
        }
        public void OutputDirectoryIsCreated()
        {
            // Arrange

            using (var writer = new TestingTextWriter())
            {
                var ioService = Mock.Of <IIOService>(s =>
                                                     s.GetWriter(It.IsAny <string>()) == writer);

                var service = new PinnedItemStorageService(ioService);

                // Act

                service.Write(new DocumentMetadata[0], "FullName");

                // Assert

                var expectedPath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                    "WorkingFilesList");

                Mock.Get(ioService).Verify(s =>
                                           s.CreateDirectory(expectedPath));
            }
        }
        public void ExceptionIsThrownWhenFullNameIsEmptyWhenGettingWriter(string fullName)
        {
            // Arrange

            var service = new PinnedItemStorageService(
                Mock.Of <IIOService>());

            // Act, Assert

            Assert.Throws <ArgumentException>(() =>
                                              service.Write(new DocumentMetadata[0], fullName));
        }
        public void WriterIsDisposed()
        {
            // Arrange

            using (var writer = new TestingTextWriter())
            {
                var ioService = Mock.Of <IIOService>(s =>
                                                     s.GetWriter(It.IsAny <string>()) == writer);

                var service = new PinnedItemStorageService(ioService);

                // Act

                service.Write(new DocumentMetadata[0], "FullName");

                // Assert

                Assert.IsTrue(writer.DisposeInvoked);
            }
        }
        public void FullNameIsHashedWhenRequestingWriter()
        {
            // Arrange

            using (var writer = new TestingTextWriter())
            {
                var ioService = Mock.Of <IIOService>(s =>
                                                     s.GetWriter(It.IsAny <string>()) == writer);

                var service = new PinnedItemStorageService(ioService);

                // Act

                service.Write(new DocumentMetadata[0], FullName);

                // Assert

                Mock.Get(ioService).Verify(s =>
                                           s.GetWriter(_hashedPath));
            }
        }