public void AddIfNotExistDictionaryTest() { var people = RandomData.GeneratePersonRefCollection<PersonProper>(10).ToDictionary(p => p.Id); var newPerson = RandomData.GenerateRefPerson<PersonProper>(); // Test parameters _ = Assert.ThrowsException<ArgumentInvalidException>(() => people.AddIfNotExists(null, newPerson)); // Test Assert.IsTrue(people.AddIfNotExists(newPerson.Id, newPerson)); Assert.IsFalse(people.AddIfNotExists(newPerson.Id, newPerson)); var readOnlyPeople = new ReadOnlyDictionary<string, PersonProper>(people); _ = Assert.ThrowsException<ArgumentReadOnlyException>(() => readOnlyPeople.AddIfNotExists(newPerson.Id, newPerson)); }
public void AddIfNotExistDictionaryTest() { var people = RandomData.GeneratePersonCollection <PersonProper>(10).ToDictionary(p => p.Id); var newPerson = RandomData.GeneratePerson <PersonProper>(); // Test parameters _ = Assert.ThrowsException <ArgumentNullException>(() => people.AddIfNotExists(null, newPerson)); _ = Assert.ThrowsException <ArgumentNullException>(() => people.AddIfNotExists(newPerson.Id, null)); // Test people.AddIfNotExists(newPerson.Id, newPerson); Assert.IsTrue(people.Count == 11); people.AddIfNotExists(newPerson.Id, newPerson); Assert.IsTrue(people.Count == 11); var readonlyPeople = new ReadOnlyDictionary <string, PersonProper>(people); readonlyPeople.AddIfNotExists(newPerson.Id, newPerson); Assert.IsTrue(readonlyPeople.Count == 11); }