Beispiel #1
0
        private void SetupForPageLoad()
        {
            var requestFormCollection = new Dictionary <string, string>()
            {
                ["Server"]   = RequestServer,
                ["DB"]       = RequestDb,
                ["Username"] = RequestUserName,
                ["Password"] = RequestPassword,
                ["WEBAPP"]   = RequestWebApp
            };

            var shimHttpServerUtility = new ShimHttpServerUtility();
            var shimHttpRequest       = new ShimHttpRequest();

            shimHttpRequest.ItemGetString =
                key => requestFormCollection.ContainsKey(key)
                       ? requestFormCollection[key]
                       : string.Empty;

            ShimPage.AllInstances.ServerGet  = _ => shimHttpServerUtility;
            ShimPage.AllInstances.RequestGet = _ => shimHttpRequest;

            var shimSpApplicationPool = new ShimSPApplicationPool();
            var shimSpProcessIdentity = new ShimSPProcessIdentity(shimSpApplicationPool);

            shimSpProcessIdentity.UsernameGet = () => ApplicationPoolUserName;

            var shimSpWebApplication = new ShimSPWebApplication();

            shimSpWebApplication.ApplicationPoolGet = () => shimSpApplicationPool;

            var shimSpWebApplicationCollection  = new ShimSPWebApplicationCollection();
            var shimSpPersistedObjectCollection = new ShimSPPersistedObjectCollection <SPWebApplication>(shimSpWebApplicationCollection);

            shimSpPersistedObjectCollection.ItemGetGuid = _ => shimSpWebApplication;

            var shimSpWebService = new ShimSPWebService();

            shimSpWebService.WebApplicationsGet = () => shimSpWebApplicationCollection;
            ShimSPWebService.ContentServiceGet  = () => shimSpWebService;
        }
        private void ArrangePageLoadTests(
            bool requestShouldHaveId,
            bool requestShouldHaveControl,
            bool shouldControlStartWithEpm,
            bool requestShouldHaveIntegration,
            bool shouldDataReadFirstCall,
            bool shouldDataReadSecondCall,
            bool shouldSPListItemCollectionBeEmpty)
        {
            _label = new Label();
            _privateObject.SetField(LabelMessageField, _label);
            _pagePrivateObject.SetField(RequestField, (HttpRequest) new ShimHttpRequest());
            ShimHttpRequest.AllInstances.ItemGetString = (_, str) =>
            {
                switch (str)
                {
                case "ID":
                    return(requestShouldHaveId
                            ? DummyId
                            : null);

                case "Control":
                    return(requestShouldHaveControl
                            ? (shouldControlStartWithEpm ? $"epmlive-{DummyControl}" : DummyControl)
                            : null);

                case "IntegrationId":
                    return(requestShouldHaveIntegration
                            ? DummyIntegrationId
                            : null);

                default:
                    return(string.Empty);
                }
            };
            ShimSPFarm.LocalGet = () => new ShimSPFarm();
            var shimSpServiceCollection        = new ShimSPServiceCollection();
            var shimPPersistedObjectCollection = new ShimSPPersistedObjectCollection <SPService>(shimSpServiceCollection);

            shimPPersistedObjectCollection.GetValueOf1String(_ => (SPWebService) new ShimSPWebService());
            ShimSPFarm.AllInstances.ServicesGet = _ => shimSpServiceCollection;
            ShimSPWebService.AllInstances.WebApplicationsGet = _ =>
                                                               (SPWebApplicationCollection) new ShimSPPersistedObjectCollection <SPWebApplication>(new ShimSPWebApplicationCollection())
            {
                GetEnumerator = () => new List <SPWebApplication>
                {
                    (SPWebApplication) new ShimSPPersistedObject(new ShimSPWebApplication())
                    {
                        NameGet = () => "WebApplication"
                    }
                }.GetEnumerator()
            };

            ShimConfigurationManager.AppSettingsGet = () => new ShimNameValueCollection
            {
                ItemGetString = str => str
            };
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code();

            ShimSqlDataReader.AllInstances.GetGuidInt32 = (_, index) => Guids[index];
            var firstCall = true;

            ShimSqlDataReader.AllInstances.Read = _ =>
            {
                if (firstCall)
                {
                    firstCall = false;
                    return(shouldDataReadFirstCall);
                }
                return(shouldDataReadSecondCall);
            };
            ShimSqlDataReader.AllInstances.IsDBNullInt32 = (_1, _2) => false;
            ShimSqlDataReader.AllInstances.GetInt32Int32 = (_1, i) => i;

            ShimSPSite.ConstructorGuid                         = (_1, _2) => { };
            ShimSPSite.AllInstances.OpenWebGuid                = (_1, _2) => new ShimSPWeb();
            ShimSPWeb.AllInstances.UrlGet                      = _ => DummyString;
            ShimSPWeb.AllInstances.ListsGet                    = _ => new ShimSPListCollection();
            ShimSPListCollection.AllInstances.ItemGetGuid      = (_1, _2) => new ShimSPList();
            ShimSPList.AllInstances.GetItemsSPQuery            = (_1, _2) => new ShimSPListItemCollection();
            ShimSPListItemCollection.AllInstances.CountGet     = _ => shouldSPListItemCollectionBeEmpty ? 0 : 1;
            ShimSPListItemCollection.AllInstances.ItemGetInt32 = (_1, _2) => new ShimSPListItem();
            ShimSPListItem.AllInstances.ItemGetString          = (_1, _2) => SpListItemId;

            _parametersAdded = new Dictionary <string, object>();
            ShimSqlCommand.AllInstances.ParametersGet = _ => new ShimSqlParameterCollection();
            ShimSqlParameterCollection.AllInstances.AddWithValueStringObject = (_1, str, obj) =>
            {
                _parametersAdded[str] = obj;
                return(new ShimSqlParameter());
            };
            _pagePrivateObject.SetField(ResponseField, (HttpResponse) new ShimHttpResponse());
            _redirectWasCalled = false;
            redirectUrl        = null;
            ShimHttpResponse.AllInstances.RedirectString = (_1, str) =>
            {
                _redirectWasCalled = true;
                redirectUrl        = str;
            };
            ShimIntegrationCore.ConstructorGuidGuid = (_1, _2, _3) => new ShimIntegrationCore();
            ShimIntegrationCore.AllInstances.GetControlURLGuidGuidStringString = (
                _,
                guid1,
                guid2,
                string1,
                string2) => $"{guid1}{guid2}{string1}{string2}";
        }