Exemplo n.º 1
0
        public void ShouldGetGaugeVersion()
        {
            const string json =
                "{\"version\": \"0.4.0\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.7.3\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}";
            var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var installedGaugeVersion = GaugeService.GetInstalledGaugeVersion(gaugeProcess);

            Assert.AreEqual("0.4.0", installedGaugeVersion.version);
            Assert.AreEqual(2, installedGaugeVersion.plugins.Length);
        }
Exemplo n.º 2
0
        public void ShouldGetGaugeVersionWhenDeprecated()
        {
            var json = string.Concat(
                "[DEPRECATED] This usage will be removed soon. Run `gauge help --legacy` for more info.",
                Environment.NewLine,
                "{\"version\": \"0.4.0\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.7.3\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}");
            var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var installedGaugeVersion = GaugeService.GetInstalledGaugeVersion(gaugeProcess);

            Assert.AreEqual("0.4.0", installedGaugeVersion.version);
            Assert.AreEqual(2, installedGaugeVersion.plugins.Length);
        }
Exemplo n.º 3
0
        public void ShouldThrowExceptionWhenExitCodeIsNonZero()
        {
            const string errorMessage = "This is an error message";
            var          outputStream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));
            var          errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(errorMessage));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.ExitCode).Returns(123);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var exception =
                Assert.Throws <GaugeVersionNotFoundException>(() =>
                                                              GaugeService.GetInstalledGaugeVersion(gaugeProcess));

            Assert.NotNull(exception);
            Assert.NotNull(exception.Data);
            Assert.AreEqual("Unable to read Gauge version", exception.Message);
            Assert.AreEqual(errorMessage, exception.Data["GaugeError"]);
        }