public void TestAddingTheElement() { StringContainer sc = new StringContainer(); sc.AddString("Jajs"); sc.AddString("kolen"); var res = sc.ShowResult(); var expected = "J k "; Assert.AreEqual(expected, res); }
public void TestAddingTheEmptyString() { // expect the exception of the exception System.Diagnostics.Contracts.__ContractsRuntime+ContractException StringContainer sc = new StringContainer(); string str = null; sc.AddString(str); }
static public void Main() { // Declare the StringContainer class and add some strings StringContainer container = new StringContainer(); container.AddString("This"); container.AddString("is"); container.AddString("a"); container.AddString("multicast"); container.AddString("delegate"); container.AddString("example"); // Create two delegates individually using different methods. StringContainer.CheckAndDisplayDelegate conStart = StringExtensions.ConStart; StringContainer.CheckAndDisplayDelegate vowelStart = StringExtensions.VowelStart; // Get the list of all delegates assigned to this MulticastDelegate instance. Delegate[] delegateList = conStart.GetInvocationList(); Console.WriteLine("conStart contains {0} delegate(s).", delegateList.Length); delegateList = vowelStart.GetInvocationList(); Console.WriteLine("vowelStart contains {0} delegate(s).\n", delegateList.Length); // Determine whether the delegates are System.Multicast delegates. if (conStart is System.MulticastDelegate && vowelStart is System.MulticastDelegate) { Console.WriteLine("conStart and vowelStart are derived from MulticastDelegate.\n"); } // Execute the two delegates. Console.WriteLine("Executing the conStart delegate:"); container.DisplayAllQualified(conStart); Console.WriteLine(); Console.WriteLine("Executing the vowelStart delegate:"); container.DisplayAllQualified(vowelStart); Console.WriteLine(); // Create a new MulticastDelegate and call Combine to add two delegates. StringContainer.CheckAndDisplayDelegate multipleDelegates = (StringContainer.CheckAndDisplayDelegate)Delegate.Combine(conStart, vowelStart); // How many delegates does multipleDelegates contain? delegateList = multipleDelegates.GetInvocationList(); Console.WriteLine("\nmultipleDelegates contains {0} delegates.\n", delegateList.Length); // Pass this multicast delegate to DisplayAllQualified. Console.WriteLine("Executing the multipleDelegate delegate."); container.DisplayAllQualified(multipleDelegates); // Call remove and combine to change the contained delegates. multipleDelegates = (StringContainer.CheckAndDisplayDelegate)Delegate.Remove(multipleDelegates, vowelStart); multipleDelegates = (StringContainer.CheckAndDisplayDelegate)Delegate.Combine(multipleDelegates, conStart); // Pass multipleDelegates to DisplayAllQualified again. Console.WriteLine("\nExecuting the multipleDelegate delegate with two conStart delegates:"); container.DisplayAllQualified(multipleDelegates); }