/// <summary>
        /// Updates the <see cref="ProteinCollection"/> from the collection of <see cref="Protein"/> objects.
        /// </summary>
        /// <param name="proteins">The collection of <see cref="Protein"/> objects used to apply changes to this collection.</param>
        public IReadOnlyList <ProteinChange> Update(IEnumerable <Protein> proteins)
        {
            if (proteins is null)
            {
                throw new ArgumentNullException(nameof(proteins));
            }

            var changes = new List <ProteinChange>();

            foreach (Protein protein in proteins.Where(Protein.IsValid))
            {
                if (Contains(protein.ProjectNumber))
                {
                    Protein previous = this[protein.ProjectNumber];
                    _ = Remove(previous);

                    var propertyChanges = GetChangedProperties(previous, protein);
                    if (propertyChanges.Count > 0)
                    {
                        changes.Add(ProteinChange.Property(protein.ProjectNumber, propertyChanges));
                    }
                    else
                    {
                        changes.Add(ProteinChange.None(protein.ProjectNumber));
                    }
                }
                else
                {
                    changes.Add(ProteinChange.Add(protein.ProjectNumber));
                }

                Add(protein);
            }
            return(changes);
        }
Beispiel #2
0
        public void ProteinChange_EnumeratesPropertyChangesToReadOnlyList()
        {
            // Arrange
            var propertyChanges = EnumeratePropertyChanges();
            // Act
            var change = ProteinChange.Property(1, propertyChanges);

            // Assert
            Assert.AreEqual(1, change.PropertyChanges.Count);
        }