コード例 #1
0
        public void WriteValueToListItem_GivenMinimalFieldInfo_ShouldUseCorrespondingValueTypeValueWriter()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var correctWriterWasUsed = false;
                var fieldInfo            = new MinimalFieldInfo <UrlValue>("InternalName", Guid.NewGuid());

                ShimUrlValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (inst, listItem, fieldValueInfo) =>
                {
                    correctWriterWasUsed = true;
                };

                var fakeListItem = new ShimSPListItem().Instance;

                IFieldValueWriter writer;
                using (var scope = UnitTestServiceLocator.BeginLifetimeScope())
                {
                    writer = scope.Resolve <IFieldValueWriter>();
                }

                // Act
                writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(fieldInfo, null));

                // Assert
                Assert.IsTrue(correctWriterWasUsed, "The UrlValueWriter should have been used for the MinimalFieldInfo type.");
            }
        }
コード例 #2
0
ファイル: FieldHelperTest.cs プロジェクト: ASAGARG/Dynamite
        public void EnsureField_WhenEnsuringAMinimalFieldInfoOOTBColumnAsSiteColumn_ShouldFailBecauseSuchOOTBSiteColumnShouldBeAddedByOOTBFeatures()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                BaseFieldInfo textFieldInfo = new MinimalFieldInfo<string>(
                    "Hobbies",
                    new Guid("{203fa378-6eb8-4ed9-a4f9-221a4c1fbf46}"));

                BaseFieldInfo dateFieldInfo = new MinimalFieldInfo<DateTime?>(
                    "Birthday",
                    new Guid("{C4C7D925-BC1B-4f37-826D-AC49B4FB1BC1}"));

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var fieldsCollection = testScope.SiteCollection.RootWeb.Fields;

                    int noOfFieldsBefore = fieldsCollection.Count;

                    // Act + Assert
                    try
                    {
                        SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                        Assert.Fail("Should've thrown NotSupportedException because a MinimalFieldInfo lacks information for site collection ensure operation.");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    try
                    {
                        SPField field = fieldHelper.EnsureField(fieldsCollection, dateFieldInfo);
                        Assert.Fail("Should've thrown NotSupportedException because a MinimalFieldInfo lacks information for site collection ensure operation.");
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
コード例 #3
0
        public void WriteValueToListItem_GivenMinimalFieldInfo_ShouldUseCorrespondingValueTypeValueWriter()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var correctWriterWasUsed = false;
                var fieldInfo = new MinimalFieldInfo<UrlValue>("InternalName", Guid.NewGuid());

                ShimUrlValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (inst, listItem, fieldValueInfo) =>
                {
                    correctWriterWasUsed = true;
                };

                var fakeListItem = new ShimSPListItem().Instance;

                IFieldValueWriter writer;
                using (var scope = UnitTestServiceLocator.BeginLifetimeScope())
                {
                    writer = scope.Resolve<IFieldValueWriter>();
                }

                // Act
                writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(fieldInfo, null));

                // Assert
                Assert.IsTrue(correctWriterWasUsed, "The UrlValueWriter should have been used for the MinimalFieldInfo type.");
            }
        }