Exemple #1
0
        public Record this[GroupPath group, string title, RecordType type] {
            get {
                var entry = this[group, title];
                return(entry.Records[type]);
            }
            set {
                if (this.IsReadOnly)
                {
                    throw new NotSupportedException("Collection is read-only.");
                }
                if (value != null)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), "Only null value is supported.");
                }

                Entry entryToModify = null;
                foreach (var entry in this.BaseCollection)
                {
                    if (entry.Group.Equals(group) && entry.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase))
                    {
                        entryToModify = entry;
                        break;
                    }
                }
                if (entryToModify != null)   //to avoid creating entry
                {
                    entryToModify.Records[type] = null;
                }
            }
        }
Exemple #2
0
        public void GroupPath_Up()
        {
            PwSafe.GroupPath path = @"A.B.C\.d";

            Assert.Equal(@"A.B.C\.d", path.ToString());
            Assert.Equal("A.B", path.Up().ToString());
            Assert.Equal("A", path.Up().Up().ToString());
            Assert.Equal("", path.Up().Up().Up().ToString());
            Assert.Equal("", path.Up().Up().Up().Up().ToString());
        }
Exemple #3
0
        public void GroupPath_New()
        {
            PwSafe.GroupPath path = "A";
            Assert.Equal("A", path.ToString());

            var segments = path.GetSegments();

            Assert.Single(segments);
            Assert.Equal("A", segments[0]);
        }
Exemple #4
0
        public void GroupPath_NewNull()
        {
            PwSafe.GroupPath path = default(string);
            Assert.Equal("", path.ToString());

            var segments = path.GetSegments();

            Assert.Single(segments);
            Assert.Equal("", segments[0]);
        }
Exemple #5
0
        public void GroupPath_Indexed()
        {
            PwSafe.GroupPath path = @"A.B.C\.d";

            Assert.Null(path[-1]);
            Assert.Equal("A", path[0]);
            Assert.Equal("B", path[1]);
            Assert.Equal("C.d", path[2]);
            Assert.Null(path[3]);
        }
Exemple #6
0
        public void GroupPath_NewTree()
        {
            PwSafe.GroupPath path = "A.B";
            Assert.Equal("A.B", path.ToString());

            var segments = path.GetSegments();

            Assert.Equal(2, segments.Length);
            Assert.Equal("A", segments[0]);
            Assert.Equal("B", segments[1]);
        }
Exemple #7
0
 /// <summary>
 /// Determines whether the collection contains an entry with specified group and title.
 /// Search is case-insensitive.
 /// </summary>
 /// <param name="group">Group.</param>
 /// <param name="title">Title.</param>
 public bool Contains(GroupPath group, string title)
 {
     foreach (var entry in this.BaseCollection)
     {
         if (entry.Group.Equals(group) && entry.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #8
0
        public void GroupPath_Append()
        {
            PwSafe.GroupPath path = "";

            Assert.Equal("", path.ToString());
            Assert.Equal("", path.Append(null).ToString());
            Assert.Equal("", path.Append("").ToString());
            Assert.Equal("A", path.Append("A").ToString());
            Assert.Equal("A.B", path.Append("A").Append("B").ToString());
            Assert.Equal(@"A.B.C\.d", path.Append("A").Append("B").Append("C.d").ToString());
            Assert.Equal(@"A.B.C\.d", path.Append("A").Append("B").Append("").Append("C.d").Append("").ToString()); //Empty elements are not appended.
        }
Exemple #9
0
        public void GroupPath_NewViaComponentsEscaped2()
        {
            var path = new PwSafe.GroupPath("A", @"B\.com");

            Assert.Equal(@"A.B\\.com", path.ToString());

            var segments = path.GetSegments();

            Assert.Equal(2, segments.Length);
            Assert.Equal("A", segments[0]);
            Assert.Equal(@"B\.com", segments[1]);
        }
Exemple #10
0
        public void GroupPath_NewViaComponents()
        {
            var path = new PwSafe.GroupPath("A", "B");

            Assert.Equal("A.B", path.ToString());

            var segments = path.GetSegments();

            Assert.Equal(2, segments.Length);
            Assert.Equal("A", segments[0]);
            Assert.Equal("B", segments[1]);
        }
Exemple #11
0
        public Entry this[GroupPath group, string title] {
            get {
                foreach (var entry in this.BaseCollection)
                {
                    if (entry.Group.Equals(group) && entry.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return(entry);
                    }
                }

                if (this.IsReadOnly)
                {
                    return(new Entry());
                }                                            //return dummy entry if collection is read-only

                var newEntry = new Entry(group, title);
                this.Add(newEntry);
                return(newEntry);
            }
            set {
                if (this.IsReadOnly)
                {
                    throw new NotSupportedException("Collection is read-only.");
                }
                if (value != null)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), "Only null value is supported.");
                }

                Entry entryToRemove = null;
                foreach (var entry in this.BaseCollection)
                {
                    if (entry.Group.Equals(group) && entry.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase))
                    {
                        entryToRemove = entry;
                        break;
                    }
                }
                if (entryToRemove != null)
                {
                    this.Remove(entryToRemove);
                }
            }
        }
Exemple #12
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="group">Group.</param>
 /// <param name="title">Title.</param>
 public Entry(GroupPath group, string title) : this()
 {
     Group = group;
     Title = title;
 }