コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        public void ExceptionIsThrownWhenFullNameIsEmptyWhenGettingWriter(string fullName)
        {
            // Arrange

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

            // Act, Assert

            Assert.Throws <ArgumentException>(() =>
                                              service.Write(new DocumentMetadata[0], fullName));
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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));
            }
        }