/// <summary>
        /// Creates a call context for the service object
        /// </summary>
        /// <returns>Service call context instance</returns>
        protected override IServiceCallContext CreateServiceCallContext()
        {
            var context = new ServiceCallContext();

            if (HttpContext.Current != null)
            {
                var headers     = HttpContext.Current.Request.Headers;
                var operationId = headers[CustomHttpHeaders.OPERATION_ID_HEADER];
                if (operationId != null)
                {
                    context.Set(new OperationInstanceIdContextItem(operationId));
                }
                var uiCulture = headers[CustomHttpHeaders.UI_CULTURE_HEADER];
                if (uiCulture != null)
                {
                    context.Set(new UiCultureContextItem(uiCulture));
                }
            }

            // --- Set up the user context
            var userIdContextProvider = ServiceManager.GetService <IUserIdContextProvider>();

            if (userIdContextProvider != null)
            {
                userIdContextProvider.SetUsetContext(context);
            }
            return(context);
        }
        public void SetItemAndGetItemWorksAsExpected()
        {
            // --- Arrange
            var context = new ServiceCallContext();

            context.Clear();

            // --- Act
            context.Set(new IntContextItem(123));
            var item1 = context.Get <IntContextItem>();

            context.Set(new StringContextItem("hello"));
            var item2 = context.Get <StringContextItem>();
            var item3 = context.Get <EmptyContextItem>();

            // --- Assert
            item1.ShouldNotBeNull();
            item1.Value.ShouldEqual(123);
            var contextItem = item1 as IServiceCallContextItem;

            contextItem.ShouldNotBeNull();
            contextItem.GetValue().ShouldEqual(123);
            item2.ShouldNotBeNull();
            item2.Value.ShouldEqual("hello");
            item3.ShouldBeNull();
        }
        public void CloneWorksAsExpected()
        {
            // --- Arrange
            var context = new ServiceCallContext();

            context.Set(new IntContextItem(123));
            context.Set(new StringContextItem("hello"));

            // --- Act
            var clone = (context as ICloneable).Clone() as ServiceCallContext;

            // --- Assert
            clone.ShouldNotBeNull();
            clone.ShouldNotBeSameAs(context);
            // ReSharper disable PossibleNullReferenceException
            clone.Get <IntContextItem>().Value.ShouldEqual(123);
            // ReSharper restore PossibleNullReferenceException
            clone.Get <StringContextItem>().Value.ShouldEqual("hello");
        }
        public void RemoveWorksAsExpected()
        {
            // --- Arrange
            var context = new ServiceCallContext();

            context.Clear();
            context.Set(new IntContextItem(123));

            // --- Act
            var item1 = context.Get <IntContextItem>();

            context.Remove <IntContextItem>();
            var item2 = context.Get <IntContextItem>();

            // --- Assert
            item1.ShouldNotBeNull();
            item2.ShouldBeNull();
        }