public void Add_DuplicateTest() { // arrange MultiCollection <int, string, DateTime> collection = new MultiCollection <int, string, DateTime>(); int testId = 1; string testName = Guid.NewGuid().ToString(); var val = DateTime.Now; // act collection.Add(testId, testName, val); collection.Add(testId, testName, val); // assert Assert.AreEqual(collection.Values.ToList()[0], val); }
public void Identical_Types_In_Key_Test() { MultiCollection <int, int, Person> dcCollection = new MultiCollection <int, int, Person>(); dcCollection.Add(75, 75, new Person()); dcCollection.Add(17, 21, new Person()); dcCollection.Add(11, 2, new Person()); dcCollection.Add(75, 4, new Person()); var resultId = dcCollection[id : 75]; Assert.AreEqual(2, resultId.Count()); var resultName = dcCollection[name : 75]; Assert.AreEqual(1, resultName.Count()); }
public void Add_ArgNullTest() { // arrange MultiCollection <int, string, Person> collection = new MultiCollection <int, string, Person>(); // assert Assert.ThrowsException <ArgumentNullException>(() => collection.Add(1, null, null)); }
public void Contains_Name_UserTypes_Test() { // Arrange var utCollection = new MultiCollection <IdKey, NameKey, Person>(); // 1 Значение var idType = new IdKey(1); var idValue = idType.Id; var nameType = new NameKey("A"); var nameValue = nameType.Name; var personType = new Person(idValue, nameValue); var personIdValue = personType.Id; var personNotesValue = personType.Notes; // 2 Значение var idType2 = new IdKey(2); var idValue2 = idType2.Id; var nameType2 = new NameKey("B"); var nameValue2 = nameType2.Name; var personType2 = new Person(idValue2, nameValue2); var personIdValue2 = personType2.Id; var personNotesValue2 = personType2.Notes; utCollection.Clear(); utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue)); utCollection.Add(new IdKey(idValue2), new NameKey(nameValue2), new Person(idValue2, nameValue2)); // Action var newNameKey = new NameKey(nameValue); var isContainsByValue = utCollection.Contains(newNameKey); var isContainsByRef = utCollection.Contains(nameType); var hCodeId = newNameKey.GetHashCode(); var hcIdType = nameType.GetHashCode(); // Assert Assert.IsFalse(utCollection.Contains(new NameKey("C"))); Assert.AreEqual(hcIdType, hCodeId); Assert.IsTrue(isContainsByValue); Assert.IsTrue(isContainsByRef); }
public void Add_UserType_Test() { var startCnt = _userTypeCollection.Count; _userTypeCollection.Add(new IdKey(2), new NameKey("B"), new Person()); var actualCnt = _userTypeCollection.Count; Assert.IsTrue(++startCnt == actualCnt); }
public void Setup() { // Стандартная коллекция с простыми типами _stdCollection = new MultiCollection <int, string, Person>(); _person1 = new Person(); _person2 = new Person(); _person3 = new Person(); _stdCollection.Add(_person1.Id, _person1.Notes, _person1); _stdCollection.Add(_person2.Id, _person2.Notes, _person2); _stdCollection.Add(_person3.Id, _person3.Notes, _person3); // Коллекция с сложными ключами _userTypeCollection = new MultiCollection <IdKey, NameKey, Person>(); _idKey1 = new IdKey(1); _nameKey1 = new NameKey("A"); _personUt1 = new Person(_idKey1.Id, _nameKey1.Name); _userTypeCollection.Add(_idKey1, _nameKey1, _personUt1); }
public void Contains_Value_UserTypes_Test() { // Arrange var utCollection = new MultiCollection <IdKey, NameKey, Person>(); // 1 Значение var idType = new IdKey(1); var idValue = idType.Id; var nameType = new NameKey("A"); var nameValue = nameType.Name; var personType = new Person(idValue, nameValue); var personIdValue = personType.Id; var personNotesValue = personType.Notes; // 2 Значение var idType2 = new IdKey(2); var idValue2 = idType2.Id; var nameType2 = new NameKey("B"); var nameValue2 = nameType2.Name; var personType2 = new Person(idValue2, nameValue2); var personIdValue2 = personType2.Id; var personNotesValue2 = personType2.Notes; utCollection.Clear(); utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue)); utCollection.Add(idType2, nameType2, personType2); // Action var isContainsByValue = utCollection.Contains(new Person(idValue2, nameValue2)); var isContainsByRef = utCollection.Contains(personType2); // Assert Assert.IsTrue(isContainsByValue); Assert.IsTrue(isContainsByRef); }
public void SpeedTest_Reference_Type_Key_Get_Value_Test() { //Arrange Stopwatch stopWatch = new Stopwatch(); var collection = new MultiCollection <IdKey, NameKey, Person>(); var expectedName = new NameKey("AA"); // Init Expected values for (int i = 0; i < 15; i++) { var p = new Person(); collection.Add(new IdKey(i), expectedName, p); } // Init random entries for (int i = 500; i < 100000; i++) { var person = new Person(); collection.Add(new IdKey(i), new NameKey(), person); } //Action stopWatch.Start(); var result = collection[expectedName]; var actualdLength = result.Count(); stopWatch.Stop(); var time = stopWatch.Elapsed.TotalMilliseconds; // Key Value // Key Struct 32.53 // Key Struct std 26.0053 // ValueTuple 24.7 // Tuple 14 //Assert Assert.AreEqual(15, actualdLength); }
public void Index_Id_Name_UserTypes_Test() { // Arrange var utCollection = new MultiCollection <IdKey, NameKey, Person>(); // 1 Значение var idType = new IdKey(1); var idValue = idType.Id; var nameType = new NameKey("A"); var nameValue = nameType.Name; var personType = new Person(idValue, nameValue); var personIdValue = personType.Id; var personNotesValue = personType.Notes; // 2 Значение var idType2 = new IdKey(2); var idValue2 = idType2.Id; var nameType2 = new NameKey("B"); var nameValue2 = nameType2.Name; var personType2 = new Person(idValue2, nameValue2); var personIdValue2 = personType2.Id; var personNotesValue2 = personType2.Notes; utCollection.Clear(); utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue)); utCollection.Add(idType2, nameType2, personType2); // Action var actualPerson = utCollection[new IdKey(idValue), new NameKey(nameValue)]; // Assert Assert.AreEqual(personType.Id, actualPerson.Id); Assert.AreEqual(personType.Notes, actualPerson.Notes); }
public void AddTest() { // arrange MultiCollection <int, int, int> collection = new MultiCollection <int, int, int>(); int numCnt = 100; // act for (int i = 0; i < numCnt; i++) { collection.Add(i, i, i); } // assert Assert.AreEqual(collection.Count, numCnt); }
public void ClearTest() { var expected = 0; //Action var p = new Person(); _stdCollection.Add(p.Id, p.Notes, p); _stdCollection.Clear(); var actual = _stdCollection.Count; _userTypeCollection.Clear(); //Assert Assert.AreEqual(expected, actual); Assert.IsTrue(_userTypeCollection.Count == 0); }