public void GetOrCreateList_Throws_ArgumentNullException()
 {
     using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
     {
         sut.GetOrCreateList(null, SPListTemplateType.DocumentLibrary);
     }
 }
        public void FeatureReceiverAddsWebPartTest()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    var webPartManager = new ShimSPLimitedWebPartManager();
                    new ShimSPWeb(context.Web)
                    {
                        GetLimitedWebPartManagerStringPersonalizationScope = (s, c) =>
                        {
                            return webPartManager;
                        },
                    };

                    webPartManager.WebPartsGet = () =>
                    {
                        var webPartCollection = new ShimSPLimitedWebPartCollection();
                        webPartCollection.ItemGetInt32 = (i) => { return new SalesOrderWebPart(); };

                        return webPartCollection.Instance;
                    };
                }

                var feature = context.Web.Features.FirstOrDefault(f => f.DefinitionId == featureId);
                if (feature == null)
                    context.Web.Features.Add(featureId);

                AssertIfWebpartOnPage(context, true);

                context.Web.Features.Remove(featureId);
            }
        }
 public void GetOrCreateList_Overload_Throws_ArgumentNullException()
 {
     using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
     {
         sut.GetOrCreateList(null);
     }
 }
 public void Can_Construct_Level_Integration()
 {
     using (var sut = new SPEmulationContext(IsolationLevel.Integration, "http://localhost"))
     {
         Assert.AreSame(sut.Site, SPContext.Current.Site);
         Assert.AreSame(sut.Web, SPContext.Current.Web);
         Assert.AreEqual(IsolationLevel.Integration, sut.IsolationLevel);
     }
 }
 public void Can_Construct_Level_Fake()
 {
     using (var sut = new SPEmulationContext(IsolationLevel.Fake))
     {
         Assert.AreSame(sut.Site, SPContext.Current.Site);
         Assert.AreSame(sut.Web, SPContext.Current.Web);
         Assert.AreEqual(IsolationLevel.Fake, sut.IsolationLevel);
     }
 }
 public void Constructor_Throws_On_x86_Process()
 {
     using (var outerShimsContect = ShimsContext.Create())
     {
         System.Fakes.ShimEnvironment.Is64BitProcessGet = () => false;
         using (var sut = new SPEmulationContext((IsolationLevel)255, "http://localhost"))
         {
         }
     }
 }
 public void Can_Construct_Level_None()
 {
     using (var sut = new SPEmulationContext(IsolationLevel.None, "http://localhost"))
     {
         Assert.IsNull(SPContext.Current);
         Assert.IsNotNull(sut.Site);
         Assert.IsNotNull(sut.Web);
         Assert.AreEqual(IsolationLevel.None, sut.IsolationLevel);
     }
 }
        public void CanCreateSalesOrder()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                var salesOrderList = context.GetOrCreateList(
                    SalesOrderListRepository.SalesOrderListName,
                    SPListTemplateType.GenericList,
                    "OrderDate", "Customer", "Status");

                var orderLinesList = context.GetOrCreateList(
                    SalesOrderListRepository.OrderLinesListName,
                    SPListTemplateType.GenericList,
                    "SalesOrder", "Price", "Quantity");

                var repository = new SalesOrderListRepository();

                var customer = new Customer
                {
                    CustomerId = 2,
                    Name = "Customer 2"
                };

                var order = new SalesOrder
                {
                    SalesOrderId = 0,
                    Customer = customer,
                    OrderDate = DateTime.Today,
                    Status = OrderStatus.New
                };


                order.Lines.Add(new OrderLine
                {
                    Product = "Product 1",
                    Quantity = 5,
                    Price = 5.5
                });

                order.Lines.Add(new OrderLine
                {
                    Product = "Product 2",
                    Quantity = 2,
                    Price = 106.5
                });

                int salesOrderCount = salesOrderList.ItemCount;
                int orderLineCount = orderLinesList.ItemCount;

                repository.Add(order);

                Assert.AreEqual<int>(salesOrderCount + 1, salesOrderList.Items.Count);
                Assert.AreEqual<int>(orderLineCount + 2, orderLinesList.Items.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);
            }
        }
Esempio n. 10
0
        private bool IsWebpartOnPage(SPEmulationContext context)
        {
            using (var webPartManager = context.Web.GetLimitedWebPartManager("Default.aspx",
                System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
            {

                var count = context.IsolationLevel != IsolationLevel.Fake ? webPartManager.WebParts.Count : 1;

                for (int i = count - 1; i >= 0; i--)
                {
                    if (webPartManager.WebParts[i].GetType() == typeof(SalesOrderWebPart))
                        return true;
                }

                return false;
            }
        }
        public void GetOrCreateList_Overload_Returns_List_On_Level_None()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.None, "http://localhost"))
            {
                var id = sut.Web.Lists.Add("ADefaultList", "My List Instance", SPListTemplateType.GenericList);
                var list = sut.Web.Lists[id];

                var result = sut.GetOrCreateList(@"..\..\..\SharePointSampleProject\ADefaultList\Elements.xml");

                Assert.AreEqual<Guid>(list.ID, result.ID);

                list.Delete();
            }
        }
 public void Construct_Trows_On_Invalid_level()
 {
     using (var sut = new SPEmulationContext((IsolationLevel)255, "http://localhost"))
     {
     }
 }
        public void GetOrCreateList_Overload_Returns_Custom_List_Instance_by_Elements_And_Schema_With_Default_Data()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var elements = @"..\..\..\SharePointSampleProject\ACustomList\ACustomListInstance\Elements.xml";
                var schema = @"..\..\..\SharePointSampleProject\ACustomList\schema.xml";
                var result = sut.GetOrCreateList(elements, schema);

                result.ItemCount.Should().Be(1);
                result.Items.Count.Should().Be(1);

                var defaultItem = result.Items[0];

                defaultItem.ID.Should().Be(1);
                defaultItem[SPBuiltInFieldId.ID].Should().Be(1);
                defaultItem[SPBuiltInFieldId.Title].Should().Be("MyTitle");
                defaultItem["String Column"].Should().Be("MyString");
                defaultItem[new Guid("{3ca9275d-7289-4ed4-86b8-9fe0d8921330}")].Should().Be(new DateTime(1999, 12, 31));
                defaultItem["User Field"].Should().BeOfType<SPUser>();
                var user = (SPUser)defaultItem["User Field"];
                user.ID.Should().Be(1);
                defaultItem["Lookup Field"].Should().Be(1);
            }
        }
        public void GetOrCreateList_Overload_Returns_Custom_List_Instance_by_Elements_And_Schema()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var elements = @"..\..\..\SharePointSampleProject\ACustomList\ACustomListInstance\Elements.xml";
                var schema = @"..\..\..\SharePointSampleProject\ACustomList\schema.xml";
                var result = sut.GetOrCreateList(elements, schema);

                var list = sut.Web.Lists["ACustomList"];

                Assert.AreSame(result, list);

                //<Field Name="StringColumn" ID="{081246d3-2d7c-4f8c-b754-48dfd4c13646}" DisplayName="String Column" Type="Text" Required="TRUE" />
                var fieldName = "String Column";
                Assert.IsNotNull(list.Fields[fieldName]);
                Assert.IsNotNull(list.Fields.GetFieldByInternalName("StringColumn"));
                Assert.AreEqual<Guid>(new Guid("{081246d3-2d7c-4f8c-b754-48dfd4c13646}"), list.Fields[fieldName].Id);
                Assert.AreEqual<string>("StringColumn", list.Fields[fieldName].InternalName);
                Assert.AreEqual<string>("String Column", list.Fields[fieldName].Title);
                Assert.AreEqual<SPFieldType>(SPFieldType.Text, list.Fields[fieldName].Type);
                Assert.IsTrue(list.Fields[fieldName].Required);

                //<Field Name="DateAndTimeColumn" ID="{3ca9275d-7289-4ed4-86b8-9fe0d8921330}" DisplayName="Date And Time Column" Type="DateTime" />
                fieldName = "Date And Time Column";
                Assert.IsNotNull(list.Fields[fieldName]);
                Assert.IsNotNull(list.Fields.GetFieldByInternalName("DateAndTimeColumn"));
                Assert.AreEqual<Guid>(new Guid("{3ca9275d-7289-4ed4-86b8-9fe0d8921330}"), list.Fields[fieldName].Id);
                Assert.AreEqual<string>("DateAndTimeColumn", list.Fields[fieldName].InternalName);
                Assert.AreEqual<string>("Date And Time Column", list.Fields[fieldName].Title);
                Assert.AreEqual<SPFieldType>(SPFieldType.DateTime, list.Fields[fieldName].Type);
                Assert.IsFalse(list.Fields[fieldName].Required);

                //<Field Name="LookupField" ID="{86af6c5f-3a60-49b1-b77d-ce7bf0d02d7c}" DisplayName="Lookup Field" Type="Lookup" ShowField="Title" List="Lists/ADefaultList" />
                fieldName = "Lookup Field";
                Assert.IsNotNull(list.Fields[fieldName]);
                Assert.IsNotNull(list.Fields.GetFieldByInternalName("LookupField"));
                Assert.AreEqual<Guid>(new Guid("{86af6c5f-3a60-49b1-b77d-ce7bf0d02d7c}"), list.Fields[fieldName].Id);
                Assert.AreEqual<string>("LookupField", list.Fields[fieldName].InternalName);
                Assert.AreEqual<string>(fieldName, list.Fields[fieldName].Title);
                Assert.AreEqual<SPFieldType>(SPFieldType.Lookup, list.Fields[fieldName].Type);
                Assert.IsFalse(list.Fields[fieldName].Required);
                
                //<Field Name="User1" ID="{e7665fd0-64de-4068-a56e-3f1dff5432a3}" DisplayName="User Field" Type="User" List="UserInfo" />
                fieldName = "User Field";
                Assert.IsNotNull(list.Fields[fieldName]);
                Assert.IsNotNull(list.Fields.GetFieldByInternalName("User1"));
                Assert.AreEqual<Guid>(new Guid("{e7665fd0-64de-4068-a56e-3f1dff5432a3}"), list.Fields[fieldName].Id);
                Assert.AreEqual<string>("User1", list.Fields[fieldName].InternalName);
                Assert.AreEqual<string>(fieldName, list.Fields[fieldName].Title);
                Assert.AreEqual<SPFieldType>(SPFieldType.User, list.Fields[fieldName].Type);
                Assert.IsFalse(list.Fields[fieldName].Required);
            }
        }
Esempio n. 15
0
 private void AssertIfWebpartOnPage(SPEmulationContext context, bool expected)
 {
     Assert.AreEqual<bool>(expected, IsWebpartOnPage(context));
 }
        public void GetOrCreateList_Overload_Supports_Default_Data()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var result = sut.GetOrCreateList(@"..\..\..\SharePointSampleProject\ADefaultList\Elements.xml");

                var list = sut.Web.Lists["ADefaultList"];

                Assert.IsNotNull(list);
                Assert.AreEqual<int>(2, list.ItemCount);
                Assert.AreEqual<int>(1, list.Items[0].ID);
                Assert.AreEqual<int>(2, list.Items[1].ID);
                Assert.AreEqual<string>("Default Item 1", list.Items[0]["Title"].ToString());
                Assert.AreEqual<string>("Default Item 2", list.Items[1]["Title"].ToString());
            }
        }
        public void GetOrCreateList_Returns_List_With_Fields()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var result = sut.GetOrCreateList("MyList", SPListTemplateType.DocumentLibrary, "MyCustomField1", "MyCustomField2");

                var list = sut.Web.Lists["MyList"];

                Assert.IsNotNull(list);
                Assert.IsNotNull(list.Fields.GetFieldByInternalName("MyCustomField1"));
            }
        }
        public void GetOrCreateList_Returns_List_On_Level_Fake()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var result = sut.GetOrCreateList("MyList", SPListTemplateType.DocumentLibrary);

                var list = sut.Web.Lists["MyList"];

                Assert.IsNotNull(list);
            }
        }
        public void GetOrCreateList_Returns_List_On_Level_Integration()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Integration, "http://localhost"))
            {
                var id = sut.Web.Lists.Add("MyList", "a description", SPListTemplateType.GenericList);
                var list = sut.Web.Lists[id];

                var result = sut.GetOrCreateList("MyList", SPListTemplateType.DocumentLibrary);

                Assert.AreEqual<Guid>(list.ID, result.ID);

                list.Delete();
            }
        }
        public void GetOrCreateList_Overload_Supports_Document_Libraries()
        {
            using (var sut = new SPEmulationContext(IsolationLevel.Fake, "http://localhost"))
            {
                var result = sut.GetOrCreateList(@"..\..\..\SharePointSampleProject\ADefaultDocumentLibrary\Elements.xml");

                var list = sut.Web.Lists["ADefaultDocumentLibrary"];

                Assert.AreSame(result, list);

                Assert.IsNotNull(list);
                Assert.AreEqual<string>("My List Instance", list.Description);
                Assert.AreEqual<SPListTemplateType>(SPListTemplateType.DocumentLibrary, list.BaseTemplate);
                Assert.IsTrue(list.OnQuickLaunch);
                Assert.AreNotEqual<int>(0, list.Fields.Count);
                Assert.IsNotNull(list.Fields[SPBuiltInFieldId.Title]);
                Assert.IsNotNull(list.Fields[SPBuiltInFieldId.ID]);
            }
        }