Пример #1
0
        public void OutputFileHelper_GetNewA11yTestFilePath_SpecificScanId_CreatesExpectedFileName()
        {
            var mockSystem    = new Mock <ISystem>(MockBehavior.Strict);
            var mockIO        = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(InertDateTime);
            mockSystem.Setup(x => x.Environment).Returns(InertEnvironment);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);

            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            string directory = @"c:\TestDir2";

            mockDirectory.Setup(x => x.Exists(directory)).Returns(true);

            var outputFileHelper = new OutputFileHelper(directory, mockSystem.Object);

            outputFileHelper.SetScanId("myScanId");
            var result = outputFileHelper.GetNewA11yTestFilePath();

            var expectedFileName = "myScanId.a11ytest";
            var actualFileName   = Path.GetFileName(result);

            Assert.AreEqual(expectedFileName, actualFileName);
            Assert.AreEqual(directory, Path.GetDirectoryName(result));

            mockSystem.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #2
0
        public void OutputFileHelperCtor_WithOutputDirectory_UsesProvidedDirectory()
        {
            var mockSystem    = new Mock <ISystem>(MockBehavior.Strict);
            var mockDateTime  = new Mock <ISystemDateTime>(MockBehavior.Strict);
            var mockIO        = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(mockDateTime.Object);
            mockSystem.Setup(x => x.Environment).Returns(InertEnvironment);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);
            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            mockDateTime.Setup(x => x.Now).Returns(DateTime.Now);

            string expectedDirectory = @"c:\TestDir";

            mockDirectory.Setup(x => x.Exists(expectedDirectory)).Returns(true);

            var    outputFileHelper = new OutputFileHelper(expectedDirectory, mockSystem.Object);
            string result           = outputFileHelper.GetNewA11yTestFilePath();

            Assert.AreEqual(expectedDirectory, Path.GetDirectoryName(result));

            mockSystem.VerifyAll();
            mockDateTime.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #3
0
        public void OutputFileHelperCtor_NullOutputDirectory_UsesEnvironment()
        {
            var mockSystem      = new Mock <ISystem>(MockBehavior.Strict);
            var mockDateTime    = new Mock <ISystemDateTime>(MockBehavior.Strict);
            var mockEnvironment = new Mock <ISystemEnvironment>(MockBehavior.Strict);
            var mockIO          = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory   = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(mockDateTime.Object);
            mockSystem.Setup(x => x.Environment).Returns(mockEnvironment.Object);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);
            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            mockDateTime.Setup(x => x.Now).Returns(DateTime.Now);

            string testParam = @"c:\TestDir";

            mockEnvironment.Setup(x => x.CurrentDirectory).Returns(testParam);

            string expectedDirectory = Path.Combine(testParam, OutputFileHelper.DefaultOutputDirectoryName);

            mockDirectory.Setup(x => x.Exists(expectedDirectory)).Returns(true);

            var    outputFileHelper = new OutputFileHelper(outputDirectory: null, system: mockSystem.Object);
            string result           = outputFileHelper.GetNewA11yTestFilePath();

            Assert.AreEqual(expectedDirectory, Path.GetDirectoryName(result));

            mockSystem.VerifyAll();
            mockDateTime.VerifyAll();
            mockEnvironment.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #4
0
        public void OutputFileHelper_EnsureOutputDirectoryExists_DoesNotCreateExistingDirectory()
        {
            var mockSystem    = new Mock <ISystem>(MockBehavior.Strict);
            var mockIO        = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(InertDateTime);
            mockSystem.Setup(x => x.Environment).Returns(InertEnvironment);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);
            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            string directory = @"c:\NonexistentDirectory";

            mockDirectory.Setup(x => x.Exists(directory)).Returns(true);

            var outputFileHelper = new OutputFileHelper(directory, mockSystem.Object);

            outputFileHelper.EnsureOutputDirectoryExists();

            // the folowing verifies that CreateDirectory was not called

            mockSystem.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #5
0
        public void OutputFileHelperCtor_CreatesNonexistentDirectory()
        {
            var mockSystemFactory = new Mock <ISystemFactory>(MockBehavior.Strict);
            var mockDateTime      = new Mock <ISystemDateTime>(MockBehavior.Strict);
            var mockEnvironment   = new Mock <ISystemEnvironment>(MockBehavior.Strict);
            var mockDirectory     = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystemFactory.Setup(x => x.CreateSystemDateTime()).Returns(mockDateTime.Object);
            mockSystemFactory.Setup(x => x.CreateSystemEnvironment()).Returns(mockEnvironment.Object);
            mockSystemFactory.Setup(x => x.CreateSystemIODirectory()).Returns(mockDirectory.Object);

            string directory = @"c:\NonexistentDirectory";

            mockDirectory.Setup(x => x.Exists(directory)).Returns(false);
            mockDirectory.Setup(x => x.CreateDirectory(directory)).Returns <System.IO.DirectoryInfo>(null);

            var outputFileHelper = new OutputFileHelper(directory, mockSystemFactory.Object);

            // the folowing verifies that Exists was called

            mockSystemFactory.VerifyAll();
            mockDateTime.VerifyAll();
            mockEnvironment.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #6
0
        public void OutputFileHelper_GetNewA11yTestFilePath_GeneratedScanId_CreatesExpectedFileName()
        {
            var mockSystem    = new Mock <ISystem>(MockBehavior.Strict);
            var mockDateTime  = new Mock <ISystemDateTime>(MockBehavior.Strict);
            var mockIO        = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(mockDateTime.Object);
            mockSystem.Setup(x => x.Environment).Returns(InertEnvironment);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);

            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            string directory = @"c:\TestDir";

            mockDirectory.Setup(x => x.Exists(directory)).Returns(true);

            var dateTime = new DateTime(
                year: 2019,
                month: 4,
                day: 1,
                hour: 20,
                minute: 8,
                second: 8
                ).AddTicks(12345);

            mockDateTime.Setup(x => x.Now).Returns(dateTime);

            var outputFileHelper = new OutputFileHelper(directory, mockSystem.Object);
            var result           = outputFileHelper.GetNewA11yTestFilePath();

            var expectedFileName = $"{OutputFileHelper.DefaultFileNameBase}_19-04-01_20-08-08.0012345.a11ytest";
            var actualFileName   = Path.GetFileName(result);

            Assert.AreEqual(expectedFileName, actualFileName);
            Assert.AreEqual(directory, Path.GetDirectoryName(result));

            mockSystem.VerifyAll();
            mockDateTime.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }
Пример #7
0
        private void llbExportModel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Excel文件(*.xlsx)|*.xlsx";
            DialogResult result = sfd.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                if (OutputFileHelper.ExportExcelModel(sfd.FileName, "供应商账龄数据模板"))
                {
                    MessageBox.Show("导出成功!");
                }
                else
                {
                    MessageBox.Show("导出失败!");
                }
                sfd.Dispose();
                GC.Collect();
            }
        }
Пример #8
0
        public void OutputFileHelper_EnsureOutputDirectoryExists_DoesNotCatchExceptions()
        {
            var mockSystem    = new Mock <ISystem>(MockBehavior.Strict);
            var mockIO        = new Mock <ISystemIO>(MockBehavior.Strict);
            var mockDirectory = new Mock <ISystemIODirectory>(MockBehavior.Strict);

            mockSystem.Setup(x => x.DateTime).Returns(InertDateTime);
            mockSystem.Setup(x => x.Environment).Returns(InertEnvironment);
            mockSystem.Setup(x => x.IO).Returns(mockIO.Object);
            mockIO.Setup(x => x.Directory).Returns(mockDirectory.Object);

            string directory = @"c:\NonexistentDirectory";

            mockDirectory.Setup(x => x.Exists(directory)).Returns(false);
            mockDirectory.Setup(x => x.CreateDirectory(directory)).Throws <Exception>();

            var outputFileHelper = new OutputFileHelper(directory, mockSystem.Object);

            Assert.ThrowsException <Exception>(() => outputFileHelper.EnsureOutputDirectoryExists());

            mockSystem.VerifyAll();
            mockIO.VerifyAll();
            mockDirectory.VerifyAll();
        }