versionone / VersionOne.Client.VisualStudio

View and update VersionOne work items directly from Visual Studio
http://versionone.github.io/VersionOne.Client.VisualStudio
BSD 3-Clause "New" or "Revised" License
2 stars 10 forks source link

Don't hardcode V1 URLs in tests #22

Closed ibuchanan closed 10 years ago

ibuchanan commented 10 years ago

At a minimum read a config file value with hardcoded fallback.

JogoShugh commented 10 years ago

Check out the code we put here for reading from environment , config, or finally hard-coded as a last resort: https://github.com/versionone/VersionOne.SDK.NET.ObjectModel/blob/master/ObjectModel.Tests/BaseSDKTester.cs

It would be nice if we had something similar to NConf in .NET. Anyone know of an open source library that does what NConf does? See https://github.com/flatiron/nconf

    protected virtual string ApplicationPath
        {
            get
            {
                const string settingName = "TEST_URL";
                var url = System.Environment.GetEnvironmentVariable(settingName);
                if (string.IsNullOrWhiteSpace(url))
                {
                    url = System.Configuration.ConfigurationManager.AppSettings[settingName];
                    if (string.IsNullOrWhiteSpace(url))
                    {
                        url = "http://localhost/V1SDKTests/";
                    }
                }

                url = url.Trim();

                return url;
            }
        }

        protected virtual string Username {
            get { return System.Environment.GetEnvironmentVariable("TEST_USER") ?? "admin"; }
        }

        protected virtual string Password {
            get { return System.Environment.GetEnvironmentVariable("TEST_PASSWORD") ?? "admin"; }
        }
lremedi commented 10 years ago

Hey Josh, I saw what you did with those tests, and create a small static class to get the values, first from app.config file, then from environment, and finally from a hardcoded value. Do you think this could work? I added this class in the test project, and it's in my repo, in order for you to test it.

    public class TestConfiguration
    {
        public static string GetVariable(string key)
        {
            return GetVariable(key, string.Empty);
        }
        public static string GetVariable(string key, string harcoded)
        {
            try
            {
                return (ConfigurationManager.AppSettings[key] ?? Environment.GetEnvironmentVariable(key)) ?? harcoded;
            }
            catch
            {
                return string.Empty;
            }
        }
    }

BTW, I found a NConf (https://nconf.codeplex.com/) for .Net, but in my point of view is not mature enough, and last commit was a year ago.