public void When_Dictionary_SetItem_Then_FactoryIsInvokedOnlyOnce() { var key = new object(); var dictionary = ImmutableDictionary <object, object> .Empty.Add(key, new object()); var invocation = 0; Transactional.SetItem( ref dictionary, new object(), o => { // Cause concurrency issue if (invocation++ == 0) { dictionary = ImmutableDictionary <object, object> .Empty.Add(new object(), new object()); } return(new object()); }); Assert.AreEqual(1, invocation); }