public void Equals_BetweenChangesetPathAction_AndObject_ReturnsFalse()
        {
            var cpa = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };
            var obj = new object();

            Assert.That(cpa.Equals(obj), Is.False);
        }
Esempio n. 2
0
        public void ToString_ReturnsActionAndPath()
        {
            var cpa = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };
            string ts = cpa.ToString();

            Assert.That(ts, Is.EqualTo("Add: /test.txt"));
        }
Esempio n. 3
0
        public void Equals_BetweenChangesetPathAction_AndObject_ReturnsFalse()
        {
            var cpa = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };
            var obj = new object();

            Assert.That(cpa.Equals(obj), Is.False);
        }
Esempio n. 4
0
        public void GetHashCodeOfObjectsWithSameContents_ReturnsSameValues()
        {
            var cpa1 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };
            var cpa2 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };

            Assert.That(cpa1.GetHashCode(), Is.EqualTo(cpa2.GetHashCode()));
        }
Esempio n. 5
0
        public void EqualsOfObject_BetweenTwoChangesetPathActionsWithTheSameContent_ReturnsTrue()
        {
            var cpa1 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };
            var cpa2 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path   = "/test.txt"
            };

            Assert.That(cpa1.Equals((object)cpa2), Is.True);
        }
        public void GetHashCodeOfObjectsWithSameContents_ReturnsSameValues()
        {
            var cpa1 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };
            var cpa2 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };

            Assert.That(cpa1.GetHashCode(), Is.EqualTo(cpa2.GetHashCode()));
        }
        public void EqualsOfObject_BetweenTwoChangesetPathActionsWithTheSameContent_ReturnsTrue()
        {
            var cpa1 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };
            var cpa2 = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };

            Assert.That(cpa1.Equals((object)cpa2), Is.True);
        }
        /// <summary>
        /// Parse the given XML lazily and return a collection of <see cref="Changeset"/>
        /// objects for the information contained in it, in the order the changesets
        /// appear in the xml.
        /// </summary>
        /// <param name="xml">
        /// The XML to parse.
        /// </param>
        /// <returns>
        /// A collection of <see cref="Changeset"/> objects.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// <para>An unknown path action character was detected in the log output.</para>
        /// <para>- or -</para>
        /// <para>The XML content was not legal according to the expected format.</para>
        /// </exception>
        public static IEnumerable<Changeset> LazyParse(string xml)
        {
            if (StringEx.IsNullOrWhiteSpace(xml))
                yield break;

            var serializer = new XmlSerializer(typeof(LogEntryNode));
            foreach (string entryXml in LazyExtractChangesetXmlPieces(xml))
            {
                var entry = (LogEntryNode)serializer.Deserialize(new StringReader(entryXml));
                var changeset = new Changeset
                {
                    Timestamp = entry.Timestamp,
                    AuthorName = (entry.Author ?? new LogEntryAuthorNode()).Name,
                    AuthorEmailAddress = (entry.Author ?? new LogEntryAuthorNode()).Email,
                    CommitMessage = entry.CommitMessage ?? string.Empty,
                    Branch = entry.Branch ?? "default",
                    Hash = entry.Hash,
                    RevisionNumber = entry.Revision,
                    Revision = RevSpec.Single(entry.Hash),
                    Tags = entry.Tags.Select(t => t.Name).ToArray(),
                };

                switch (entry.Parents.Count)
                {
                    case 2:
                        changeset.RightParentHash = entry.Parents[1].Hash;
                        changeset.RightParentRevision = entry.Parents[1].Revision;
                        goto case 1;

                    case 1:
                        changeset.LeftParentHash = entry.Parents[0].Hash;
                        changeset.LeftParentRevision = entry.Parents[0].Revision;
                        break;

                    case 0:
                        changeset.LeftParentRevision = changeset.RevisionNumber - 1;
                        break;
                }

                foreach (LogEntryPathNode action in entry.PathActions)
                {
                    var pathAction = new ChangesetPathAction
                    {
                        Path = action.Path,
                    };
                    switch (action.Action)
                    {
                        case "M":
                            pathAction.Action = ChangesetPathActionType.Modify;
                            break;

                        case "A":
                            pathAction.Action = ChangesetPathActionType.Add;
                            LogEntryCopyNode copySource = entry.Copies.Where(c => c.Destination == action.Path).FirstOrDefault();
                            if (copySource != null)
                                pathAction.Source = copySource.Source;
                            break;

                        case "R":
                            pathAction.Action = ChangesetPathActionType.Remove;
                            break;

                        default:
                            throw new InvalidOperationException("Unknown path action: " + action.Action);
                    }
                    changeset.PathActions.Add(pathAction);
                }

                yield return changeset;
            }
        }
        public void ToString_ReturnsActionAndPath()
        {
            var cpa = new ChangesetPathAction
            {
                Action = ChangesetPathActionType.Add,
                Path = "/test.txt"
            };
            string ts = cpa.ToString();

            Assert.That(ts, Is.EqualTo("Add: /test.txt"));
        }