Exemple #1
0
        public void SingleFileOutputCssFileWritingUsingStreamWriterTest()
        {
            string path = Path.Combine(Path.GetTempPath(), "sf");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            var streamWriterFactory = new StreamWriterFactory();

            var settings = new AclExpanderApplicationSettings();

            settings.UseMultipleFileOutput = false;
            settings.Directory             = path;
            var application = new AclExpanderApplication(streamWriterFactory);

            application.Run(settings, TextWriter.Null, TextWriter.Null);

            // Single file HTML output => expect 2 files (CSS, HTML file)
            Assert.That(Directory.GetFiles(path).Length, Is.EqualTo(2));

            const string cssFileName = AclExpanderApplication.CssFileName;

            Assert.That(File.Exists(Path.Combine(path, Path.ChangeExtension(cssFileName, "css"))), Is.True);
        }
Exemple #2
0
        public void NewTextWriterWithNullDirectoryThrowsTest()
        {
            var streamWriterFactory = new StreamWriterFactory();

            streamWriterFactory.Directory = null;
            streamWriterFactory.CreateTextWriter("whatever");
        }
Exemple #3
0
        public void MultipleFileOutputCssFileWritingUsingStreamWriterTest()
        {
            string path = Path.Combine(Path.GetTempPath(), "mf");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            var streamWriterFactory = new StreamWriterFactory();

            var settings = new AclExpanderApplicationSettings();

            settings.UseMultipleFileOutput = true;
            settings.Directory             = path;
            var application = new AclExpanderApplication(streamWriterFactory);

            application.Run(settings, TextWriter.Null, TextWriter.Null);

            const string   cssFileName = AclExpanderApplication.CssFileName;
            TextWriterData cssTextWriterData;

            streamWriterFactory.NameToTextWriterData.TryGetValue(cssFileName, out cssTextWriterData);

            // Multifile HTML output => expect at least 3 files (CSS, main HTML, detail HTML files)
            Assert.That(Directory.GetFiles(cssTextWriterData.Directory).Length, Is.EqualTo(8));

            Assert.That(File.Exists(Path.Combine(cssTextWriterData.Directory, Path.ChangeExtension(cssFileName, "css"))), Is.True);
        }
Exemple #4
0
        public void MultipleFileOutputWritingTest()
        {
            var streamWriterFactory = new StreamWriterFactory();

            var settings = new AclExpanderApplicationSettings();

            settings.UseMultipleFileOutput = true;
            string path = Path.GetTempPath();
            //string path = "c:\\temp";
            string testDirectory = Path.Combine(path, "TestDirectory");

            settings.Directory = testDirectory;
            var application = new AclExpanderApplication(streamWriterFactory);

            application.Run(settings, TextWriter.Null, TextWriter.Null);

            string outputDirectory = streamWriterFactory.Directory;

            AssertFileExists(outputDirectory, "group0_user1.html");
            AssertFileExists(outputDirectory, "group0_user2.html");
            AssertFileExists(outputDirectory, "group1_user1.html");
            AssertFileExists(outputDirectory, "group1_user2.html");

            AssertFileExists(outputDirectory, "_AclExpansionMain_.html");
            AssertFileExists(outputDirectory, "AclExpansion.css");

            AssertFileExists(outputDirectory, "test.user.html");
        }
Exemple #5
0
        public void OverwriteCallsCreate()
        {
            var writer  = Mock.Of <Func <string, StreamWriter> >();
            var factory = new StreamWriterFactory(writer);

            factory.Overwrite("some path");
            Mock.Get(writer).Verify(a => a(It.Is <string>(s => s == "some path")), Times.Once);
        }
Exemple #6
0
        public void NewTextWriterNameAlreadyExistsTest()
        {
            const string textWriterName      = "abc";
            var          streamWriterFactory = new StreamWriterFactory();

            streamWriterFactory.Directory = "xyz";
            streamWriterFactory.CreateTextWriter(textWriterName);
            streamWriterFactory.CreateTextWriter(textWriterName);
        }
Exemple #7
0
        public void DefaultMethodIsCreate()
        {
            var factory = new StreamWriterFactory();
            Func <string, StreamWriter> val = factory.GetType()
                                              .GetField("CreateTextFile", BindingFlags.NonPublic | BindingFlags.Instance)
                                              .GetValue(factory) as Func <string, StreamWriter>;

            Assert.Equal(File.CreateText, val);
        }
        public void WhenCreate_WithPathAndAppend_ReturnsWrappedStreamWriter()
        {
            // Arrange
            var factory = new StreamWriterFactory();
            var path    = Path.GetTempFileName();

            // Act
            var result = factory.Create(path, true);

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.StreamWriterInstance);
        }
        public void WhenCreate_WithStreamWriter_ReturnsWrappedStreamWriter()
        {
            // Arrange
            var factory      = new StreamWriterFactory();
            var memoryStream = new StreamWriterWrap(new MemoryStream());

            // Act
            var result = factory.Create(memoryStream);

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(memoryStream.StreamWriterInstance, result.StreamWriterInstance);
        }
        public void WhenCreate_WithPathAppendEncodingAndBufferSize_ReturnsWrappedStreamWriter()
        {
            // Arrange
            var factory = new StreamWriterFactory();
            var path    = Path.GetTempFileName();

            // Act
            var result = factory.Create(path, false, Encoding.UTF8, 123);

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.StreamWriterInstance);
        }
Exemple #11
0
        public void NewTextWriterArgumentTest()
        {
            var          streamWriterFactory = new StreamWriterFactory();
            string       directory           = Path.Combine(Path.GetTempPath(), "StreamWriterFactoryTest_DirectoryTest");
            const string extension           = "xyz";
            const string fileName            = "someFile";

            using (StreamWriter streamWriter = (StreamWriter)streamWriterFactory.CreateTextWriter(directory, fileName, extension))
            {
                var    fileStream       = (FileStream)streamWriter.BaseStream;
                string filePathExpected = Path.Combine(directory, fileName + "." + extension);
                Assert.That(fileStream.Name, Is.EqualTo(filePathExpected));
            }
        }
        public void WhenCreate_WithStreamEncodingAndBufferSize_ReturnsWrappedStreamWriter()
        {
            // Arrange
            var factory      = new StreamWriterFactory();
            var memoryStream = new MemoryStreamWrap();

            // Act
            var result = factory.Create(memoryStream, Encoding.UTF8, 123);

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.StreamWriterInstance);
            Assert.AreEqual(memoryStream.StreamInstance, result.BaseStream);
        }