public void AddCustomerIfNotInList() { var collection = new Collection<Customer>(); var customer = new Customer(); var activity = new EnsureCustomerIsInList(); var host = new WorkflowInvokerTest(activity); var inputs = new Dictionary<string, object> { { "CustomerCollection", collection }, { "Customer", customer } }; try { host.TestActivity(inputs); Assert.IsTrue(collection.Contains(customer)); } finally { host.Tracking.Trace(); } }
public void WhatHappensIfCopiedCustomerExists() { var collection = new Collection<Customer>(); var customer1 = new Customer(); // Add the customer to the list collection.Add(customer1); // Create a copy of the same customer var customer2 = new Customer(customer1); var activity = new EnsureCustomerIsInList(); var host = new WorkflowInvokerTest(activity); // Pass the copy to the activity var inputs = new Dictionary<string, object> { { "CustomerCollection", collection }, { "Customer", customer2 } }; try { host.TestActivity(inputs); this.TestContext.WriteLine("Customer collection count {0}", collection.Count); foreach (var cust in collection) { this.TestContext.WriteLine("Customer ID {0}", cust.Id); } // The copy will be added because the reference is not equal // This is probably not be what you want Assert.IsTrue(collection.Contains(customer1)); Assert.IsTrue(collection.Contains(customer2)); // Both customer and customer2 are in the collection Assert.AreEqual(2, collection.Count); } finally { host.Tracking.Trace(); } }