Ejemplo n.º 1
0
        public void WhenFillingItemMissingPropertyFailsWithClearException()
        {
            Guid       fieldId1   = new Guid("{95C7711D-E2B5-42f9-B0DB-4C840BED0C74}");
            SPListItem spListItem = Isolate.Fake.Instance <SPListItem>();

            Isolate.WhenCalled(() => spListItem.Name).WillReturn("ItemName");

            var target = new ListItemFieldMapper <TestEntity>();

            target.AddMapping(fieldId1, "NonExistingProperty");

            try
            {
                target.FillSPListItemFromEntity(spListItem, new TestEntity());
                Assert.Fail();
            }
            catch (ListItemFieldMappingException ex)
            {
                Assert.AreEqual(
                    "Type 'Microsoft.Practices.SPG.Common.Tests.ListRepository.TestEntity' does not have a property 'NonExistingProperty' which was mapped to FieldID: '95c7711d-e2b5-42f9-b0db-4c840bed0c74' for SPListItem 'ItemName'."
                    , ex.Message);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 2
0
        public void CanFillSPListItemFromEntity()
        {
            Guid       fieldId1   = Guid.NewGuid();
            Guid       fieldId2   = Guid.NewGuid();
            TestEntity testEntity = new TestEntity()
            {
                Property1String = "teststring", Property2Integer = 321
            };
            SPListItem spListItem  = Isolate.Fake.Instance <SPListItem>();
            object     field1Value = null;
            object     field2Value = null;

            Isolate.WhenCalled(() => spListItem[fieldId1] = "teststring").DoInstead((context) => field1Value = context.Parameters[1]);
            Isolate.WhenCalled(() => spListItem[fieldId2] = 321).DoInstead((context) => field2Value = context.Parameters[1]);


            ListItemFieldMapper <TestEntity> target = new ListItemFieldMapper <TestEntity>();

            target.AddMapping(fieldId1, "Property1String");
            target.AddMapping(fieldId2, "Property2Integer");

            target.FillSPListItemFromEntity(spListItem, testEntity);

            Assert.AreEqual("teststring", field1Value);
            Assert.AreEqual(321, field2Value);
        }
        /// <summary>
        /// Inserts a new item into the "Sub Site Creation Request List". Calling this method will trigger
        /// the "Sub Site Creation Workflow".
        /// </summary>
        /// <param name="request">The request entity containing necessary information to successfully run the Sub Site Creation Workflow.</param>
        public void AddSubSiteCreationRequest(SubSiteCreationRequest request)
        {
            if (request == null)
            {
                throw new SubSiteCreationException(Constants.TheSubSiteCreationRequestWasNullMessage);
            }
            else if (string.IsNullOrEmpty(request.BusinessEvent))
            {
                throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.BusinessEventProperty));
            }
            else if (string.IsNullOrEmpty(request.EventId))
            {
                throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.EventIdProperty));
            }
            else if (string.IsNullOrEmpty(request.SiteCollectionUrl))
            {
                throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.SiteCollectionUrlProperty));
            }

            IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>();
            string adminWebUrl = hierarchicalConfig.GetByKey <string>(Constants.SubSiteCreationConfigSiteKey, ConfigLevel.CurrentSPFarm);

            if (string.IsNullOrEmpty(adminWebUrl))
            {
                throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ConfigSiteNotFoundMessage, Constants.SubSiteCreationConfigSiteKey));
            }

            using (SPSite site = new SPSite(adminWebUrl))
            {
                using (SPWeb adminWeb = site.OpenWeb())
                {
                    SPList     subSiteCreationRequests = adminWeb.Lists[Constants.SubSiteRequestsListName];
                    SPListItem subSiteCreationRequest  = subSiteCreationRequests.Items.Add();
                    ListItemFieldMapper.FillSPListItemFromEntity(subSiteCreationRequest, request);
                    subSiteCreationRequest.Update();
                }
            }
        }