예제 #1
0
        public void Execute_should_set_paths_appropriately_for_self_repo_with_multiple_checkouts()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                InitializeExecutionContext(hc, true);
                var updateRepoPath = new PluginInternalUpdateRepositoryPathCommand();
                var command        = new Microsoft.VisualStudio.Services.Agent.Command("area", "event");
                command.Properties.Add("alias", "self");
                command.Data = "/1/newPath";

                updateRepoPath.Execute(_ec.Object, command);

                Assert.Equal("/1/newPath", _selfRepo.Properties.Get <String>(RepositoryPropertyNames.Path));
                Assert.Equal("/1/otherRepo", _otherRepo.Properties.Get <String>(RepositoryPropertyNames.Path));
                Assert.Equal(null, _variables.Get(Constants.Variables.Build.SourcesDirectory));
                Assert.Equal("newPath", GetLastPathPart(_variables.Get(Constants.Variables.Build.RepoLocalPath)));
                Assert.Equal(null, _variables.Get(Constants.Variables.System.DefaultWorkingDirectory));
            }
        }
예제 #2
0
        public void Execute_should_throw_appropriately()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                InitializeExecutionContext(hc);
                var updateRepoPath = new PluginInternalUpdateRepositoryPathCommand();
                var command        = new Microsoft.VisualStudio.Services.Agent.Command("area", "event");

                // missing alias
                Assert.Throws <Exception>(() => updateRepoPath.Execute(_ec.Object, command));

                // add alias, still missing matching repository
                command.Properties.Add("alias", "repo1");
                Assert.Throws <Exception>(() => updateRepoPath.Execute(_ec.Object, command));

                // add repository, still missing data
                _repositories.Add(new RepositoryResource()
                {
                    Alias = "repo1"
                });
                Assert.Throws <Exception>(() => updateRepoPath.Execute(_ec.Object, command));
            }
        }
예제 #3
0
        public static bool TryParse(string message, out Command command)
        {
            command = null;
            if (string.IsNullOrEmpty(message))
            {
                return false;
            }

            try
            {
                // Get the index of the prefix.
                int prefixIndex = message.IndexOf(LoggingCommandPrefix);
                if (prefixIndex < 0)
                {
                    return false;
                }

                // Get the index of the separator between the command info and the data.
                int rbIndex = message.IndexOf(']', prefixIndex);
                if (rbIndex < 0)
                {
                    return false;
                }

                // Get the command info (area.event and properties).
                int cmdIndex = prefixIndex + LoggingCommandPrefix.Length;
                string cmdInfo = message.Substring(cmdIndex, rbIndex - cmdIndex);

                // Get the command name (area.event).
                int spaceIndex = cmdInfo.IndexOf(' ');
                string commandName = 
                    spaceIndex < 0
                    ? cmdInfo
                    : cmdInfo.Substring(0, spaceIndex);

                // Get the area and event.
                string[] areaEvent = commandName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (areaEvent.Length != 2)
                {
                    return false;
                }

                string areaName = areaEvent[0];
                string eventName = areaEvent[1];

                // Initialize the command.
                command = new Command(areaName, eventName);

                // Set the properties.
                if (spaceIndex > 0)
                {
                    string propertiesStr = cmdInfo.Substring(spaceIndex + 1);
                    string[] splitProperties = propertiesStr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string propertyStr in splitProperties)
                    {
                        string[] pair = propertyStr.Split(new[] { '=' }, count: 2, options: StringSplitOptions.RemoveEmptyEntries);
                        if (pair.Length == 2)
                        {
                            command.Properties[pair[0]] = Unescape(pair[1]);
                        }
                    }
                }

                command.Data = Unescape(message.Substring(rbIndex + 1));
                return true;
            }
            catch
            {
                command = null;
                return false;
            }
        }