public void Find( ) { RecentComputerList computers = new RecentComputerList(); ComputerName withAlias = new ComputerName( "1.1.1.1", "alias" ); ComputerName justComputer = new ComputerName( "work", null ); computers.Add( withAlias ); computers.Add( justComputer ); // Find by alias Assert.AreEqual( withAlias, computers.Find( "alias" ) ); // Find by computer Assert.AreEqual( withAlias, computers.Find( "1.1.1.1" ) ); // Find with no alias Assert.AreEqual( justComputer, computers.Find( "work" ) ); // Find by alias, case insensitive Assert.AreEqual( withAlias, computers.Find( "ALIAS" ) ); // Find by computer, case insensitive Assert.AreEqual( justComputer, computers.Find( "WORK" ) ); // Not found Assert.IsNull( computers.Find( "foobar" ) ); }
public void CopyCtor( ) { var computers = new RecentComputerList(); computers.Add( new ComputerName( "1.1.1.1", "work", true ) ); computers.Add( new ComputerName( "2.2.2.2", "home", false ) ); var otherComps = new RecentComputerList( computers ); // Did we copy? Assert.AreEqual( new ComputerName[] { new ComputerName( "1.1.1.1", "work", true ), new ComputerName( "2.2.2.2", "home", false ) }, otherComps.ToArray() ); // Are the underlying lists different objects? computers.Remove( computers.Find( "home" ) ); Assert.AreEqual( 1, computers.Count ); Assert.AreEqual( 2, otherComps.Count ); // Are the underlayng ComputerName different objects? foreach ( var name in computers ) { name.Alias = null; } Assert.IsNull( computers.Find( "work" ) ); Assert.IsNotNull( otherComps.Find( "work" ) ); }