public void AddTwoKeyValueAndRetrieveBoth() { var customHashTable = new CustomHashTable <string, Person>(); var person = new Person { Name = "Vaibhav", Age = 35 }; customHashTable.Add(person.Name, person); var personTwo = new Person { Name = "Vaibhav Bali", Age = 35 }; customHashTable.Add(personTwo.Name, personTwo); Assert.IsTrue(customHashTable.Contains(person.Name)); var element = customHashTable.GetElement(person.Name); Assert.IsNotNull(element); Assert.AreEqual(person.Name, element.Name); Assert.AreEqual(person.Age, element.Age); Assert.IsTrue(customHashTable.Contains(personTwo.Name)); var secondElement = customHashTable.GetElement(personTwo.Name); Assert.IsNotNull(secondElement); Assert.AreEqual(personTwo.Name, secondElement.Name); Assert.AreEqual(personTwo.Age, secondElement.Age); }
public void AddOneKeyValue() { var customHashTable = new CustomHashTable <string, Person>(); var person = new Person { Name = "Vaibhav", Age = 35 }; customHashTable.Add(person.Name, person); Assert.IsTrue(customHashTable.Contains(person.Name)); }
internal static CNDAddressingReg GetAddressingRegister(CustomHashTable table) { if (!table.Contains(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Component Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_HOST_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Hostname]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[P2PPortNumber]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[IPAddress]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Process ID]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Registration Date Time]\' is missing.")); } string compName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)); compName = compName.ToUpper(); string hostName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_HOST_NAME)); string P2PPortNumber = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)); string IPAddress = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)); string ApplicationName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)); string ApplicationProcessID = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)); string RegistrationDateTime = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)); int PortNumber = Convert.ToInt32(P2PPortNumber); CNDAddressingReg reg = new CNDAddressingReg(compName, hostName, IPAddress, PortNumber, ApplicationName, ApplicationProcessID, RegistrationDateTime); return(reg); }
public void Contains_SomeElement_ReturnFalse() { CustomHashTable <string, int> hashTable = new CustomHashTable <string, int>(); for (var index = 1; index <= 100; index++) { hashTable.Add(index.ToString(), index); } for (var index = 100; index <= 200; index++) { var containsItem = hashTable.Contains(new KeyValuePair <string, int>(index.ToString(), 35)); Assert.IsFalse(containsItem); } }