Ejemplo n.º 1
0
        public void SetParameterValue_GetParameterValue_ValueThatWasSetReturned()
        {
            var teamCityWriter = A.Fake<ITeamCityWriter>();

            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns(null);

            var teamCityWriterFactory = A.Fake<ITeamCityWriterFactory>();
            A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter);

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever, teamCityWriterFactory,
                A.Fake<IPropertiesFileParser>());

            // Act
            buildParameters.SetBuildParameter("param1", "newValue");
            var parameterValue = buildParameters.GetBuildParameter("param1");

            // Assert
            parameterValue.Should().Be("newValue");
        }
Ejemplo n.º 2
0
        public void GetParameterValue_TeamcityBuildConfName_ValueReturned()
        {
            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns(@"C:\properties.file.txt");

            var dictionary = new Dictionary<string, string> {{"teamcity.buildConfName", "FluentTc"}};

            var propertiesFileParser = A.Fake<IPropertiesFileParser>();
            A.CallTo(() => propertiesFileParser.ParsePropertiesFile(@"C:\properties.file.txt"))
                .Returns(dictionary);

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever, A.Fake<ITeamCityWriterFactory>(),
                propertiesFileParser);

            // Act
            string buildConfName = buildParameters.TeamcityBuildConfName;

            // Assert
            buildConfName.Should().Be("FluentTc");
        }
Ejemplo n.º 3
0
        public void GetParameterValue_MissingParameter_MissingBuildParameterExceptionThrown()
        {
            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns(@"C:\properties.file.txt");

            var propertiesFileParser = A.Fake<IPropertiesFileParser>();
            A.CallTo(() => propertiesFileParser.ParsePropertiesFile(@"C:\properties.file.txt"))
                .Returns(new Dictionary<string, string>());

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever, A.Fake<ITeamCityWriterFactory>(),
                propertiesFileParser);

            // Act
            string result;
            Action action = () => result = buildParameters.GetBuildParameter<string>("missing.param");

            // Assert
            action.ShouldThrow<MissingBuildParameterException>()
                .WithMessage("Build parameter missing.param is missing. It needs to be added from TeamCity");
        }
Ejemplo n.º 4
0
        public void SetParameterValue_TeamCityMode_ExceptionThrown()
        {
            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns("propertiesFile.txt");

            var propertiesFileParser = A.Fake<IPropertiesFileParser>();
            A.CallTo(() => propertiesFileParser.ParsePropertiesFile("propertiesFile.txt"))
                .Returns(new Dictionary<string, string>());

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever,
                A.Fake<ITeamCityWriterFactory>(), propertiesFileParser);
            Action action = () => buildParameters.SetBuildParameter("param1", "newValue");

            // Assert
            action.ShouldThrow<MissingBuildParameterException>();
        }
Ejemplo n.º 5
0
        public void TryGetParameterValue_ValueDoesNotExists_False()
        {
            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns(@"C:\properties.file.txt");

            var propertiesFileParser = A.Fake<IPropertiesFileParser>();
            A.CallTo(() => propertiesFileParser.ParsePropertiesFile(@"C:\properties.file.txt"))
                .Returns(new Dictionary<string, string>());

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever, A.Fake<ITeamCityWriterFactory>(),
                propertiesFileParser);

            // Act
            string buildConfName;
            var valueExists = buildParameters.TryGetBuildParameter("teamcity.buildConfName", out buildConfName);

            // Assert
            valueExists.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void SetParameterValue_NotTeamCityMode_ValueSet()
        {
            // Arrange
            var teamCityWriter = A.Fake<ITeamCityWriter>();

            var teamCityBuildPropertiesFileRetriever = A.Fake<ITeamCityBuildPropertiesFileRetriever>();
            A.CallTo(() => teamCityBuildPropertiesFileRetriever.GetTeamCityBuildPropertiesFilePath()).Returns(null);

            var teamCityWriterFactory = A.Fake<ITeamCityWriterFactory>();
            A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter);

            var buildParameters = new BuildParameters(teamCityBuildPropertiesFileRetriever, teamCityWriterFactory,
                A.Fake<IPropertiesFileParser>());

            // Act
            buildParameters.SetBuildParameter("param1", "newValue");
            var parameterValue = buildParameters.GetBuildParameter<string>("param1");

            // Assert
            parameterValue.Should().Be("newValue");
            A.CallTo(() => teamCityWriter.WriteBuildParameter("param1", "newValue")).MustHaveHappened();
        }