Exemplo n.º 1
0
        public void CanGetListOfCustomers()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                var item2 = context.CustomerList.Items.Add();
                item2["Title"] = "Customer 1";
                item2.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new[] { item, item2 });
                        return(shim.Instance);
                    }
                };
            }

            var result = repository.GetAll();

            Assert.AreEqual(2, result.Count());
        }
        public void SetUp()
        {
            _shimsContext = ShimsContext.Create();

            _resourceUrl = "http://test.test";

            _webServerRelativeUrl = "http://test.test";

            _resourcePlanListsString = "1,2,3";
            _siteId   = Guid.NewGuid();
            _hours    = 1;
            _workdays = "1";

            _listItemShim = new ShimSPListItem
            {
                ItemGetGuid = id => new object()
            };

            var listItemCollection = new ShimSPListItemCollection();

            var webList = new ShimSPList
            {
                GetItemsSPQuery = query =>
                {
                    return(listItemCollection.Bind(new[] { _listItemShim.Instance }));
                },
                FieldsGet = () => new ShimSPFieldCollection
                {
                    GetFieldByInternalNameString = name => new ShimSPField()
                }
            };

            var webListCollectionShim = new ShimSPListCollection
            {
                ItemGetString = (name) => webList.Instance
            };

            _webShim = new ShimSPWeb
            {
                ServerRelativeUrlGet = () => _webServerRelativeUrl,
                ListsGet             = () => webListCollectionShim.Instance
            };

            ShimSPFieldLookupValue.ConstructorString = (element, name) =>
                                                       new ShimSPFieldLookupValue();

            _spFieldUserValues = new List <SPFieldUserValue>
            {
                new SPFieldUserValue(_webShim.Instance, "1"),
                new SPFieldUserValue(_webShim.Instance, "2"),
            };

            // (CC-76656, 2018-07-18) Sadly, can not shim SPFieldUserValueCollection constructor to be able to contain elements, due to SP limitations
            // Therefore, can not test ResourceInfo generation
        }
        private void PrepareSpContext()
        {
            ShimSPContext.CurrentGet          = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet = _ => new ShimSPWeb();

            ShimSPWebCollection.AllInstances.ItemGetGuid = (_, __) => new ShimSPWeb();
            var listCollection = new ShimSPListCollection();

            ShimSPWeb.AllInstances.ListsGet       = _ => listCollection.Bind(new SPList[] { new ShimSPList() });
            ShimSPWeb.AllInstances.SiteGet        = _ => new ShimSPSite();
            ShimSPWeb.AllInstances.CurrentUserGet = _ => new ShimSPUser();
            ShimSPWeb.AllInstances.Close          = _ => { };
            ShimSPUser.AllInstances.IDGet         = _ => Id;

            ShimSPSite.ConstructorGuid                 = (_, __) => { };
            ShimSPSite.AllInstances.OpenWeb            = _ => new ShimSPWeb();
            ShimSPSite.AllInstances.OpenWebGuid        = (_, __) => new ShimSPWeb();
            ShimSPSite.AllInstances.AllWebsGet         = _ => new ShimSPWebCollection();
            ShimSPSite.AllInstances.ContentDatabaseGet = _ => new ShimSPContentDatabase();
            ShimSPSite.AllInstances.SiteIdGet          = _ => DefaultSiteId;
            ShimSPSite.AllInstances.IDGet              = _ => DefaultSiteId;
            ShimSPSite.AllInstances.Close              = _ => { };

            ShimSPListCollection.AllInstances.ItemGetString = (_, __) => new ShimSPList();
            ShimSPListCollection.AllInstances.ItemGetGuid   = (_, __) => new ShimSPList();
            ShimSPList.AllInstances.TitleGet = _ => ListTitle;
            var listItemCollection = new ShimSPListItemCollection();

            ShimSPList.AllInstances.GetItemsSPQuery = (_, __) => listItemCollection.Bind(new SPListItem[] { new ShimSPListItem() });
            var fieldCollection = new ShimSPFieldCollection();

            ShimSPList.AllInstances.FieldsGet    = _ => fieldCollection.Bind(new SPField[] { new ShimSPField() });
            ShimSPListItem.AllInstances.TitleGet = _ => DummyString;

            ShimSPFieldCollection.AllInstances.ItemGetString = (_, __) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.ContainsFieldString          = (_, __) => true;
            ShimSPField.AllInstances.TypeGet         = _ => SPFieldType.Text;
            ShimSPField.AllInstances.TitleGet        = _ => FieldTitle;
            ShimSPField.AllInstances.InternalNameGet = _ => Title;
            ShimSPField.AllInstances.ReorderableGet  = _ => true;

            ShimSPFieldMultiChoice.AllInstances.ChoicesGet = _ => new StringCollection {
                DummyString
            };
            ShimSPFieldLookup.AllInstances.LookupWebIdGet = _ => DefaultWebId;

            ShimSPDatabase.AllInstances.DatabaseConnectionStringGet             = _ => DummyString;
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code?.Invoke();
        }
        public void CanGetSalesOrderByCustomer()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                var solutionRelativePath = @"..\..\..\SalesOrderPortalSolution\Lists\";
                var salesOrderList = context.GetOrCreateList(solutionRelativePath + "SalesOrders\\Elements.xml", solutionRelativePath + "SalesOrders\\schema.xml");
                var orderLinesList = context.GetOrCreateList(solutionRelativePath + "OrderLines\\Elements.xml", solutionRelativePath + "OrderLines\\schema.xml");

                var repository = new SalesOrderListRepository();

                // CAML not yet supported. Fake queries.
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    new ShimSPList(salesOrderList)
                    {
                        GetItemsSPQuery = (q) =>
                            {
                                var shim = new ShimSPListItemCollection();
                                shim.Bind(salesOrderList.Items.Cast<SPListItem>().Where(i => (int)i["Customer"] == 1));

                                return shim.Instance;
                            }
                    };

                    new ShimSPList(orderLinesList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim = new ShimSPListItemCollection();
                            var match = Regex.Match(q.Query, "<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >.*?</Value>");
                            var lookupId = int.Parse(match.Value.Replace("<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >", "").Replace("</Value>", ""));
                            shim.Bind(orderLinesList.Items.Cast<SPListItem>().Where(i => (int)i["SalesOrder"] == 1));

                            return shim.Instance;
                        }
                    };
                }

                var customer1 = new Customer
                {
                    CustomerId = 1,
                    Name = "Customer 1"
                };

                var salesOrdersOfCustomer1 = repository.GetByCustomer(customer1);
                Assert.AreEqual<int>(2, salesOrdersOfCustomer1.Count());
                Assert.AreEqual<int>(2, salesOrdersOfCustomer1.First().Lines.Count);
            }
        }
        public void CanGetSalesOrderByCustomer()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                var solutionRelativePath = @"..\..\..\SalesOrderPortalSolution\Lists\";
                var salesOrderList       = context.GetOrCreateList(solutionRelativePath + "SalesOrders\\Elements.xml", solutionRelativePath + "SalesOrders\\schema.xml");
                var orderLinesList       = context.GetOrCreateList(solutionRelativePath + "OrderLines\\Elements.xml", solutionRelativePath + "OrderLines\\schema.xml");

                var repository = new SalesOrderListRepository();

                // CAML not yet supported. Fake queries.
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    new ShimSPList(salesOrderList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim = new ShimSPListItemCollection();
                            shim.Bind(salesOrderList.Items.Cast <SPListItem>().Where(i => (int)i["Customer"] == 1));

                            return(shim.Instance);
                        }
                    };

                    new ShimSPList(orderLinesList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim     = new ShimSPListItemCollection();
                            var match    = Regex.Match(q.Query, "<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >.*?</Value>");
                            var lookupId = int.Parse(match.Value.Replace("<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >", "").Replace("</Value>", ""));
                            shim.Bind(orderLinesList.Items.Cast <SPListItem>().Where(i => (int)i["SalesOrder"] == 1));

                            return(shim.Instance);
                        }
                    };
                }

                var customer1 = new Customer
                {
                    CustomerId = 1,
                    Name       = "Customer 1"
                };

                var salesOrdersOfCustomer1 = repository.GetByCustomer(customer1);
                Assert.AreEqual <int>(2, salesOrdersOfCustomer1.Count());
                Assert.AreEqual <int>(2, salesOrdersOfCustomer1.First().Lines.Count);
            }
        }
Exemplo n.º 6
0
        private void PrepareSpContext()
        {
            ShimSPContext.CurrentGet               = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet      = _ => new ShimSPWeb();
            ShimSPContext.AllInstances.ListItemGet = _ => new ShimSPListItem();

            ShimCoreFunctions.getLockedWebSPWeb = web => DefaultWebId;
            ShimCoreFunctions.iGetConfigSettingSPWebStringBooleanBoolean = (a, b, c, d) => string.Empty;
            ShimUtils.GetConfigWebSPWebGuid = (_, __) => new ShimSPWeb();
            var listCollection = new ShimSPListCollection();

            ShimSPWeb.AllInstances.ListsGet            = _ => listCollection.Bind(new SPList[] { new ShimSPList() });
            ShimSPWeb.AllInstances.CurrentUserGet      = _ => new ShimSPUser();
            ShimSPWeb.AllInstances.RegionalSettingsGet = _ => new ShimSPRegionalSettings();
            ShimSPWeb.AllInstances.Close = _ => { };

            ShimSPSite.ConstructorString = (_, __) =>
            {
                ShimSPSite.AllInstances.OpenWeb = x => new ShimSPWeb();
                ShimSPSite.AllInstances.Close   = x => { };
            };

            ShimSPListCollection.AllInstances.GetListGuidBoolean = (a, b, c) => new ShimSPList();
            ShimSPListCollection.AllInstances.ItemGetString      = (_, __) => new ShimSPList();
            var fieldCollection = new ShimSPFieldCollection();

            ShimSPList.AllInstances.FieldsGet = _ => fieldCollection.Bind(new SPField[] { new ShimSPField() });
            var listItemCollection = new ShimSPListItemCollection();

            ShimSPList.AllInstances.ItemsGet          = _ => listItemCollection.Bind(new SPListItem[] { new ShimSPListItem().Instance });
            ShimSPListItem.AllInstances.IDGet         = _ => Id;
            ShimSPListItem.AllInstances.TitleGet      = _ => "LITitle";
            ShimSPListItem.AllInstances.ItemGetString = (_, key) => GetListItemValue(key);

            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPFieldLookup();
            ShimSPField.AllInstances.GetCustomPropertyString = (_, key) => key;

            ShimSPFieldLookup.AllInstances.LookupListGet = _ => DefaultListId.ToString();

            ShimSPFieldUserValue.ConstructorSPWebString = (a, b, c) => { };
            ShimSPFieldUserValue.AllInstances.UserGet   = _ => new ShimSPUser();
            ShimSPUser.AllInstances.IDGet = _ => Id;

            ShimSPFieldLookupValue.ConstructorString        = (_, __) => { };
            ShimSPFieldLookupValue.AllInstances.LookupIdGet = _ => Id;

            ShimSPRegionalSettings.AllInstances.LocaleIdGet = _ => (uint)CultureInfo.InvariantCulture.LCID;
        }
        public void GetCustomerByNameReturnsNull()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new SPListItem[0]);
                        return shim.Instance;
                    }
                };
            }

            var result = repository.GetByName("Customer XXX");
            Assert.IsNull(result);
        }
Exemplo n.º 8
0
        public void GetCustomerByNameReturnsNull()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new SPListItem[0]);
                        return(shim.Instance);
                    }
                };
            }

            var result = repository.GetByName("Customer XXX");

            Assert.IsNull(result);
        }
        public void CanGetListOfCustomers()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                var item2 = context.CustomerList.Items.Add();
                item2["Title"] = "Customer 1";
                item2.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new[] { item, item2 });
                        return shim.Instance;
                    }
                };
            }

            var result = repository.GetAll();
            Assert.AreEqual(2, result.Count());
        }