public void Setup()
 {
     _shimsContext             = ShimsContext.Create();
     _baseChannelEditor        = new basechanneleditor();
     _baseChannelEditorPrivate = new PrivateObject(_baseChannelEditor);
     _user = new User
     {
         UserID = UserId
     };
     _baseChannelId                                       = default(int);
     _clientGroupSelectResult                             = null;
     _clientGroupSaveResult                               = default(int);
     _clientGroupPassedToSave                             = null;
     _clientGroupServicePassedToSave                      = null;
     _clientGroupServiceMapSaveResult                     = default(int);
     _clientGroupServiceFeatureMapSaveResult              = default(int);
     _clientGroupServiceFeatureMapPassedToSave            = null;
     _securityGroupTemplateNamePassedToCreateFromTemplate = null;
     _clientGroupIdPassedToCreateFromTemplate             = default(int);
     _administrativeLevelPassedToCreateFromTemplate       = null;
     _userPassedToCreateFromTemplate                      = null;
     _ecnSessionRemoveFromSessionCalled                   = default(bool);
     _contact                  = new Contact();
     _responseStream           = new MemoryStream();
     _responseStreamWriter     = new StreamWriter(_responseStream);
     _baseChannelPassedToSave  = null;
     _validateErrorToThrow     = null;
     _baseChannelSaveException = null;
     _clientGroupSaveException = null;
     InitializeFields();
     CommonShims();
 }
        private void CommonShims()
        {
            ShimUserSession();
            Shimbasechanneleditor.AllInstances.getBaseChannelID = instance => _baseChannelId;
            ShimBaseChannel.ValidateBaseChannelUser             = (baseCannel, user) =>
            {
                if (_validateErrorToThrow != null)
                {
                    var errors = _validateErrorToThrow.Split(new[] { ValidateSeparator },
                                                             StringSplitOptions.RemoveEmptyEntries)
                                 .Select(message => new ECNError {
                        ErrorMessage = message
                    })
                                 .ToList();
                    throw new ECNException(errors);
                }
            };
            ShimClientGroup.AllInstances.SelectInt32Boolean = (instance, clientGroupId, includeObjects) =>
            {
                return(_clientGroupSelectResult);
            };
            var clientGroupSaveCallCount = 0;

            ShimClientGroup.AllInstances.SaveClientGroup = (instance, clientGroup) =>
            {
                ++clientGroupSaveCallCount;
                _clientGroupPassedToSave = clientGroup;
                if (_clientGroupSaveException != null && clientGroupSaveCallCount > 1)
                {
                    throw _clientGroupSaveException;
                }
                return(_clientGroupSaveResult);
            };
            ShimClientGroupServiceMap.AllInstances.SaveClientGroupServiceMap = (instance, groupServiceMap) =>
            {
                _clientGroupServicePassedToSave = groupServiceMap;
                return(_clientGroupServiceMapSaveResult);
            };
            ShimClientGroupServiceFeatureMap.AllInstances.SaveClientGroupServiceFeatureMap = (instance, map) =>
            {
                _clientGroupServiceFeatureMapPassedToSave = _clientGroupServiceFeatureMapPassedToSave ?? map;
                return(_clientGroupServiceFeatureMapSaveResult);
            };
            ShimSecurityGroup.AllInstances.CreateFromTemplateForClientGroupStringInt32StringUser =
                (instance, securityGroupTemplateName, clientGroupId, administrativeLevel, user) =>
            {
                _securityGroupTemplateNamePassedToCreateFromTemplate = securityGroupTemplateName;
                _clientGroupIdPassedToCreateFromTemplate             = clientGroupId;
                _administrativeLevelPassedToCreateFromTemplate       = administrativeLevel;
                _userPassedToCreateFromTemplate = user;
                return(GetAnyNumber());
            };
            ShimContactEntity.ConstructorStringStringStringStringStringStringStringStringStringStringStringString =
                (instace, salutation, firstName, lastName, title, phone, fax, email, address, city, state, country,
                 zip) =>
            {
            };
            ShimBaseChannel.SaveBaseChannelUser = (baseChannel, user) =>
            {
                if (_baseChannelSaveException != null)
                {
                    throw _baseChannelSaveException;
                }
                _baseChannelPassedToSave = baseChannel;
            };
            ShimServiceFeature.AllInstances.GetClientGroupTreeListNullableOfInt32Boolean =
                (instance, clientGroupId, isAdditionalCost) =>
            {
                return(new List <ClientGroupTreeListRow>
                {
                    new ClientGroupTreeListRow
                    {
                        ServiceFeatureID = GetAnyNumber()
                    }
                });
            };

            ShimPage.AllInstances.ResponseGet = instance =>
            {
                return(new System.Web.HttpResponse(_responseStreamWriter));
            };
            ShimHttpResponse.AllInstances.RedirectString = (instance, url) =>
            {
            };
            ShimEmailDirect.SaveEmailDirect = email =>
            {
                return(GetAnyNumber());
            };
        }