Пример #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_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();
        }