Esempio n. 1
0
        /// <summary>
        /// Gets a value containing arbitrary user-specified state information associated with the operation.
        /// </summary>
        /// <param name="key">A key used to identify the user state.</param>
        /// <returns>The user state set, or null if none was found for the given key.</returns>
        public object FindUserState(string key)
        {
            Check.NotNull(key, "key");

            return(_mutableData.FindUserState(key));
        }
        public void UserState_can_be_changed(bool useObsoleteState)
        {
            var data = new InterceptionContextMutableData();

            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Null(data.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Null(data.FindUserState("A"));
                Assert.Null(data.FindUserState("B"));
            }

            if (useObsoleteState)
            {
#pragma warning disable 618
                data.UserState = "Cheddar";
#pragma warning restore 618
            }
            else
            {
                data.SetUserState("A", "AState");
                data.SetUserState("B", "BState");
            }

            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Equal("Cheddar", data.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Equal("AState", data.FindUserState("A"));
                Assert.Equal("BState", data.FindUserState("B"));
                Assert.Null(data.FindUserState("C"));
            }

            if (useObsoleteState)
            {
#pragma warning disable 618
                data.UserState = "Cheddar2";
#pragma warning restore 618
            }
            else
            {
                data.SetUserState("A", "AState2");
                data.SetUserState("B", "BState2");
            }

            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Equal("Cheddar2", data.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Equal("AState2", data.FindUserState("A"));
                Assert.Equal("BState2", data.FindUserState("B"));
                Assert.Null(data.FindUserState("C"));
            }
        }