Пример #1
0
 public static string TagsText(this TextFieldInfo self)
 => self.Tags.Length == 0 ? "" :
 self.Tags.Aggregate(
     new StringBuilder(""),
     (builder, tag) => builder.Append(PaddedTagName(tag.Name)))
 .ToString()
 .Replace(" ", space);
Пример #2
0
        private static void addProjectAttachmentsIfNeeded(TextFieldInfo info, NSMutableAttributedString finalString)
        {
            if (string.IsNullOrEmpty(info.ProjectColor))
            {
                return;
            }

            var color = MvxColor.ParseHexString(info.ProjectColor).ToNativeColor();

            var projectName = new NSAttributedString(info.ProjectName.TruncatedAt(maxTextLength), new UIStringAttributes
            {
                Font            = tokenFont,
                ForegroundColor = color
            });

            var textAttachment = new TokenTextAttachment(
                projectName,
                textVerticalOffset,
                color,
                regularFont.Descender,
                textFieldInfoTokenLeftMargin,
                textFieldInfoTokenRightMargin
                );
            var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment));
            var attributes  = new UIStringAttributes {
                ParagraphStyle = paragraphStyle
            };

            attributes.Dictionary[Project] = new NSObject();
            tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length));

            finalString.Append(tokenString);
        }
            public void RemovesTheReportedTagFromTheCurrentTextFieldInfo(int index)
            {
                var workspace = Substitute.For <IDatabaseWorkspace>();

                workspace.Name.Returns("Some workspace");
                var tag = Substitute.For <IDatabaseTag>();

                tag.Name.Returns("Some tag");
                tag.Id.Returns(1);
                tag.Workspace.Returns(workspace);
                tag.WorkspaceId.Returns(3);
                var tag2 = Substitute.For <IDatabaseTag>();

                tag2.Name.Returns("Some tag 2");
                tag2.Id.Returns(2);
                tag2.Workspace.Returns(workspace);
                tag2.WorkspaceId.Returns(3);
                TargetBinding.SetValue(
                    TextFieldInfo
                    .Empty(1)
                    .AddTag(new TagSuggestion(tag))
                    .AddTag(new TagSuggestion(tag2)));

                EventProvider.RaiseTagDeleted(index);

                TargetBinding.TextFieldInfo.Tags.Single().TagId.Should().Be(index == 0 ? 2 : 1);
            }
 private void onProjectDeleted(object sender, EventArgs e)
 {
     onTextFieldInfoChanged(
         TextFieldInfo
         .RemoveProjectInfo()
         .WithTextAndCursor(TextFieldInfo.Text, TextFieldInfo.Text.Length));
 }
Пример #5
0
        public static TextFieldInfo FromTimeEntrySuggestion(
            this TextFieldInfo textFieldInfo,
            TimeEntrySuggestion timeEntrySuggestion)
        {
            var builder = ImmutableList.CreateBuilder <ISpan>();

            builder.Add(new TextSpan(timeEntrySuggestion.Description));

            if (timeEntrySuggestion.HasProject)
            {
                var projectSpan = new ProjectSpan(
                    timeEntrySuggestion.ProjectId.Value,
                    timeEntrySuggestion.ProjectName,
                    timeEntrySuggestion.ProjectColor,
                    timeEntrySuggestion.TaskId,
                    timeEntrySuggestion.TaskName
                    );

                builder.Add(projectSpan);
            }

            builder.Add(new QueryTextSpan());

            return(TextFieldInfo
                   .Empty(timeEntrySuggestion.WorkspaceId)
                   .ReplaceSpans(builder.ToImmutable()));
        }
Пример #6
0
        public void WriteValueToListItem_GivenTextFieldInfo_ShouldUseBaseValueWriter()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var correctWriterWasUsed = false;
                var fieldInfo            = new TextFieldInfo("InternalName", Guid.NewGuid(), string.Empty, string.Empty, string.Empty);

                ShimStringValueWriter.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 BaseValueWriter should have been used for the TextFieldInfo type.");
            }
        }
 private void onTagDeleted(object sender, TagDeletedEventArgs e)
 {
     onTextFieldInfoChanged(
         TextFieldInfo
         .RemoveTag(TextFieldInfo.Tags[e.TagIndex])
         .WithTextAndCursor(TextFieldInfo.Text, e.CursorPosition));
 }
        private void onTextFieldInfo(TextFieldInfo textFieldInfo)
        {
            var(formattedText, cursorPosition) = textFieldInfo.AsSpannableTextAndCursorPosition();

            editText.TextFormatted = formattedText;
            editText.SetSelection(cursorPosition);
        }
Пример #9
0
        public static TextFieldInfo FromQuerySymbolSuggestion(
            this TextFieldInfo textFieldInfo,
            QuerySymbolSuggestion querySymbolSuggestion)
        {
            var result = textFieldInfo.AddQuerySymbol(querySymbolSuggestion.Symbol);

            return(result);
        }
Пример #10
0
        public static TextFieldInfo FromTagSuggestion(
            this TextFieldInfo textFieldInfo,
            TagSuggestion tagSuggestion)
        {
            var result = textFieldInfo.AddTag(tagSuggestion.TagId, tagSuggestion.Name);

            return(result);
        }
                public async Task WhenTheUserBeginsTypingADescription(string description)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 0);

                    await Provider.Query(textFieldInfo);

                    await Database.TimeEntries.Received().GetAll();
                }
Пример #12
0
                public void DoesNotExtractTheProjectNameWhenCursorIsMovedBeforeTheAtSymbol(string text, int cursorPosition)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, cursorPosition);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().NotBe(AutocompleteSuggestionType.Projects);
                }
Пример #13
0
            public void DoesNotAddTagIfAlreadyAdded()
            {
                var textFieldInfo =
                    TextFieldInfo.Empty(WorkspaceId)
                    .AddTag(1, "1")
                    .AddTag(1, "1");

                textFieldInfo.Spans.OfType <TagSpan>().Should().HaveCount(1);
            }
Пример #14
0
        private void clearTagsIfNeeded(long currentWorkspaceId, long newWorkspaceId)
        {
            if (currentWorkspaceId == newWorkspaceId)
            {
                return;
            }

            TextFieldInfo = TextFieldInfo.ClearTags();
        }
Пример #15
0
                public void ExtractTheTagtNameFromTheFirstHashSymbolWithPreceededWithAWhiteSpaceOrAtTheVeryBeginningOfTheText(string text, string expectedTagName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, text.Length);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Tags);
                    parsed.Text.Should().Be(expectedTagName);
                }
Пример #16
0
                public void ExtractsTheProjectNameWhileTyping(string text, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, text.Length);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
                public async Task WhenTheSearchStringIsEmpty()
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor("", 0);

                    var suggestions = await Provider.Query(textFieldInfo);

                    suggestions.Should().HaveCount(2)
                    .And.AllBeOfType <QuerySymbolSuggestion>();
                }
Пример #18
0
                public void ExtractTheProjectNameFromTheFirstAtSymbolPrecedingTheCursor(string text, int cursorPosition, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).ReplaceSpans(new QueryTextSpan(text, cursorPosition));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
Пример #19
0
                public void DoesNotSuggestAnythingWhenTheTextIsEmpty(string text)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, 0);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.None);
                    parsed.Text.Should().Be(String.Empty);
                }
                public async Task WhenTheHashtagSymbolIsTyped(string description)
                {
                    var actualDescription = $"{description} #{description}";
                    var textFieldInfo     = TextFieldInfo.Empty(1).WithTextAndCursor(actualDescription, description.Length + 2);

                    await Provider.Query(textFieldInfo);

                    await Database.Tags.Received().GetAll();
                }
Пример #21
0
            public void RemovesTheTagQueryIfAnyHashtagSymbolIsPresent()
            {
                var newDescription = $"{Description}#something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .ReplaceSpans(new QueryTextSpan(newDescription, newDescription.Length))
                                    .RemoveTagQueryIfNeeded();

                textFieldInfo.GetQuerySpan().Text.Should().Be(Description);
            }
                public async Task WhenTheUserHasTypedAnySearchSymbolsButMovedTheCaretToAnIndexThatComesBeforeTheSymbol(
                    string description)
                {
                    var actualDescription = $"{description} @{description}";
                    var textFieldInfo     = TextFieldInfo.Empty(1).WithTextAndCursor(actualDescription, 0);

                    await Provider.Query(textFieldInfo);

                    await Database.TimeEntries.Received().GetAll();
                }
Пример #23
0
            public void RemovesTheTagQueryIfAnyHashtagSymbolIsPresent()
            {
                var newDescription = $"{Description}#something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .WithTextAndCursor(newDescription, newDescription.Length)
                                    .RemoveTagQueryFromDescriptionIfNeeded();

                textFieldInfo.Text.Should().Be(Description);
            }
Пример #24
0
                public void ExtractTheProjectNameFromTheFirstAtSymbolWithPreceededWithAWhiteSpaceOrAtTheVeryBeginningOfTheText(string text, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, text.Length));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
Пример #25
0
                public void ExtractsTheTagNameWhileTyping(string text, string expectedTagName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, text.Length));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Tags);
                    parsed.Text.Should().Be(expectedTagName);
                }
Пример #26
0
        public static ISpannable GetSpannableText(this TextFieldInfo self)
        {
            var builder = new SpannableStringBuilder();

            builder.Append(self.Text);
            builder.AppendProjectToken(self);
            builder.AppendTagTokens(self);

            return(builder);
        }
Пример #27
0
            protected TextFieldInfo CreateDefaultTextFieldInfo()
            {
                var spans = new ISpan[]
                {
                    new QueryTextSpan(Description, Description.Length),
                    new ProjectSpan(ProjectId, ProjectName, ProjectColor, TaskId, TaskName)
                };

                return(TextFieldInfo.Empty(WorkspaceId).ReplaceSpans(spans.ToImmutableList()));
            }
Пример #28
0
                public void DoesNotSuggestAnythingWhenTheTextIsEmpty(string text)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, 0));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.None);
                    parsed.Text.Should().Be(String.Empty);
                }
Пример #29
0
            public void DoesNotAddTagIfAlreadyAdded()
            {
                var tag = createTagSuggestion(1);

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .AddTag(tag)
                                    .AddTag(tag);

                textFieldInfo.Tags.Should().HaveCount(1);
            }
Пример #30
0
        public static NSAttributedString GetAttributedText(this TextFieldInfo self)
        {
            var projectName    = self.PaddedProjectAndTaskName();
            var tags           = self.TagsText();
            var fullText       = $"{self.Text}{projectName}{tags}";
            var result         = new NSMutableAttributedString(fullText);
            var baselineOffset = string.IsNullOrEmpty(self.Text) ? 5 : 3;

            result.AddAttributes(new UIStringAttributes
            {
                ParagraphStyle = paragraphStyle,
                Font           = UIFont.SystemFontOfSize(16, UIFontWeight.Regular),
            }, new NSRange(0, self.Text.Length));

            if (!string.IsNullOrEmpty(self.ProjectColor))
            {
                var color = MvxColor.ParseHexString(self.ProjectColor).ToNativeColor();

                var attributes = new UIStringAttributes
                {
                    ForegroundColor = color,
                    StrokeColor     = strokeColor,
                    BaselineOffset  = baselineOffset,
                    ParagraphStyle  = paragraphStyle,
                    Font            = UIFont.SystemFontOfSize(12, UIFontWeight.Regular),
                };
                attributes.Dictionary[TimeEntryTagsTextView.RoundedBackground] = color.ColorWithAlpha(0.12f);

                result.AddAttributes(attributes, new NSRange(self.Text.Length, projectName.Length));
            }

            if (!string.IsNullOrEmpty(tags))
            {
                var startingPosition = self.Text.Length + projectName.Length;

                for (int i = 0; i < self.Tags.Length; i++)
                {
                    var tagLength = self.Tags[i].Name.Length + 6;

                    var attributes = new UIStringAttributes
                    {
                        BaselineOffset = baselineOffset,
                        ParagraphStyle = paragraphStyle,
                        Font           = UIFont.SystemFontOfSize(12, UIFontWeight.Regular),
                    };
                    attributes.Dictionary[TimeEntryTagsTextView.TagIndex]       = new NSNumber(i);
                    attributes.Dictionary[TimeEntryTagsTextView.RoundedBorders] = strokeColor;
                    result.AddAttributes(attributes, new NSRange(startingPosition, tagLength));

                    startingPosition += tagLength;
                }
            }

            return(result);
        }
Пример #31
0
        public void TextFieldInfo_ShouldBeAbleToCreateFromXml()
        {
            var xmlElement = XElement.Parse("<Field Name=\"SomeInternalName\" Type=\"Text\" ID=\"{7a937493-3c82-497c-938a-d7a362bd8086}\" StaticName=\"SomeInternalName\" DisplayName=\"SomeDisplayName\" Description=\"SomeDescription\" Group=\"Test\" EnforceUniqueValues=\"FALSE\" ShowInListSettings=\"TRUE\" MaxLength=\"255\" />");
            var textFieldDefinition = new TextFieldInfo(xmlElement);

            Assert.AreEqual("SomeInternalName", textFieldDefinition.InternalName);
            Assert.AreEqual("Text", textFieldDefinition.FieldType);
            Assert.AreEqual(new Guid("{7a937493-3c82-497c-938a-d7a362bd8086}"), textFieldDefinition.Id);
            Assert.AreEqual("SomeDisplayName", textFieldDefinition.DisplayNameResourceKey);
            Assert.AreEqual("SomeDescription", textFieldDefinition.DescriptionResourceKey);
            Assert.AreEqual("Test", textFieldDefinition.GroupResourceKey);
            Assert.AreEqual(255, textFieldDefinition.MaxLength);
        }
Пример #32
0
        public void EnsureField_WhenNotAlreadyExists_ShouldAddAndReturnField()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName", 
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

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

                    int noOfFieldsBefore = fieldsCollection.Count;

                    // Act
                    SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    // Assert
                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(field);
                    Assert.AreEqual(textFieldInfo.Id, field.Id);
                    Assert.AreEqual(textFieldInfo.InternalName, field.InternalName);
                    Assert.AreEqual(textFieldInfo.DisplayNameResourceKey, field.TitleResource.Value);
                    Assert.AreEqual(textFieldInfo.DescriptionResourceKey, field.DescriptionResource.Value);
                    Assert.AreEqual(textFieldInfo.GroupResourceKey, field.Group);

                    SPField fieldRefetched = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id];
                    Assert.AreEqual(textFieldInfo.Id, fieldRefetched.Id);
                    Assert.AreEqual(textFieldInfo.InternalName, fieldRefetched.InternalName);
                    Assert.AreEqual(textFieldInfo.DisplayNameResourceKey, fieldRefetched.TitleResource.Value);
                    Assert.AreEqual(textFieldInfo.DescriptionResourceKey, fieldRefetched.DescriptionResource.Value);
                    Assert.AreEqual(textFieldInfo.GroupResourceKey, fieldRefetched.Group);
                }                
            }
        }
Пример #33
0
        public void EnsureField_WhenTextFieldInfo_ShouldApplyEnforceUniqueValuesProperty()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                TextFieldInfo noValueTextFieldInfo = new TextFieldInfo(
                    "TestInternalNameDefaultText",
                    new Guid("{7BEB995F-C696-453B-BA86-09A32381C783}"),
                    "NameKeyDefaults",
                    "DescriptionKeyDefaults",
                    "GroupKey");

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

                    // Text field on/off
                    SPField textField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                    Assert.AreEqual(textFieldInfo.EnforceUniqueValues, textField.EnforceUniqueValues);  // both should be true

                    SPField defaultValueTextField = fieldHelper.EnsureField(fieldsCollection, noValueTextFieldInfo);
                    Assert.AreEqual(false, defaultValueTextField.EnforceUniqueValues);  // default should be false
                }
            }
        }
Пример #34
0
        public void EnsureField_WhenAttemptingToChangeFieldType_ShouldFailToUpdateAndReturnExistingField()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    Required = RequiredType.NotRequired,
                    MaxLength = 50
                };

                NoteFieldInfo noteFieldInfoWithSameNameAndId = new NoteFieldInfo(   // different type
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),  // same GUID and same internal name
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    Required = RequiredType.Required
                };

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

                    // STEP 1: Create the first field
                    int noOfFieldsBefore = fieldsCollection.Count;
                    SPField originalField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    Assert.AreEqual(textFieldInfo.Id, originalField.Id);
                    Assert.AreEqual(textFieldInfo.InternalName, originalField.InternalName);

                    // STEP 2: Try to create the type-switching evil alternate field
                    SPField alternateEnsuredField = fieldHelper.EnsureField(fieldsCollection, noteFieldInfoWithSameNameAndId);

                    Assert.AreEqual("Text", alternateEnsuredField.TypeAsString);   // not a Note/SPFieldMultilineText

                    // The returned field shouldn't have gotten its properties updated
                    // (as in this shouldn't happen: "Ensure and Update existing other
                    // unrelated field which has clashing Guid/Internal name")
                    Assert.IsFalse(alternateEnsuredField.Required);     // false like original Text field (fail update Note was Required=True)
                }
            }
        }
Пример #35
0
        public void EnsureField_ShouldProperlyInitializeAllFieldBasicProperties()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                    {
                        EnforceUniqueValues = true,
                        IsHidden = true,
                        IsHiddenInDisplayForm = true,
                        IsHiddenInNewForm = false,
                        IsHiddenInEditForm = false,
                        IsHiddenInListSettings = false,
                        MaxLength = 50,
                        Required = RequiredType.Required
                    };

                TextFieldInfo alternateTextFieldInfo = new TextFieldInfo(
                    "TestInternalNameAlt",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                    {
                        EnforceUniqueValues = false,
                        IsHidden = false,
                        IsHiddenInDisplayForm = false,
                        IsHiddenInNewForm = true,
                        IsHiddenInEditForm = true,
                        IsHiddenInListSettings = true,
                        MaxLength = 500,
                        Required = RequiredType.NotRequired
                    };

                TextFieldInfo defaultsTextFieldInfo = new TextFieldInfo(
                    "TestInternalNameDefaults",
                    new Guid("{7BEB995F-C696-453B-BA86-09A32381C783}"),
                    "NameKeyDefaults",
                    "DescriptionKeyDefaults",
                    "GroupKey");

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

                    // 1) First field definition
                    int noOfFieldsBefore = fieldsCollection.Count;
                    SPField originalField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(originalField);
                    this.ValidateFieldBasicValues(textFieldInfo, originalField);

                    SPField originalFieldRefetched = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id];
                    this.ValidateFieldBasicValues(textFieldInfo, originalFieldRefetched);

                    // 2) Alternate field definition
                    SPField alternateEnsuredField = fieldHelper.EnsureField(fieldsCollection, alternateTextFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 2, fieldsCollection.Count);
                    Assert.IsNotNull(alternateEnsuredField);
                    this.ValidateFieldBasicValues(alternateTextFieldInfo, alternateEnsuredField);

                    SPField alternateFieldRefetched = testScope.SiteCollection.RootWeb.Fields[alternateTextFieldInfo.Id];
                    this.ValidateFieldBasicValues(alternateTextFieldInfo, alternateFieldRefetched);

                    // 3) Defaults-based field definition
                    SPField defaultBasedEnsuredField = fieldHelper.EnsureField(fieldsCollection, defaultsTextFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 3, fieldsCollection.Count);
                    Assert.IsNotNull(defaultBasedEnsuredField);
                    this.ValidateFieldBasicValues(defaultsTextFieldInfo, defaultBasedEnsuredField);

                    SPField defaultsFieldRefetched = testScope.SiteCollection.RootWeb.Fields[defaultsTextFieldInfo.Id];
                    this.ValidateFieldBasicValues(defaultsTextFieldInfo, defaultsFieldRefetched);
                }
            }
        }
Пример #36
0
        public void EnsureField_WhenAlreadyExists_ShouldReturnExistingField()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

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

                    // STEP 1: Create the field
                    int noOfFieldsBefore = fieldsCollection.Count;
                    SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(field);

                    // STEP 2: Try to re-ensure the field
                    SPField doubleEnsuredField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(doubleEnsuredField);
                    Assert.AreEqual(textFieldInfo.Id, doubleEnsuredField.Id);
                    Assert.AreEqual(textFieldInfo.InternalName, doubleEnsuredField.InternalName);
                }
            }
        }
Пример #37
0
        public void EnsureField_WhenSubWebFieldCollection_AndSiteColumnDoesntExist_ShouldAddFieldParentRootWebInAReallySneakyWay()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    SPWeb subWeb = testScope.SiteCollection.RootWeb.Webs.Add("subweb");

                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var fieldsCollection = subWeb.Fields;

                    SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    SPWeb testSubWeb = testScope.SiteCollection.RootWeb.Webs["subweb"];

                    try
                    {
                        var shouldBeMissingAndThrowException = testSubWeb.Fields[fieldId];
                        Assert.Fail();
                    }
                    catch (ArgumentException)
                    {
                        // we got sneaky and created the site column on the root web instead
                        // (customizing a field definition in a sub-web is impossible once the rootweb
                        // column exists)
                    }

                    Assert.IsNotNull(testScope.SiteCollection.RootWeb.Fields[fieldId]);    // would be null if we hadn't bothered ensuring the field on the root web
                }
            }
        }
Пример #38
0
        public void EnsureField_WhenSubWebFieldCollection_AndSiteColumnAlreadyExist_ShouldThrowExceptionToShowHowImpossibleThisIs()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    SPWeb subWeb = testScope.SiteCollection.RootWeb.Webs.Add("subweb");

                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var rootWebFields = testScope.SiteCollection.RootWeb.Fields;
                    var subWebFields = subWeb.Fields;

                    SPField field = fieldHelper.EnsureField(rootWebFields, textFieldInfo);
                    textFieldInfo.Required = RequiredType.NotRequired;

                    // Act + Assert
                    // Should be impossible to re-define a field that already exists on root web
                    SPField sameSubWebFieldShouldThrowException = fieldHelper.EnsureField(subWebFields, textFieldInfo);
                }
            }
        }
Пример #39
0
        public void EnsureList_WhenUpdateingContentTypesOnList_ShouldUpdateUniqueContentTypeOrderToFollowInputOrder()
        {
            // Arrange
            const string Url = "testUrl";

            var testFieldInfo = new TextFieldInfo("TestFieldInfoText", new Guid("{3AB6C2FB-DA24-4C67-A4CC-7FA4CE07A03F}"), "NameKey", "DescriptionKey", "GroupKey")
            {
                Required = RequiredType.Required
            };

            var contentTypeId1 = ContentTypeIdBuilder.CreateChild(SPBuiltInContentTypeId.Item, new Guid("{F8B6FF55-2C9E-4FA2-A705-F55FE3D18777}"));
            var contentTypeId2 = ContentTypeIdBuilder.CreateChild(SPBuiltInContentTypeId.Item, new Guid("{A7BAA5B7-C57B-4928-9778-818D267505A1}"));

            var contentTypeInfo1 = new ContentTypeInfo(contentTypeId1, "ContentTypeNameKey1", "ContentTypeDescKey1", "GroupKey")
            {
                Fields = new List<BaseFieldInfo>()
                    {
                        testFieldInfo
                    }
            };

            var contentTypeInfo2 = new ContentTypeInfo(contentTypeId2, "ContentTypeNameKey2", "ContentTypeDescKey2", "GroupKey")
            {
                Fields = new List<BaseFieldInfo>()
                    {
                        testFieldInfo
                    }
            };

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey")
            {
                ContentTypes = new List<ContentTypeInfo>()
                    {
                        contentTypeInfo1,
                        contentTypeInfo2
                    }
            };

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    
                    // Ensure a first time with ordering #1 > #2
                    var list = listHelper.EnsureList(rootWeb, listInfo);

                    // Change the ordering
                    listInfo.ContentTypes = new List<ContentTypeInfo>()
                        {
                            contentTypeInfo2,
                            contentTypeInfo1
                        };

                    // Act: Re-provision to update the ordering
                    list = listHelper.EnsureList(rootWeb, listInfo);
                    var listRefetched = rootWeb.Lists[list.ID];

                    // Assert
                    var listUniqueContentTypeOrder = list.RootFolder.UniqueContentTypeOrder;
                    Assert.IsTrue(listUniqueContentTypeOrder[0].Id.IsChildOf(contentTypeInfo2.ContentTypeId));
                    Assert.IsTrue(listUniqueContentTypeOrder[1].Id.IsChildOf(contentTypeInfo1.ContentTypeId));

                    var listUniqueContentTypeOrderRefetched = listRefetched.RootFolder.UniqueContentTypeOrder;
                    Assert.IsTrue(listUniqueContentTypeOrderRefetched[0].Id.IsChildOf(contentTypeInfo2.ContentTypeId));
                    Assert.IsTrue(listUniqueContentTypeOrderRefetched[1].Id.IsChildOf(contentTypeInfo1.ContentTypeId));
                }
            }
        }
Пример #40
0
        public void EnsureField_WhenTextOrNoteOrHtmlFieldInfo_ShouldApplyStringDefaultValues()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    DefaultValue = "Text default value",
                };

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "Note default value"
                };

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "HTML default value"
                };

                TextFieldInfo noValueTextFieldInfo = new TextFieldInfo(
                    "TestInternalNameDefaultText",
                    new Guid("{7BEB995F-C696-453B-BA86-09A32381C783}"),
                    "NameKeyDefaults",
                    "DescriptionKeyDefaults",
                    "GroupKey");

                NoteFieldInfo noValueNoteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameDefaultNote",
                    new Guid("{0BB1677D-9B14-4EE8-ADB9-53834D5FD516}"),
                    "NameKeyDefaults",
                    "DescriptionKeyDefaults",
                    "GroupKey");

                HtmlFieldInfo noValueHtmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameDefaultHtml",
                    new Guid("{4B44FCBE-A8C3-43FB-9633-C2F89F28032D}"),
                    "NameKeyDefaults",
                    "DescriptionKeyDefaults",
                    "GroupKey");

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

                    // 1) Text field definition (with/without default value)
                    SPField textField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                    Assert.AreEqual("Text default value", textField.DefaultValue);
                    SPField textFieldRefetched = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id]; // refetch to make sure .Update() was properly called on SPField
                    Assert.AreEqual("Text default value", textFieldRefetched.DefaultValue);

                    SPField noDefaultValueTextField = fieldHelper.EnsureField(fieldsCollection, noValueTextFieldInfo);
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueTextField.DefaultValue));
                    SPField noDefaultValueTextFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noValueTextFieldInfo.Id];
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueTextFieldRefetched.DefaultValue));

                    // 1) Note field definition (with/without default value)
                    SPField noteField = fieldHelper.EnsureField(fieldsCollection, noteFieldInfo);
                    Assert.AreEqual("Note default value", noteField.DefaultValue);
                    SPField noteFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noteFieldInfo.Id];
                    Assert.AreEqual("Note default value", noteFieldRefetched.DefaultValue);

                    SPField noDefaultValueNoteField = fieldHelper.EnsureField(fieldsCollection, noValueNoteFieldInfo);
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueNoteField.DefaultValue));
                    SPField noDefaultValueNoteFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noValueNoteFieldInfo.Id];
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueNoteFieldRefetched.DefaultValue));

                    // 3) HTML field definition (with/without default value)
                    SPField htmlField = fieldHelper.EnsureField(fieldsCollection, htmlFieldInfo);
                    Assert.AreEqual("HTML default value", htmlField.DefaultValue);
                    SPField htmlFieldRefetched = testScope.SiteCollection.RootWeb.Fields[htmlFieldInfo.Id];
                    Assert.AreEqual("HTML default value", htmlFieldRefetched.DefaultValue);

                    SPField noDefaultValueHtmlField = fieldHelper.EnsureField(fieldsCollection, noValueHtmlFieldInfo);
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueHtmlField.DefaultValue));
                    SPField noDefaultValueHtmlFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noValueHtmlFieldInfo.Id];
                    Assert.IsTrue(string.IsNullOrEmpty(noDefaultValueHtmlFieldRefetched.DefaultValue));
                }
            }
        }
Пример #41
0
        public void EnsureField_WhenFrenchOnlySiteCollection_ShouldCreateFieldWithFrenchDisplayName()
        {
            using (var testScope = SiteTestScope.BlankSite(Language.French.Culture.LCID))
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "Test_FieldTitle",
                    "Test_FieldDescription",
                    "Test_ContentGroup")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

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

                    SPField field = fieldHelper.EnsureField(rootWebFieldsCollection, textFieldInfo);
                    SPField fieldFromOldCollection = rootWebFieldsCollection[textFieldInfo.Id];
                    SPField fieldRefetched = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id];

                    // Set MUI to french
                    var ambientThreadCulture = Thread.CurrentThread.CurrentUICulture;
                    Thread.CurrentThread.CurrentUICulture = Language.French.Culture;

                    Assert.AreEqual("FR Nom de champ", field.Title);
                    Assert.AreEqual("FR Description de champ", field.Description);
                    Assert.AreEqual("FR Groupe de contenu", field.Group);

                    Assert.AreEqual("FR Nom de champ", fieldFromOldCollection.Title);
                    Assert.AreEqual("FR Description de champ", fieldFromOldCollection.Description);
                    Assert.AreEqual("FR Groupe de contenu", fieldFromOldCollection.Group);

                    Assert.AreEqual("FR Nom de champ", fieldRefetched.Title);
                    Assert.AreEqual("FR Description de champ", fieldRefetched.Description);
                    Assert.AreEqual("FR Groupe de contenu", fieldRefetched.Group);

                    // Reset MUI to its old abient value
                    Thread.CurrentThread.CurrentUICulture = ambientThreadCulture;
                }
            }
        }
Пример #42
0
        public void EnsureField_WhenFieldAlreadyExistsAndInfoObjectChanged_ShouldUpdateExistingBasicFieldProperties()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    EnforceUniqueValues = true,
                    IsHidden = true,
                    IsHiddenInDisplayForm = true,
                    IsHiddenInNewForm = false,
                    IsHiddenInEditForm = false,
                    IsHiddenInListSettings = false,
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyNote",
                    "DescriptionKeyNote",
                    "GroupKey")
                {
                    EnforceUniqueValues = false,
                    IsHidden = false,
                    IsHiddenInDisplayForm = false,
                    IsHiddenInNewForm = true,
                    IsHiddenInEditForm = true,
                    IsHiddenInListSettings = true,
                    Required = RequiredType.NotRequired,
                    HasRichText = true
                };

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

                    // 1) Ensure the basic fields and the first version of their properties
                    SPField textField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                    SPField noteField = fieldHelper.EnsureField(fieldsCollection, noteFieldInfo);

                    this.ValidateFieldBasicValues(textFieldInfo, textField);
                    Assert.AreEqual(50, ((SPFieldText)textField).MaxLength);    // see MaxLength=50 above
                    this.ValidateFieldBasicValues(noteFieldInfo, noteField);
                    Assert.IsTrue(((SPFieldMultiLineText)noteField).RichText);  // see HasRichText=true above

                    SPField textFieldRefetched = testScope.SiteCollection.RootWeb.Fields[textField.Id];     // gotta make sure the re-fetched field has same definition as one returned by EnsureField
                    SPField noteFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noteField.Id];

                    this.ValidateFieldBasicValues(textFieldInfo, textFieldRefetched);
                    Assert.AreEqual(50, ((SPFieldText)textFieldRefetched).MaxLength);    // see MaxLength=50 above
                    this.ValidateFieldBasicValues(noteFieldInfo, noteFieldRefetched);
                    Assert.IsTrue(((SPFieldMultiLineText)noteFieldRefetched).RichText);  // see HasRichText=true above

                    // 2) Modify the FieldInfo values
                    textFieldInfo.DisplayNameResourceKey = "NameKeyUpdated";
                    textFieldInfo.DescriptionResourceKey = "DescriptionKeyUpdated";
                    textFieldInfo.GroupResourceKey = "GroupKeyUpdated";
                    textFieldInfo.EnforceUniqueValues = false;
                    textFieldInfo.IsHidden = false;
                    textFieldInfo.IsHiddenInDisplayForm = false;
                    textFieldInfo.IsHiddenInNewForm = true;
                    textFieldInfo.IsHiddenInEditForm = true;
                    textFieldInfo.IsHiddenInListSettings = true;
                    textFieldInfo.MaxLength = 500;
                    textFieldInfo.Required = RequiredType.NotRequired;

                    noteFieldInfo.DisplayNameResourceKey = "NameKeyNoteUpdated";
                    noteFieldInfo.DescriptionResourceKey = "DescriptionKeyNoteUpdated";
                    noteFieldInfo.GroupResourceKey = "GroupKeyNoteUpdated";
                    noteFieldInfo.IsHidden = true;
                    noteFieldInfo.IsHiddenInDisplayForm = true;
                    noteFieldInfo.IsHiddenInNewForm = false;
                    noteFieldInfo.IsHiddenInEditForm = false;
                    noteFieldInfo.IsHiddenInListSettings = false;
                    noteFieldInfo.Required = RequiredType.Required;
                    noteFieldInfo.HasRichText = false;

                    // Act
                    // 3) Update the site columns by re-ensuring with the updated FieldInfo values
                    fieldsCollection = testScope.SiteCollection.RootWeb.Fields;
                    textField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                    noteField = fieldHelper.EnsureField(fieldsCollection, noteFieldInfo);

                    // 4) Assert that the field contain the 2nd version's updates
                    this.ValidateFieldBasicValues(textFieldInfo, textField);
                    Assert.AreEqual(500, ((SPFieldText)textField).MaxLength);    // see MaxLength=500 above
                    this.ValidateFieldBasicValues(noteFieldInfo, noteField);
                    Assert.IsFalse(((SPFieldMultiLineText)noteField).RichText);  // see HasRichText=false above

                    // gotta make sure the re-fetched field has same definition as one returned by EnsureField
                    textFieldRefetched = testScope.SiteCollection.RootWeb.Fields[textField.Id];
                    noteFieldRefetched = testScope.SiteCollection.RootWeb.Fields[noteField.Id];

                    this.ValidateFieldBasicValues(textFieldInfo, textFieldRefetched);
                    Assert.AreEqual(500, ((SPFieldText)textFieldRefetched).MaxLength);    // see MaxLength=500 above
                    this.ValidateFieldBasicValues(noteFieldInfo, noteFieldRefetched);
                    Assert.IsFalse(((SPFieldMultiLineText)noteFieldRefetched).RichText);  // see HasRichText=false above
                }
            }
        }
Пример #43
0
        public void EnsureField_WhenFieldAddedToListWithDefaultValue_NewItemsCreatedOnListShouldHaveDefaultValues()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey")
                {
                    DefaultValue = 555
                };

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey")
                {
                    DefaultValue = 5.5
                };

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey")
                {
                    DefaultValue = 500.95,
                    LocaleId = 3084 // fr-CA
                };

                BooleanFieldInfo boolFieldInfoBasic = new BooleanFieldInfo(
                    "TestInternalNameBool",
                    new Guid("{F556AB6B-9E51-43E2-99C9-4A4E551A4BEF}"),
                    "NameKeyBool",
                    "DescriptionKeyBool",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoDefaultTrue = new BooleanFieldInfo(
                    "TestInternalNameBoolTrue",
                    new Guid("{0D0289AD-C5FB-495B-96C6-48CC46737D08}"),
                    "NameKeyBoolTrue",
                    "DescriptionKeyBoolTrue",
                    "GroupKey")
                {
                    DefaultValue = true
                };

                BooleanFieldInfo boolFieldInfoDefaultFalse = new BooleanFieldInfo(
                    "TestInternalNameBoolFalse",
                    new Guid("{628181BD-9B0B-4B7E-934F-1CF1796EA4E4}"),
                    "NameKeyBoolFalse",
                    "DescriptionKeyBoolFalse",
                    "GroupKey")
                {
                    DefaultValue = false
                };

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                DateTimeFieldInfo dateTimeFieldInfoDefault = new DateTimeFieldInfo(
                    "TestInternalNameDateDefault",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTimeDefault",
                    "DescriptionKeyDateTimeDefault",
                    "GroupKey")
                {
                    DefaultValue = new DateTime(2005, 10, 21)
                };

                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    DefaultValue = "Text default value"
                };

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "Note default value"
                };

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "<p class=\"some-css-class\">HTML default value</p>"
                };

                ImageFieldInfo imageFieldInfo = new ImageFieldInfo(
                    "TestInternalNameImage",
                    new Guid("{6C5B9E77-B621-43AA-BFBF-B333093EFCAE}"),
                    "NameKeyImage",
                    "DescriptionKeyImage",
                    "GroupKey")
                {
                    DefaultValue = new ImageValue()
                    {
                        Hyperlink = "http://github.com/GSoft-SharePoint/",
                        ImageUrl = "/_layouts/15/MyFolder/MyImage.png"
                    }
                };

                UrlFieldInfo urlFieldInfo = new UrlFieldInfo(
                    "TestInternalNameUrl",
                    new Guid("{208F904C-5A1C-4E22-9A79-70B294FABFDA}"),
                    "NameKeyUrl",
                    "DescriptionKeyUrl",
                    "GroupKey")
                {
                    DefaultValue = new UrlValue()
                    {
                        Url = "http://github.com/GSoft-SharePoint/",
                        Description = "patate!"
                    }
                };

                UrlFieldInfo urlFieldInfoImage = new UrlFieldInfo(
                    "TestInternalNameUrlImg",
                    new Guid("{96D22CFF-5B40-4675-B632-28567792E11B}"),
                    "NameKeyUrlImg",
                    "DescriptionKeyUrlImg",
                    "GroupKey")
                {
                    Format = UrlFieldFormat.Image,
                    DefaultValue = new UrlValue()
                    {
                        Url = "http://github.com/GSoft-SharePoint/",
                        Description = "patate!"
                    }
                };

                LookupFieldInfo lookupFieldInfo = new LookupFieldInfo(
                    "TestInternalNameLookup",
                    new Guid("{62F8127C-4A8C-4217-8BD8-C6712753AFCE}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    // ShowField should be Title by default
                    DefaultValue = new LookupValue(1, "Test Item 1")
                };

                LookupFieldInfo lookupFieldInfoAlt = new LookupFieldInfo(
                    "TestInternalNameLookupAlt",
                    new Guid("{1F05DFFA-6396-4AEF-AD23-72217206D35E}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    ShowField = "ID",
                    DefaultValue = new LookupValue(2, "2")
                };

                LookupMultiFieldInfo lookupMultiFieldInfo = new LookupMultiFieldInfo(
                    "TestInternalNameLookupM",
                    new Guid("{2C9D4C0E-21EB-4742-8C6C-4C30DCD08A05}"),
                    "NameKeyMulti",
                    "DescriptionKeyMulti",
                    "GroupKey")
                {
                    DefaultValue = new LookupValueCollection() { new LookupValue(1, "Test Item 1"), new LookupValue(2, "Test Item 2") }
                };

                var ensuredUser1 = testScope.SiteCollection.RootWeb.EnsureUser(Environment.UserDomainName + "\\" + Environment.UserName);
                var ensuredUser2 = testScope.SiteCollection.RootWeb.EnsureUser("OFFICE\\maxime.boissonneault");

                UserFieldInfo userFieldInfo = new UserFieldInfo(
                    "TestInternalNameUser",
                    new Guid("{5B74DD50-0D2D-4D24-95AF-0C4B8AA3F68A}"),
                    "NameKeyUser",
                    "DescriptionKeyUser",
                    "GroupKey")
                {
                    DefaultValue = new UserValue(ensuredUser1)
                };

                UserMultiFieldInfo userMultiFieldInfo = new UserMultiFieldInfo(
                    "TestInternalNameUserMulti",
                    new Guid("{8C662588-D54E-4905-B232-856C2239B036}"),
                    "NameKeyUserMulti",
                    "DescriptionKeyUserMulti",
                    "GroupKey")
                {
                    DefaultValue = new UserValueCollection() { new UserValue(ensuredUser1), new UserValue(ensuredUser2) }
                };

                MediaFieldInfo mediaFieldInfo = new MediaFieldInfo(
                    "TestInternalNameMedia",
                    new Guid("{A2F070FE-FE33-44FC-9FDF-D18E74ED4D67}"),
                    "NameKeyMedia",
                    "DescriptionKeyMEdia",
                    "GroupKey")
                {
                    DefaultValue = new MediaValue()
                    {
                        Title = "Some media file title",
                        Url = "/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf",
                        IsAutoPlay = true,
                        IsLoop = true,
                        PreviewImageUrl = "/_layouts/15/Images/logo.png"
                    }
                };

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    DefaultValue = new TaxonomyValue(levelOneTermB),
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    new Guid("{2F49D362-B014-41BB-9959-1000C9A7FFA0}"),
                    "NameKeyMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    DefaultValue = new TaxonomyValueCollection(
                        new List<TaxonomyValue>()
                            {
                                new TaxonomyValue(levelTwoTermAA),
                                new TaxonomyValue(levelTwoTermAB)
                            }),
                    TermStoreMapping = new TaxonomyContext(levelOneTermA)   // choices limited to children of a specific term, instead of having full term set choices
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        boolFieldInfoBasic,
                        boolFieldInfoDefaultTrue,
                        boolFieldInfoDefaultFalse,
                        dateTimeFieldInfoFormula,
                        dateTimeFieldInfoDefault,
                        textFieldInfo,
                        noteFieldInfo,
                        htmlFieldInfo,
                        imageFieldInfo,
                        urlFieldInfo,
                        urlFieldInfoImage,
                        lookupFieldInfo,
                        lookupFieldInfoAlt,
                        lookupMultiFieldInfo,
                        userFieldInfo,
                        userMultiFieldInfo,
                        mediaFieldInfo,
                        taxoFieldInfo,
                        taxoMultiFieldInfo
                    };

                ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");

                ListInfo listInfo1 = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");
                ListInfo listInfo2 = new ListInfo("sometestlistpathalt", "DynamiteTestListNameKeyAlt", "DynamiteTestListDescriptionKeyAlt")
                {
                    FieldDefinitions = fieldsToEnsure
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Lookup field ListId setup
                    SPList lookupList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, lookupListInfo);
                    lookupFieldInfo.ListId = lookupList.ID;
                    lookupFieldInfoAlt.ListId = lookupList.ID;
                    lookupMultiFieldInfo.ListId = lookupList.ID;

                    // Create the looked-up items
                    var lookupItem1 = lookupList.Items.Add();
                    lookupItem1["Title"] = "Test Item 1";
                    lookupItem1.Update();

                    var lookupItem2 = lookupList.Items.Add();
                    lookupItem2["Title"] = "Test Item 2";
                    lookupItem2.Update();

                    // Create the first test list
                    SPList list1 = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo1);

                    var fieldHelper = injectionScope.Resolve<IFieldHelper>();

                    // we need to ensure all fields on first list directly
                    IList<SPField> ensuredFieldsOnList1 = fieldHelper.EnsureField(list1.Fields, fieldsToEnsure).ToList();

                    // second ListInfo object holds its own field definitions (which should be ensured at same time as list through listHelper)
                    SPList list2 = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo2);

                    // Act
                    var itemOnList1 = list1.AddItem();
                    itemOnList1.Update();
                    var itemOnList2 = list2.AddItem();
                    itemOnList2.Update();

                    // Assert
                    // List item #1 (fields on list ensured via FieldHelper.EnsureField)
                    Assert.AreEqual(555, itemOnList1["TestInternalNameInteger"]);
                    Assert.AreEqual(5.5, itemOnList1["TestInternalNameNumber"]);
                    Assert.AreEqual(500.95, itemOnList1["TestInternalNameCurrency"]);
                    Assert.IsNull(itemOnList1["TestInternalNameBool"]);
                    Assert.IsTrue((bool)itemOnList1["TestInternalNameBoolTrue"]);
                    Assert.IsFalse((bool)itemOnList1["TestInternalNameBoolFalse"]);
                    Assert.AreEqual(DateTime.Today, itemOnList1["TestInternalNameDateFormula"]);
                    Assert.AreEqual(new DateTime(2005, 10, 21), itemOnList1["TestInternalNameDateDefault"]);
                    Assert.AreEqual("Text default value", itemOnList1["TestInternalNameText"]);
                    Assert.AreEqual("Note default value", itemOnList1["TestInternalNameNote"]);
                    Assert.AreEqual("<p class=\"some-css-class\">HTML default value</p>", itemOnList1["TestInternalNameHtml"]);

                    var imageFieldVal = (ImageFieldValue)itemOnList1["TestInternalNameImage"];
                    Assert.IsNotNull(imageFieldVal);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", imageFieldVal.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", imageFieldVal.ImageUrl);

                    var urlFieldVal = new SPFieldUrlValue(itemOnList1["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    ////Assert.AreEqual("patate!", urlFieldVal.Description);     // proper Url description will never be set for Format=Hyperlink

                    var urlImageFieldVal = new SPFieldUrlValue(itemOnList1["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    ////Assert.AreEqual("patate!", urlImageFieldVal.Description);     // proper Url description will never be set for Format=Image either

                    var lookupFieldVal = new SPFieldLookupValue(itemOnList1["TestInternalNameLookup"].ToString());
                    Assert.AreEqual(1, lookupFieldVal.LookupId);
                    Assert.AreEqual("Test Item 1", lookupFieldVal.LookupValue);

                    var lookupAltFieldVal = new SPFieldLookupValue(itemOnList1["TestInternalNameLookupAlt"].ToString());
                    Assert.AreEqual(2, lookupAltFieldVal.LookupId);
                    Assert.AreEqual("2", lookupAltFieldVal.LookupValue); // ShowField/LookupField is ID

                    var lookupMultiFieldVal = new SPFieldLookupValueCollection(itemOnList1["TestInternalNameLookupM"].ToString());
                    Assert.AreEqual(1, lookupMultiFieldVal[0].LookupId);
                    Assert.AreEqual("Test Item 1", lookupMultiFieldVal[0].LookupValue);
                    Assert.AreEqual(2, lookupMultiFieldVal[1].LookupId);
                    Assert.AreEqual("Test Item 2", lookupMultiFieldVal[1].LookupValue);

                    var userFieldVal = new SPFieldUserValue(testScope.SiteCollection.RootWeb, itemOnList1["TestInternalNameUser"].ToString());
                    Assert.AreEqual(ensuredUser1.Name, userFieldVal.User.Name);

                    var userMultiFieldVal = new SPFieldUserValueCollection(testScope.SiteCollection.RootWeb, itemOnList1["TestInternalNameUserMulti"].ToString());
                    Assert.AreEqual(ensuredUser1.Name, userMultiFieldVal[0].User.Name);
                    Assert.AreEqual("Maxime Boissonneault", userMultiFieldVal[1].User.Name);

                    var mediaFieldVal = MediaFieldValue.FromString(itemOnList1["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    var taxoFieldValue = (TaxonomyFieldValue)itemOnList1["TestInternalNameTaxo"];
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermB.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermB.Label, taxoFieldValue.Label);

                    var taxoFieldValueMulti = (TaxonomyFieldValueCollection)itemOnList1["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);

                    // List item #2 (fields on list ensured via ListHelper.EnsureList)
                    Assert.AreEqual(555, itemOnList2["TestInternalNameInteger"]);
                    Assert.AreEqual(5.5, itemOnList2["TestInternalNameNumber"]);
                    Assert.AreEqual(500.95, itemOnList2["TestInternalNameCurrency"]);
                    Assert.IsNull(itemOnList2["TestInternalNameBool"]);
                    Assert.IsTrue((bool)itemOnList2["TestInternalNameBoolTrue"]);
                    Assert.IsFalse((bool)itemOnList2["TestInternalNameBoolFalse"]);
                    Assert.AreEqual(DateTime.Today, itemOnList2["TestInternalNameDateFormula"]);
                    Assert.AreEqual(new DateTime(2005, 10, 21), itemOnList2["TestInternalNameDateDefault"]);
                    Assert.AreEqual("Text default value", itemOnList2["TestInternalNameText"]);
                    Assert.AreEqual("Note default value", itemOnList2["TestInternalNameNote"]);
                    Assert.AreEqual("<p class=\"some-css-class\">HTML default value</p>", itemOnList2["TestInternalNameHtml"]);

                    imageFieldVal = (ImageFieldValue)itemOnList2["TestInternalNameImage"];
                    Assert.IsNotNull(imageFieldVal);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", imageFieldVal.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", imageFieldVal.ImageUrl);

                    urlFieldVal = new SPFieldUrlValue(itemOnList2["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    ////Assert.AreEqual("patate!", urlFieldVal.Description);     // proper Url description will never be set for Format=Hyperlink

                    urlImageFieldVal = new SPFieldUrlValue(itemOnList2["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    ////Assert.AreEqual("patate!", urlImageFieldVal.Description);     // proper Url description will never be set for Format=Image either

                    lookupFieldVal = new SPFieldLookupValue(itemOnList2["TestInternalNameLookup"].ToString());
                    Assert.AreEqual(1, lookupFieldVal.LookupId);
                    Assert.AreEqual("Test Item 1", lookupFieldVal.LookupValue);

                    lookupAltFieldVal = new SPFieldLookupValue(itemOnList2["TestInternalNameLookupAlt"].ToString());
                    Assert.AreEqual(2, lookupAltFieldVal.LookupId);
                    Assert.AreEqual("2", lookupAltFieldVal.LookupValue); // ShowField/LookupField is ID

                    lookupMultiFieldVal = new SPFieldLookupValueCollection(itemOnList2["TestInternalNameLookupM"].ToString());
                    Assert.AreEqual(1, lookupMultiFieldVal[0].LookupId);
                    Assert.AreEqual("Test Item 1", lookupMultiFieldVal[0].LookupValue);
                    Assert.AreEqual(2, lookupMultiFieldVal[1].LookupId);
                    Assert.AreEqual("Test Item 2", lookupMultiFieldVal[1].LookupValue);

                    userFieldVal = new SPFieldUserValue(testScope.SiteCollection.RootWeb, itemOnList2["TestInternalNameUser"].ToString());
                    Assert.AreEqual(ensuredUser1.Name, userFieldVal.User.Name);

                    userMultiFieldVal = new SPFieldUserValueCollection(testScope.SiteCollection.RootWeb, itemOnList2["TestInternalNameUserMulti"].ToString());
                    Assert.AreEqual(ensuredUser1.Name, userMultiFieldVal[0].User.Name);
                    Assert.AreEqual("Maxime Boissonneault", userMultiFieldVal[1].User.Name);

                    mediaFieldVal = MediaFieldValue.FromString(itemOnList2["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    taxoFieldValue = (TaxonomyFieldValue)itemOnList2["TestInternalNameTaxo"];
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermB.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermB.Label, taxoFieldValue.Label);

                    taxoFieldValueMulti = (TaxonomyFieldValueCollection)itemOnList2["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);
                }

                // Cleanup term set so that we don't pollute the metadata store
                newTermSet.Delete();
                defaultSiteCollectionTermStore.CommitAll();
            }
        }
Пример #44
0
        public void EnsureField_WhenEnglishOnlySiteCollection_ShouldCreateFieldWithEnglishDisplayName()
        {
            using (var testScope = SiteTestScope.BlankSite(Language.English.Culture.LCID))
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "Test_FieldTitle",
                    "Test_FieldDescription",
                    "Test_ContentGroup")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();

                    var rootWebFieldsCollection = testScope.SiteCollection.RootWeb.Fields;

                    SPField field = fieldHelper.EnsureField(rootWebFieldsCollection, textFieldInfo);
                    SPField fieldFromOldCollection = rootWebFieldsCollection[textFieldInfo.Id];
                    SPField fieldRefetched = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id];

                    Assert.AreEqual("EN Field Title", field.Title);
                    Assert.AreEqual("EN Field Description", field.Description);
                    Assert.AreEqual("EN Content Group", field.Group);

                    Assert.AreEqual("EN Field Title", fieldFromOldCollection.Title);
                    Assert.AreEqual("EN Field Description", fieldFromOldCollection.Description);
                    Assert.AreEqual("EN Content Group", fieldFromOldCollection.Group);

                    Assert.AreEqual("EN Field Title", fieldRefetched.Title);
                    Assert.AreEqual("EN Field Description", fieldRefetched.Description);
                    Assert.AreEqual("EN Content Group", fieldRefetched.Group);
                }
            }
        }
Пример #45
0
        public void EnsureField_WhenContentTypeFieldCollection_ShouldThrowArgumentException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                var contentTypeInfo = new ContentTypeInfo(SPBuiltInContentTypeId.BasicPage.ToString() + "01", "CTNameKey", "CTDescrKey", "GroupKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    IContentTypeHelper contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();
                    SPContentType ensuredContentType = contentTypeHelper.EnsureContentType(testScope.SiteCollection.RootWeb.ContentTypes, contentTypeInfo);

                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var fieldsCollection = ensuredContentType.Fields;

                    SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);
                }
            }
        }
Пример #46
0
        public void EnsureList_WhenUpdatingAListToAddFieldsToDefaultView_TheDefaultViewShouldBeModifiedAccordingly()
        {
            // Arrange
            const string Url = "testUrl";

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            const string Desc = "DescriptionFieldKey";
            const string Name = "NameFieldKey";
            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    Name,
                    Desc,
                    "GroupKey");

            var numberFieldInfo = new NumberFieldInfo(
                    "NumberInternalName",
                    new Guid("{953D865E-7C19-4961-9643-1BFCE3AC3889}"),
                    "NameKey2",
                    "DescKey2",
                    "GroupKey2");

            listInfo.FieldDefinitions.Add(textFieldInfo);
            listInfo.FieldDefinitions.Add(numberFieldInfo);

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = listHelper.EnsureList(rootWeb, listInfo);
                    var numberOfListsBeforeUpdate = rootWeb.Lists.Count;

                    // Act
                    listInfo.DefaultViewFields.Add(numberFieldInfo);
                    var updatedList = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.AreEqual(numberOfListsBeforeUpdate, rootWeb.Lists.Count);
                    Assert.IsNotNull(updatedList);
                    updatedList = rootWeb.GetList(Url);
                    Assert.AreEqual(listInfo.DisplayNameResourceKey, updatedList.TitleResource.Value);
                    Assert.IsNotNull(updatedList.Fields[Name]);
                    Assert.IsNotNull(updatedList.Fields["NameKey2"]);
                    Assert.IsTrue(list.DefaultView.ViewFields.Exists("NumberInternalName"));
                }
            }
        }
Пример #47
0
        public void EnsureList_WhenSpecifyingBothContentTypesAndFieldDefinitions_AndSiteColumnAndContenTypeAlreadyThere_ShouldProvisionListContentType_ThenOverrideFieldDefinitionOnTheList()
        {
            // Arrange
            const string Url = "testUrl";

            var testFieldInfoRequired = new TextFieldInfo("TestFieldInfoText", new Guid("{3AB6C2FB-DA24-4C67-A4CC-7FA4CE07A03F}"), "NameKey", "DescriptionKey", "GroupKey")
            {
                Required = RequiredType.Required
            };

            var sameTestFieldInfoButNotRequired = new TextFieldInfo("TestFieldInfoText", new Guid("{3AB6C2FB-DA24-4C67-A4CC-7FA4CE07A03F}"), "NameKeyAlt", "DescriptionKey", "GroupKey")
            {
                Required = RequiredType.NotRequired
            };

            var contentTypeId = string.Format(
                    CultureInfo.InvariantCulture,
                    "0x0100{0:N}",
                    new Guid("{F8B6FF55-2C9E-4FA2-A705-F55FE3D18777}"));

            var contentTypeInfo = new ContentTypeInfo(contentTypeId, "ContentTypeNameKey", "ContentTypeDescKey", "GroupKey")
            {
                Fields = new List<BaseFieldInfo>()
                    {
                        testFieldInfoRequired
                    }
            };

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey")
            {
                ContentTypes = new List<ContentTypeInfo>()
                    {
                        contentTypeInfo     // this includes testFieldInfoRequired 
                    },
                FieldDefinitions = new List<BaseFieldInfo>()
                    {
                        sameTestFieldInfoButNotRequired     // this is the list-specific field definition override
                    }
            };

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Provision the site column and site content type first
                    var siteColumn = fieldHelper.EnsureField(rootWeb.Fields, testFieldInfoRequired);
                    var siteContentType = contentTypeHelper.EnsureContentType(rootWeb.ContentTypes, contentTypeInfo);

                    // Act: Provision the list with an alternate field definition (NotRequired)
                    var list = listHelper.EnsureList(rootWeb, listInfo);
                    var listRefetched = rootWeb.Lists[list.ID];

                    // Assert

                    // Site column should've been added to root web
                    var siteColumnRefetched = rootWeb.Fields[testFieldInfoRequired.Id];
                    Assert.IsNotNull(siteColumnRefetched);
                    Assert.IsTrue(siteColumnRefetched.Required);
                    Assert.AreEqual("NameKey", siteColumnRefetched.Title);

                    // Content type should've been added to root web
                    var siteContentTypeRefetched = rootWeb.ContentTypes[new SPContentTypeId(contentTypeId)];
                    Assert.IsNotNull(siteContentTypeRefetched);
                    Assert.IsNotNull(siteContentTypeRefetched.Fields[testFieldInfoRequired.Id]);

                    // Content type should've been added to new list
                    var listContentType = list.ContentTypes["ContentTypeNameKey"];
                    Assert.IsNotNull(listContentType);
                    Assert.IsNotNull(listContentType.Fields[testFieldInfoRequired.Id]);

                    var listContentTypeRefetched = rootWeb.Lists[list.ID].ContentTypes["ContentTypeNameKey"];
                    Assert.IsNotNull(listContentTypeRefetched);
                    Assert.IsNotNull(listContentTypeRefetched.Fields[testFieldInfoRequired.Id]);

                    // New list should hold a NotRequired variant of the site column
                    var listColumn = list.Fields[sameTestFieldInfoButNotRequired.Id];
                    Assert.IsFalse(listColumn.Required);
                    Assert.AreEqual("NameKeyAlt", listColumn.Title);

                    var listColumnRefetched = rootWeb.Lists[list.ID].Fields[sameTestFieldInfoButNotRequired.Id];
                    Assert.IsFalse(listColumnRefetched.Required);    // definition should've been overriden for the list only
                    Assert.AreEqual("NameKeyAlt", listColumnRefetched.Title);
                }
            }
        }
Пример #48
0
        public void EnsureContentType_WhenOnSubWeb_AndRootWebCTDoesntAlreadyExists_ShouldProvisionRootWebCT()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "Test_FieldTitle",
                    "Test_FieldDescription",
                    "Test_ContentGroup")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                var contentTypeId = string.Format(
                    CultureInfo.InvariantCulture,
                    "0x0100{0:N}",
                    new Guid("{F8B6FF55-2C9E-4FA2-A705-F55FE3D18777}"));

                var contentTypeInfo = new ContentTypeInfo(contentTypeId, "NameKey", "DescriptionKey", "GroupKey")
                {
                    Fields = new List<BaseFieldInfo>()
                    {
                        textFieldInfo
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var rootWeb = testScope.SiteCollection.RootWeb;
                    var subWeb = rootWeb.Webs.Add("subweb");

                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Act
                    var ensuredSubWebContentType = contentTypeHelper.EnsureContentType(subWeb.ContentTypes, contentTypeInfo);

                    // Assert
                    var refetchedRootWebCT = rootWeb.ContentTypes["NameKey"];
                    Assert.IsNotNull(refetchedRootWebCT);

                    // CT shouldn't ever end up on sub-web exclusively (we wanna force the creation of RootWeb CT instead)
                    Assert.IsNull(subWeb.ContentTypes.Cast<SPContentType>().SingleOrDefault(ct => ct.Id == ensuredSubWebContentType.Id));
                }
            }
        }
Пример #49
0
        public void EnsureList_WhenUpdatingAListWithSpecifiedFieldDefinitions_ItShouldAddAndPersistThem()
        {
            // Arrange
            const string Url = "testUrl";

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            const string Desc = "DescriptionFieldKey";
            const string Name = "NameFieldKey";
            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    Name,
                    Desc,
                    "GroupKey");

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = listHelper.EnsureList(rootWeb, listInfo);
                    var numberOfListsBeforeUpdate = rootWeb.Lists.Count;
                    var numberOfFieldsOnListBefore = list.Fields.Count;
                    var numberOfSiteColumnsBefore = rootWeb.Fields.Count;

                    // Act
                    listInfo.FieldDefinitions.Add(textFieldInfo);
                    var updatedList = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.AreEqual(numberOfListsBeforeUpdate, rootWeb.Lists.Count);
                    Assert.IsNotNull(updatedList);
                    updatedList = rootWeb.GetList(Url);
                    Assert.AreEqual(listInfo.DisplayNameResourceKey, updatedList.TitleResource.Value);
                    Assert.AreEqual(updatedList.Fields.Count, numberOfFieldsOnListBefore + 1);
                    Assert.AreEqual(numberOfSiteColumnsBefore + 1, rootWeb.Fields.Count);
                    Assert.IsNotNull(updatedList.Fields[Name]);
                    Assert.AreEqual(updatedList.Fields[Name].DescriptionResource.Value, Desc);
                }
            }
        }
Пример #50
0
        public void EnsureList_WhenEnsuringANewListAndAddingAFieldAndWantItToBeInDefaultView_ShouldBeAddedToDefaultView()
        {
            // Arrange
            const string Url = "testUrl";

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            const string Desc = "DescriptionFieldKey";
            const string Name = "NameFieldKey";
            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    Name,
                    Desc,
                    "GroupKey");

            listInfo.FieldDefinitions.Add(textFieldInfo);
            listInfo.DefaultViewFields.Add(textFieldInfo);

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var numberOfListsBefore = rootWeb.Lists.Count;

                    // Act
                    var list = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.AreEqual(numberOfListsBefore + 1, rootWeb.Lists.Count);
                    Assert.IsNotNull(list);
                    list = rootWeb.GetList(Url);
                    Assert.AreEqual(listInfo.DisplayNameResourceKey, list.TitleResource.Value);
                    Assert.IsNotNull(list.Fields[Name]);
                    Assert.AreEqual(list.Fields[Name].DescriptionResource.Value, Desc);
                    Assert.IsTrue(list.DefaultView.ViewFields.Exists("TestInternalName"));
                }
            }
        }
        public void ToEntity_WhenMappingFromListItem_AndItemPropertiesAreFilledWithValues_ShouldMapEntityWithAllItemValues()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey");

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey");

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoBasic = new BooleanFieldInfo(
                    "TestInternalNameBool",
                    new Guid("{F556AB6B-9E51-43E2-99C9-4A4E551A4BEF}"),
                    "NameKeyBool",
                    "DescriptionKeyBool",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoDefaultTrue = new BooleanFieldInfo(
                    "TestInternalNameBoolTrue",
                    new Guid("{0D0289AD-C5FB-495B-96C6-48CC46737D08}"),
                    "NameKeyBoolTrue",
                    "DescriptionKeyBoolTrue",
                    "GroupKey")
                {
                    DefaultValue = true
                };

                BooleanFieldInfo boolFieldInfoDefaultFalse = new BooleanFieldInfo(
                    "TestInternalNameBoolFalse",
                    new Guid("{628181BD-9B0B-4B7E-934F-1CF1796EA4E4}"),
                    "NameKeyBoolFalse",
                    "DescriptionKeyBoolFalse",
                    "GroupKey")
                {
                    DefaultValue = false
                };

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                DateTimeFieldInfo dateTimeFieldInfoDefault = new DateTimeFieldInfo(
                    "TestInternalNameDateDefault",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTimeDefault",
                    "DescriptionKeyDateTimeDefault",
                    "GroupKey");

                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey");

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey");

                ImageFieldInfo imageFieldInfo = new ImageFieldInfo(
                    "TestInternalNameImage",
                    new Guid("{6C5B9E77-B621-43AA-BFBF-B333093EFCAE}"),
                    "NameKeyImage",
                    "DescriptionKeyImage",
                    "GroupKey");

                UrlFieldInfo urlFieldInfo = new UrlFieldInfo(
                    "TestInternalNameUrl",
                    new Guid("{208F904C-5A1C-4E22-9A79-70B294FABFDA}"),
                    "NameKeyUrl",
                    "DescriptionKeyUrl",
                    "GroupKey");

                UrlFieldInfo urlFieldInfoImage = new UrlFieldInfo(
                    "TestInternalNameUrlImg",
                    new Guid("{96D22CFF-5B40-4675-B632-28567792E11B}"),
                    "NameKeyUrlImg",
                    "DescriptionKeyUrlImg",
                    "GroupKey")
                {
                    Format = UrlFieldFormat.Image
                };

                LookupFieldInfo lookupFieldInfo = new LookupFieldInfo(
                    "TestInternalNameLookup",
                    new Guid("{62F8127C-4A8C-4217-8BD8-C6712753AFCE}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

                LookupFieldInfo lookupFieldInfoAlt = new LookupFieldInfo(
                    "TestInternalNameLookupAlt",
                    new Guid("{1F05DFFA-6396-4AEF-AD23-72217206D35E}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    ShowField = "ID"
                };

                LookupMultiFieldInfo lookupMultiFieldInfo = new LookupMultiFieldInfo(
                    "TestInternalNameLookupM",
                    new Guid("{2C9D4C0E-21EB-4742-8C6C-4C30DCD08A05}"),
                    "NameKeyMulti",
                    "DescriptionKeyMulti",
                    "GroupKey");

                var ensuredUser1 = testScope.SiteCollection.RootWeb.EnsureUser(Environment.UserDomainName + "\\" + Environment.UserName);
                var ensuredUser2 = testScope.SiteCollection.RootWeb.EnsureUser("OFFICE\\maxime.boissonneault");

                UserFieldInfo userFieldInfo = new UserFieldInfo(
                    "TestInternalNameUser",
                    new Guid("{5B74DD50-0D2D-4D24-95AF-0C4B8AA3F68A}"),
                    "NameKeyUser",
                    "DescriptionKeyUser",
                    "GroupKey");

                UserMultiFieldInfo userMultiFieldInfo = new UserMultiFieldInfo(
                    "TestInternalNameUserMulti",
                    new Guid("{8C662588-D54E-4905-B232-856C2239B036}"),
                    "NameKeyUserMulti",
                    "DescriptionKeyUserMulti",
                    "GroupKey");

                MediaFieldInfo mediaFieldInfo = new MediaFieldInfo(
                    "TestInternalNameMedia",
                    new Guid("{A2F070FE-FE33-44FC-9FDF-D18E74ED4D67}"),
                    "NameKeyMedia",
                    "DescriptionKeyMEdia",
                    "GroupKey");

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    new Guid("{2F49D362-B014-41BB-9959-1000C9A7FFA0}"),
                    "NameKeyMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(levelOneTermA)   // choices limited to children of a specific term, instead of having full term set choices
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        boolFieldInfoBasic,
                        boolFieldInfoDefaultTrue,
                        boolFieldInfoDefaultFalse,
                        dateTimeFieldInfoFormula,
                        dateTimeFieldInfoDefault,
                        textFieldInfo,
                        noteFieldInfo,
                        htmlFieldInfo,
                        imageFieldInfo,
                        urlFieldInfo,
                        urlFieldInfoImage,
                        lookupFieldInfo,
                        lookupFieldInfoAlt,
                        lookupMultiFieldInfo,
                        userFieldInfo,
                        userMultiFieldInfo,
                        mediaFieldInfo,
                        taxoFieldInfo,
                        taxoMultiFieldInfo
                    };

                ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    FieldDefinitions = fieldsToEnsure
                };

                // Note how we need to specify SPSite for injection context - ISharePointEntityBinder's implementation
                // is lifetime-scoped to InstancePerSite.
                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(testScope.SiteCollection))
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Lookup field ListId setup
                    SPList lookupList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, lookupListInfo);
                    lookupFieldInfo.ListId = lookupList.ID;
                    lookupFieldInfoAlt.ListId = lookupList.ID;
                    lookupMultiFieldInfo.ListId = lookupList.ID;

                    // Create the looked-up items
                    var lookupItem1 = lookupList.Items.Add();
                    lookupItem1["Title"] = "Test Item 1";
                    lookupItem1.Update();

                    var lookupItem2 = lookupList.Items.Add();
                    lookupItem2["Title"] = "Test Item 2";
                    lookupItem2.Update();

                    // Create the first test list
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);
                    list.EnableVersioning = true;
                    list.Update();

                    // Create item on list
                    var itemOnList = list.AddItem();

                    // Update with the field values through the SharePoint API
                    itemOnList["Title"] = "Item under test";
                    itemOnList["TestInternalNameInteger"] = 555;
                    itemOnList["TestInternalNameNumber"] = 5.5;
                    itemOnList["TestInternalNameCurrency"] = 500.95;
                    itemOnList["TestInternalNameBool"] = true;
                    itemOnList["TestInternalNameBoolTrue"] = false;
                    itemOnList["TestInternalNameBoolFalse"] = true;
                    itemOnList["TestInternalNameDateFormula"] = new DateTime(1977, 7, 7);
                    itemOnList["TestInternalNameDateDefault"] = new DateTime(1977, 7, 7);
                    itemOnList["TestInternalNameText"] = "Text value";
                    itemOnList["TestInternalNameNote"] = "Note value";
                    itemOnList["TestInternalNameHtml"] = "<p class=\"some-css-class\">HTML value</p>";
                    itemOnList["TestInternalNameImage"] = new ImageFieldValue()
                        {
                            Hyperlink = "http://github.com/GSoft-SharePoint/",
                            ImageUrl = "/_layouts/15/MyFolder/MyImage.png"
                        };
                    itemOnList["TestInternalNameUrl"] = new SPFieldUrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        };
                    itemOnList["TestInternalNameUrlImg"] = new SPFieldUrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        };

                    itemOnList["TestInternalNameLookup"] = new SPFieldLookupValue(1, "Test Item 1");
                    itemOnList["TestInternalNameLookupAlt"] = new SPFieldLookupValue(2, "2");
                    itemOnList["TestInternalNameLookupM"] = new SPFieldLookupValueCollection() { new SPFieldLookupValue(1, "Test Item 1"), new SPFieldLookupValue(2, "Test Item 2") };
                    itemOnList["TestInternalNameUser"] = new SPFieldUserValue(testScope.SiteCollection.RootWeb, ensuredUser1.ID, ensuredUser1.Name);
                    itemOnList["TestInternalNameUserMulti"] = new SPFieldUserValueCollection() 
                        {  
                            new SPFieldUserValue(testScope.SiteCollection.RootWeb, ensuredUser1.ID, ensuredUser1.Name),
                            new SPFieldUserValue(testScope.SiteCollection.RootWeb, ensuredUser2.ID, ensuredUser2.Name)
                        };
                    itemOnList["TestInternalNameMedia"] = new MediaFieldValue()
                        {
                            Title = "Some media file title",
                            MediaSource = "/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf",
                            AutoPlay = true,
                            Loop = true,
                            PreviewImageSource = "/_layouts/15/Images/logo.png"
                        };

                    var taxonomyField = (TaxonomyField)itemOnList.Fields.GetFieldByInternalName("TestInternalNameTaxo");
                    taxonomyField.SetFieldValue(itemOnList, createdTermB);

                    var taxonomyMultiField = (TaxonomyField)itemOnList.Fields.GetFieldByInternalName("TestInternalNameTaxoMulti");
                    taxonomyMultiField.SetFieldValue(itemOnList, new[] { createdTermAA, createdTermAB });

                    itemOnList.Update();

                    var entityBinder = injectionScope.Resolve<ISharePointEntityBinder>();
                    var entityMappedFromSingleItem = new TestItemEntityWithLookups();
                    var entityMappedFromItemVersion = new TestItemEntityWithLookups();

                    // Act

                    // Map from SPListItem
                    entityBinder.ToEntity<TestItemEntityWithLookups>(entityMappedFromSingleItem, itemOnList);

                    // Map from SPListItemVersion
                    entityBinder.ToEntity<TestItemEntityWithLookups>(entityMappedFromItemVersion, itemOnList.Versions[0]);

                    // Map from DataRow/SPListItemCollection
                    var entitiesMappedFromItemCollection = entityBinder.Get<TestItemEntity>(list.Items);

                    // Assert
                    // #1 Validate straight single list item to entity mappings
                    Assert.AreEqual(555, entityMappedFromSingleItem.IntegerProperty);
                    Assert.AreEqual(5.5, entityMappedFromSingleItem.DoubleProperty);
                    Assert.AreEqual(500.95, entityMappedFromSingleItem.CurrencyProperty);
                    Assert.IsTrue(entityMappedFromSingleItem.BoolProperty.Value);
                    Assert.IsFalse(entityMappedFromSingleItem.BoolDefaultTrueProperty);
                    Assert.IsTrue(entityMappedFromSingleItem.BoolDefaultFalseProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entityMappedFromSingleItem.DateTimeFormulaProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entityMappedFromSingleItem.DateTimeProperty);
                    Assert.AreEqual("Text value", entityMappedFromSingleItem.TextProperty);
                    Assert.AreEqual("Note value", entityMappedFromSingleItem.NoteProperty);
                    Assert.AreEqual("<p class=\"some-css-class\">HTML value</p>", entityMappedFromSingleItem.HtmlProperty);

                    Assert.IsNotNull(entityMappedFromSingleItem.ImageProperty);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromSingleItem.ImageProperty.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", entityMappedFromSingleItem.ImageProperty.ImageUrl);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromSingleItem.UrlProperty.Url);
                    Assert.AreEqual("patate!", entityMappedFromSingleItem.UrlProperty.Description);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromSingleItem.UrlImageProperty.Url);
                    Assert.AreEqual("patate!", entityMappedFromSingleItem.UrlProperty.Description);

                    Assert.AreEqual(1, entityMappedFromSingleItem.LookupProperty.Id);
                    Assert.AreEqual("Test Item 1", entityMappedFromSingleItem.LookupProperty.Value);

                    Assert.AreEqual(2, entityMappedFromSingleItem.LookupAltProperty.Id);
                    Assert.AreEqual("2", entityMappedFromSingleItem.LookupAltProperty.Value); // ShowField/LookupField is ID

                    Assert.AreEqual(1, entityMappedFromSingleItem.LookupMultiProperty[0].Id);
                    Assert.AreEqual("Test Item 1", entityMappedFromSingleItem.LookupMultiProperty[0].Value);
                    Assert.AreEqual(2, entityMappedFromSingleItem.LookupMultiProperty[1].Id);
                    Assert.AreEqual("Test Item 2", entityMappedFromSingleItem.LookupMultiProperty[1].Value);

                    Assert.AreEqual(ensuredUser1.Name, entityMappedFromSingleItem.UserProperty.DisplayName);

                    Assert.AreEqual(ensuredUser1.Name, entityMappedFromSingleItem.UserMultiProperty[0].DisplayName);
                    Assert.AreEqual("Maxime Boissonneault", entityMappedFromSingleItem.UserMultiProperty[1].DisplayName);

                    Assert.AreEqual("Some media file title", entityMappedFromSingleItem.MediaProperty.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), entityMappedFromSingleItem.MediaProperty.Url);
                    Assert.IsTrue(entityMappedFromSingleItem.MediaProperty.IsAutoPlay);
                    Assert.IsTrue(entityMappedFromSingleItem.MediaProperty.IsLoop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", entityMappedFromSingleItem.MediaProperty.PreviewImageUrl);

                    Assert.AreEqual(levelOneTermB.Id, entityMappedFromSingleItem.TaxonomyProperty.Id);
                    Assert.AreEqual(levelOneTermB.Label, entityMappedFromSingleItem.TaxonomyProperty.Label);

                    Assert.AreEqual(levelTwoTermAA.Id, entityMappedFromSingleItem.TaxonomyMultiProperty[0].Id);
                    Assert.AreEqual(levelTwoTermAA.Label, entityMappedFromSingleItem.TaxonomyMultiProperty[0].Label);
                    Assert.AreEqual(levelTwoTermAB.Id, entityMappedFromSingleItem.TaxonomyMultiProperty[1].Id);
                    Assert.AreEqual(levelTwoTermAB.Label, entityMappedFromSingleItem.TaxonomyMultiProperty[1].Label);

                    // #2 Validate list item version mappings
                    Assert.AreEqual(555, entityMappedFromItemVersion.IntegerProperty);
                    Assert.AreEqual(5.5, entityMappedFromItemVersion.DoubleProperty);
                    Assert.AreEqual(500.95, entityMappedFromItemVersion.CurrencyProperty);
                    Assert.IsTrue(entityMappedFromItemVersion.BoolProperty.Value);
                    Assert.IsFalse(entityMappedFromItemVersion.BoolDefaultTrueProperty);
                    Assert.IsTrue(entityMappedFromItemVersion.BoolDefaultFalseProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entityMappedFromItemVersion.DateTimeFormulaProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entityMappedFromItemVersion.DateTimeProperty);
                    Assert.AreEqual("Text value", entityMappedFromItemVersion.TextProperty);
                    Assert.AreEqual("Note value", entityMappedFromItemVersion.NoteProperty);
                    Assert.AreEqual("<p class=\"some-css-class\">HTML value</p>", entityMappedFromItemVersion.HtmlProperty);

                    Assert.IsNotNull(entityMappedFromItemVersion.ImageProperty);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromItemVersion.ImageProperty.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", entityMappedFromItemVersion.ImageProperty.ImageUrl);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromItemVersion.UrlProperty.Url);
                    Assert.AreEqual("patate!", entityMappedFromItemVersion.UrlProperty.Description);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entityMappedFromItemVersion.UrlImageProperty.Url);
                    Assert.AreEqual("patate!", entityMappedFromItemVersion.UrlProperty.Description);

                    Assert.AreEqual(1, entityMappedFromItemVersion.LookupProperty.Id);
                    Assert.AreEqual("Test Item 1", entityMappedFromItemVersion.LookupProperty.Value);

                    Assert.AreEqual(2, entityMappedFromItemVersion.LookupAltProperty.Id);
                    Assert.AreEqual("2", entityMappedFromItemVersion.LookupAltProperty.Value); // ShowField/LookupField is ID

                    Assert.AreEqual(1, entityMappedFromItemVersion.LookupMultiProperty[0].Id);
                    Assert.AreEqual("Test Item 1", entityMappedFromItemVersion.LookupMultiProperty[0].Value);
                    Assert.AreEqual(2, entityMappedFromItemVersion.LookupMultiProperty[1].Id);
                    Assert.AreEqual("Test Item 2", entityMappedFromItemVersion.LookupMultiProperty[1].Value);

                    Assert.AreEqual(ensuredUser1.Name, entityMappedFromItemVersion.UserProperty.DisplayName);

                    Assert.AreEqual(ensuredUser1.Name, entityMappedFromItemVersion.UserMultiProperty[0].DisplayName);
                    Assert.AreEqual("Maxime Boissonneault", entityMappedFromItemVersion.UserMultiProperty[1].DisplayName);

                    Assert.AreEqual("Some media file title", entityMappedFromItemVersion.MediaProperty.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), entityMappedFromItemVersion.MediaProperty.Url);
                    Assert.IsTrue(entityMappedFromItemVersion.MediaProperty.IsAutoPlay);
                    Assert.IsTrue(entityMappedFromItemVersion.MediaProperty.IsLoop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", entityMappedFromItemVersion.MediaProperty.PreviewImageUrl);

                    Assert.AreEqual(levelOneTermB.Id, entityMappedFromItemVersion.TaxonomyProperty.Id);
                    Assert.AreEqual(levelOneTermB.Label, entityMappedFromItemVersion.TaxonomyProperty.Label);

                    Assert.AreEqual(levelTwoTermAA.Id, entityMappedFromItemVersion.TaxonomyMultiProperty[0].Id);
                    Assert.AreEqual(levelTwoTermAA.Label, entityMappedFromItemVersion.TaxonomyMultiProperty[0].Label);
                    Assert.AreEqual(levelTwoTermAB.Id, entityMappedFromItemVersion.TaxonomyMultiProperty[1].Id);
                    Assert.AreEqual(levelTwoTermAB.Label, entityMappedFromItemVersion.TaxonomyMultiProperty[1].Label);

                    // #3 Validate straight list item collection to entity mappings
                    Assert.AreEqual(555, entitiesMappedFromItemCollection[0].IntegerProperty);
                    Assert.AreEqual(5.5, entitiesMappedFromItemCollection[0].DoubleProperty);
                    Assert.AreEqual(500.95, entitiesMappedFromItemCollection[0].CurrencyProperty);
                    Assert.IsTrue(entitiesMappedFromItemCollection[0].BoolProperty.Value);
                    Assert.IsFalse(entitiesMappedFromItemCollection[0].BoolDefaultTrueProperty);
                    Assert.IsTrue(entitiesMappedFromItemCollection[0].BoolDefaultFalseProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entitiesMappedFromItemCollection[0].DateTimeFormulaProperty);
                    Assert.AreEqual(new DateTime(1977, 7, 7), entitiesMappedFromItemCollection[0].DateTimeProperty);
                    Assert.AreEqual("Text value", entitiesMappedFromItemCollection[0].TextProperty);
                    Assert.AreEqual("Note value", entitiesMappedFromItemCollection[0].NoteProperty);
                    Assert.AreEqual("<p class=\"some-css-class\">HTML value</p>", entitiesMappedFromItemCollection[0].HtmlProperty);

                    Assert.IsNotNull(entitiesMappedFromItemCollection[0].ImageProperty);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entitiesMappedFromItemCollection[0].ImageProperty.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", entitiesMappedFromItemCollection[0].ImageProperty.ImageUrl);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entitiesMappedFromItemCollection[0].UrlProperty.Url);
                    Assert.AreEqual("patate!", entitiesMappedFromItemCollection[0].UrlProperty.Description);

                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", entitiesMappedFromItemCollection[0].UrlImageProperty.Url);
                    Assert.AreEqual("patate!", entitiesMappedFromItemCollection[0].UrlImageProperty.Description);

                    // No lookups or User fields because DataRow formatting screws up lookup values (we lose the lookup IDs)
                    Assert.AreEqual("Some media file title", entitiesMappedFromItemCollection[0].MediaProperty.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), entitiesMappedFromItemCollection[0].MediaProperty.Url);
                    Assert.IsTrue(entitiesMappedFromItemCollection[0].MediaProperty.IsAutoPlay);
                    Assert.IsTrue(entitiesMappedFromItemCollection[0].MediaProperty.IsLoop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", entitiesMappedFromItemCollection[0].MediaProperty.PreviewImageUrl);

                    Assert.AreEqual(levelOneTermB.Id, entitiesMappedFromItemCollection[0].TaxonomyProperty.Id);
                    Assert.AreEqual(levelOneTermB.Label, entitiesMappedFromItemCollection[0].TaxonomyProperty.Label);

                    Assert.AreEqual(levelTwoTermAA.Id, entitiesMappedFromItemCollection[0].TaxonomyMultiProperty[0].Id);
                    Assert.AreEqual(levelTwoTermAA.Label, entitiesMappedFromItemCollection[0].TaxonomyMultiProperty[0].Label);
                    Assert.AreEqual(levelTwoTermAB.Id, entitiesMappedFromItemCollection[0].TaxonomyMultiProperty[1].Id);
                    Assert.AreEqual(levelTwoTermAB.Label, entitiesMappedFromItemCollection[0].TaxonomyMultiProperty[1].Label);
                }

                // Cleanup term set so that we don't pollute the metadata store
                newTermSet.Delete();
                defaultSiteCollectionTermStore.CommitAll();
            }
        }
Пример #52
0
        public void EnsureList_WhenEnsuringANonExistingListWithMultipleValidationLocales_ItShouldApplyTheCorrectOnes()
        {
            // Arrange
            const string Url = "testUrl";
            const string NameFr = "NameFieldKeyFr";
            const string NameEn = "NameFieldKeyEn";
            const string NameDe = "NameFieldKeyDe";
            const string Desc = "DescriptionFieldKey";
            const string FormulaRequiredValue = "\"Bob\"";

            var validationFormulaFr = string.Format(
                CultureInfo.InvariantCulture,
                "={0}={1}",
                NameFr,
                FormulaRequiredValue);

            var validationFormulaEn = string.Format(
                CultureInfo.InvariantCulture,
                "={0}={1}",
                NameEn,
                FormulaRequiredValue);

            var validationFormulaDe = string.Format(
                CultureInfo.InvariantCulture,
                "={0}={1}",
                NameDe,
                FormulaRequiredValue);

            const string ValidationMessageEn = "Name needs to be Bill";
            const string ValidationMessageFr = "Name needs to be Robert";
            const string ValidationMessageDe = "Name needs to be Franz";

            const string ValidationLocaleEn = "en-US";
            const string ValidationLocaleFr = "fr-FR";
            const string ValidationLocaleDe = "de-DE";

            // Web will be in de-DE Locale, so field will be using the DE Name
            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    NameDe,
                    Desc,
                    "GroupKey");

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            listInfo.FieldDefinitions = new[]
            {
                textFieldInfo
            };

            listInfo.ValidationSettings.Add(ValidationLocaleEn, new ListValidationInfo(validationFormulaEn, ValidationMessageEn));
            listInfo.ValidationSettings.Add(ValidationLocaleFr, new ListValidationInfo(validationFormulaFr, ValidationMessageFr));
            listInfo.ValidationSettings.Add(ValidationLocaleDe, new ListValidationInfo(validationFormulaDe, ValidationMessageDe));

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;
                rootWeb.Locale = new CultureInfo("de-DE");
                rootWeb.Update();

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var numberOfListsBefore = rootWeb.Lists.Count;

                    // Act
                    var list = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.AreEqual(listInfo.DisplayNameResourceKey, list.TitleResource.Value);
                    list = rootWeb.GetList(Url);
                    Assert.IsNotNull(list);
                    Assert.AreEqual(numberOfListsBefore + 1, rootWeb.Lists.Count);
                    Assert.AreEqual(validationFormulaDe, list.ValidationFormula);
                    Assert.AreEqual(ValidationMessageDe, list.ValidationMessage);
                }
            }
        }
Пример #53
0
        public void EnsureField_WhenListFieldCollection_AndSiteColumnAlreadyExist_ShouldAddFieldToListAndShouldAvoidModifyingSiteColumn()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                                                                                    // set will not be cleaned up and upon next test run we will
                                                                                    // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                defaultSiteCollectionTermStore.CommitAll();

                var textFieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    textFieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    MaxLength = 50
                };

                var taxoFieldId = new Guid("{9708BECA-D3EF-41C3-ABD3-5F1BAC3CE5AE}");
                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    taxoFieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                var taxoMultiFieldId = new Guid("{B2517ECF-819E-4F75-88AF-18E926AD30BD}");
                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    taxoMultiFieldId,
                    "NameKeyMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    // no term store mapping
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    // 1) Ensure the fields on the site collection with first version of their definition
                    var siteCollectionFields = testScope.SiteCollection.RootWeb.Fields;
                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    SPField textSiteColumn = fieldHelper.EnsureField(siteCollectionFields, textFieldInfo);
                    SPField taxoSiteColumn = fieldHelper.EnsureField(siteCollectionFields, taxoFieldInfo);
                    SPField taxoMultiSiteColumn = fieldHelper.EnsureField(siteCollectionFields, taxoMultiFieldInfo);

                    // 2) Change the field definitions slightly
                    textFieldInfo.Required = RequiredType.Required;
                    textFieldInfo.DefaultValue = "SomeDefaultValue";

                    taxoFieldInfo.TermStoreMapping = new TaxonomyContext(levelOneTermA);    // constrain the term to a child term of the term set

                    taxoMultiFieldInfo.TermStoreMapping = new TaxonomyContext(testTermSet); // list column has a mapping, whereas the site column doesn't

                    // 3) Ensure the modified field definitions directly on the list
                    IListHelper listHelper = injectionScope.Resolve<IListHelper>();
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);
                    var listFields = list.Fields;
                    SPField textListColumn = fieldHelper.EnsureField(listFields, textFieldInfo);
                    SPField taxoListColumn = fieldHelper.EnsureField(listFields, taxoFieldInfo);
                    SPField taxoMultiListColumn = fieldHelper.EnsureField(listFields, taxoMultiFieldInfo);

                    // 4) Assert that the site column definitions were not touched
                    list = testScope.SiteCollection.RootWeb.Lists[list.ID];

                    // Text field
                    var siteText = testScope.SiteCollection.RootWeb.Fields[textFieldInfo.Id];
                    var listText = list.Fields[textFieldInfo.Id];
                    Assert.IsFalse(siteText.Required);
                    Assert.IsTrue(string.IsNullOrEmpty(siteText.DefaultValue));

                    Assert.IsTrue(listText.Required);
                    Assert.AreEqual("SomeDefaultValue", listText.DefaultValue);

                    // Taxo single field
                    var siteTaxo = (TaxonomyField)testScope.SiteCollection.RootWeb.Fields[taxoFieldInfo.Id];
                    var listTaxo = (TaxonomyField)list.Fields[taxoFieldInfo.Id];
                    Assert.AreEqual(testTermSet.Id, siteTaxo.TermSetId);
                    Assert.AreEqual(defaultSiteCollectionTermStore.Id, siteTaxo.SspId);
                    Assert.AreEqual(Guid.Empty, siteTaxo.AnchorId);    // choices should not be constrained to a child term
                    Assert.IsTrue(siteTaxo.IsTermSetValid);

                    Assert.AreEqual(testTermSet.Id, listTaxo.TermSetId);
                    Assert.AreEqual(defaultSiteCollectionTermStore.Id, listTaxo.SspId);
                    Assert.AreEqual(levelOneTermA.Id, listTaxo.AnchorId);    // choices should be constrained to a child term
                    Assert.IsTrue(listTaxo.IsTermSetValid);
                    Assert.IsTrue(listTaxo.IsAnchorValid);

                    // Taxo multi field
                    var siteTaxoMulti = (TaxonomyField)testScope.SiteCollection.RootWeb.Fields[taxoMultiFieldInfo.Id];
                    var listTaxoMulti = (TaxonomyField)list.Fields[taxoMultiFieldInfo.Id];

                    Assert.AreEqual(Guid.Empty, siteTaxoMulti.TermSetId);    // empty binding on site column
                    Assert.AreEqual(Guid.Empty, siteTaxoMulti.SspId);
                    Assert.AreEqual(Guid.Empty, siteTaxoMulti.AnchorId);
                    Assert.IsFalse(siteTaxoMulti.IsTermSetValid);

                    Assert.AreEqual(testTermSet.Id, listTaxoMulti.TermSetId);
                    Assert.AreEqual(defaultSiteCollectionTermStore.Id, listTaxoMulti.SspId);
                    Assert.AreEqual(Guid.Empty, listTaxoMulti.AnchorId);    // choices should not be constrained to a child term
                    Assert.IsTrue(listTaxoMulti.IsTermSetValid);
                }
            }
        }
Пример #54
0
        public void EnsureList_WhenEnsuringANonExistingListWithInvalidFormula_ItShouldThrowException()
        {
            // Arrange
            const string Url = "testUrl";
            const string Name = "NameFieldKey";
            const string Desc = "DescriptionFieldKey";
            const string WebLocale = "en-US";
            const string FormulaRequiredValue = "'Bob'";
            var expectedFormula = string.Format(
                CultureInfo.InvariantCulture,
                "={0}={1}",
                Name,
                FormulaRequiredValue);

            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    Name,
                    Desc,
                    "GroupKey");

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            listInfo.FieldDefinitions = new[]
            {
                textFieldInfo
            };

            listInfo.ValidationSettings.Add(WebLocale, new ListValidationInfo(expectedFormula));

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var numberOfListsBefore = rootWeb.Lists.Count;

                    // Act
                    var list = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.IsTrue(false);   // Exception should have been thrown already
                }
            }
        }
Пример #55
0
        public void EnsureField_WhenListFieldCollection_AndSiteColumnDoesntExist_ShouldAddFieldToBothListAndParentRootWeb()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    IListHelper listHelper = injectionScope.Resolve<IListHelper>();

                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    var fieldsCollection = list.Fields;

                    SPField field = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    SPList testList = testScope.SiteCollection.RootWeb.Lists[list.ID];
                    Assert.IsNotNull(testList.Fields[fieldId]);
                    Assert.IsNotNull(testScope.SiteCollection.RootWeb.Fields[fieldId]);    // would be null if we hadn't bothered ensuring the field on the root web
                }
            }
        }
Пример #56
0
        public void EnsureField_WhenOnListInFrenchSubWeb_ShouldCreateListFieldWithFrenchDisplayName()
        {
            // English root web
            using (var testScope = SiteTestScope.BlankSite(Language.English.Culture.LCID))
            {
                var fieldId = new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}");
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    fieldId,
                    "Test_FieldTitle",
                    "Test_FieldDescription",
                    "Test_ContentGroup")
                {
                    MaxLength = 50,
                    Required = RequiredType.Required
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    SPWeb frenchSubWeb = testScope.SiteCollection.RootWeb.Webs.Add("subweb", "French sub-web", string.Empty, (uint)Language.French.Culture.LCID, "STS#1", false, false);

                    IListHelper listHelper = injectionScope.Resolve<IListHelper>();
                    SPList subWebList = listHelper.EnsureList(frenchSubWeb, listInfo);

                    IFieldHelper fieldHelper = injectionScope.Resolve<IFieldHelper>();
                    SPFieldCollection listFields = testScope.SiteCollection.RootWeb.Webs["subweb"].Lists[subWebList.ID].Fields;

                    SPField field = fieldHelper.EnsureField(listFields, textFieldInfo);
                    SPField fieldOnOldCollection = listFields[textFieldInfo.Id];
                    SPField fieldRefetched = testScope.SiteCollection.RootWeb.Webs["subweb"].Lists[subWebList.ID].Fields[textFieldInfo.Id];

                    // Set MUI to french
                    var ambientThreadCulture = Thread.CurrentThread.CurrentUICulture;
                    Thread.CurrentThread.CurrentUICulture = Language.French.Culture;

                    Assert.AreEqual("FR Nom de champ", field.Title);
                    Assert.AreEqual("FR Description de champ", field.Description);
                    Assert.AreEqual("FR Groupe de contenu", field.Group);

                    Assert.AreEqual("FR Nom de champ", fieldOnOldCollection.Title);
                    Assert.AreEqual("FR Description de champ", fieldOnOldCollection.Description);
                    Assert.AreEqual("FR Groupe de contenu", fieldOnOldCollection.Group);

                    Assert.AreEqual("FR Nom de champ", fieldRefetched.Title);
                    Assert.AreEqual("FR Description de champ", fieldRefetched.Description);
                    Assert.AreEqual("FR Groupe de contenu", fieldRefetched.Group);

                    // Reset MUI to its old abient value
                    Thread.CurrentThread.CurrentUICulture = ambientThreadCulture;
                }
            }
        }
        public void FromEntityToEntityRoundTrip_ShouldEndUpWithIdenticalEntities()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey");

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey");

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoBasic = new BooleanFieldInfo(
                    "TestInternalNameBool",
                    new Guid("{F556AB6B-9E51-43E2-99C9-4A4E551A4BEF}"),
                    "NameKeyBool",
                    "DescriptionKeyBool",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoDefaultTrue = new BooleanFieldInfo(
                    "TestInternalNameBoolTrue",
                    new Guid("{0D0289AD-C5FB-495B-96C6-48CC46737D08}"),
                    "NameKeyBoolTrue",
                    "DescriptionKeyBoolTrue",
                    "GroupKey")
                {
                    DefaultValue = true
                };

                BooleanFieldInfo boolFieldInfoDefaultFalse = new BooleanFieldInfo(
                    "TestInternalNameBoolFalse",
                    new Guid("{628181BD-9B0B-4B7E-934F-1CF1796EA4E4}"),
                    "NameKeyBoolFalse",
                    "DescriptionKeyBoolFalse",
                    "GroupKey")
                {
                    DefaultValue = false
                };

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                DateTimeFieldInfo dateTimeFieldInfo = new DateTimeFieldInfo(
                    "TestInternalNameDateDefault",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTimeDefault",
                    "DescriptionKeyDateTimeDefault",
                    "GroupKey");

                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey");

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey");

                ImageFieldInfo imageFieldInfo = new ImageFieldInfo(
                    "TestInternalNameImage",
                    new Guid("{6C5B9E77-B621-43AA-BFBF-B333093EFCAE}"),
                    "NameKeyImage",
                    "DescriptionKeyImage",
                    "GroupKey");

                UrlFieldInfo urlFieldInfo = new UrlFieldInfo(
                    "TestInternalNameUrl",
                    new Guid("{208F904C-5A1C-4E22-9A79-70B294FABFDA}"),
                    "NameKeyUrl",
                    "DescriptionKeyUrl",
                    "GroupKey");

                UrlFieldInfo urlFieldInfoImage = new UrlFieldInfo(
                    "TestInternalNameUrlImg",
                    new Guid("{96D22CFF-5B40-4675-B632-28567792E11B}"),
                    "NameKeyUrlImg",
                    "DescriptionKeyUrlImg",
                    "GroupKey")
                {
                    Format = UrlFieldFormat.Image
                };

                LookupFieldInfo lookupFieldInfo = new LookupFieldInfo(
                    "TestInternalNameLookup",
                    new Guid("{62F8127C-4A8C-4217-8BD8-C6712753AFCE}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey");

                LookupFieldInfo lookupFieldInfoAlt = new LookupFieldInfo(
                    "TestInternalNameLookupAlt",
                    new Guid("{1F05DFFA-6396-4AEF-AD23-72217206D35E}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    ShowField = "ID"
                };

                LookupMultiFieldInfo lookupMultiFieldInfo = new LookupMultiFieldInfo(
                    "TestInternalNameLookupM",
                    new Guid("{2C9D4C0E-21EB-4742-8C6C-4C30DCD08A05}"),
                    "NameKeyMulti",
                    "DescriptionKeyMulti",
                    "GroupKey");

                var ensuredUser1 = testScope.SiteCollection.RootWeb.EnsureUser(Environment.UserDomainName + "\\" + Environment.UserName);
                var ensuredUser2 = testScope.SiteCollection.RootWeb.EnsureUser("OFFICE\\maxime.boissonneault");

                UserFieldInfo userFieldInfo = new UserFieldInfo(
                    "TestInternalNameUser",
                    new Guid("{5B74DD50-0D2D-4D24-95AF-0C4B8AA3F68A}"),
                    "NameKeyUser",
                    "DescriptionKeyUser",
                    "GroupKey");

                UserMultiFieldInfo userMultiFieldInfo = new UserMultiFieldInfo(
                    "TestInternalNameUserMulti",
                    new Guid("{8C662588-D54E-4905-B232-856C2239B036}"),
                    "NameKeyUserMulti",
                    "DescriptionKeyUserMulti",
                    "GroupKey");

                MediaFieldInfo mediaFieldInfo = new MediaFieldInfo(
                    "TestInternalNameMedia",
                    new Guid("{A2F070FE-FE33-44FC-9FDF-D18E74ED4D67}"),
                    "NameKeyMedia",
                    "DescriptionKeyMEdia",
                    "GroupKey");

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    new Guid("{2F49D362-B014-41BB-9959-1000C9A7FFA0}"),
                    "NameKeyMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(levelOneTermA)   // choices limited to children of a specific term, instead of having full term set choices
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        boolFieldInfoBasic,
                        boolFieldInfoDefaultTrue,
                        boolFieldInfoDefaultFalse,
                        dateTimeFieldInfoFormula,
                        dateTimeFieldInfo,
                        textFieldInfo,
                        noteFieldInfo,
                        htmlFieldInfo,
                        imageFieldInfo,
                        urlFieldInfo,
                        urlFieldInfoImage,
                        lookupFieldInfo,
                        lookupFieldInfoAlt,
                        lookupMultiFieldInfo,
                        userFieldInfo,
                        userMultiFieldInfo,
                        mediaFieldInfo,
                        taxoFieldInfo,
                        taxoMultiFieldInfo
                    };

                ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    FieldDefinitions = fieldsToEnsure
                };

                // Note how we need to specify SPSite for injection context - ISharePointEntityBinder's implementation
                // is lifetime-scoped to InstancePerSite.
                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(testScope.SiteCollection))
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Lookup field ListId setup
                    SPList lookupList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, lookupListInfo);
                    lookupFieldInfo.ListId = lookupList.ID;
                    lookupFieldInfoAlt.ListId = lookupList.ID;
                    lookupMultiFieldInfo.ListId = lookupList.ID;

                    // Create the looked-up items
                    var lookupItem1 = lookupList.Items.Add();
                    lookupItem1["Title"] = "Test Item 1";
                    lookupItem1.Update();

                    var lookupItem2 = lookupList.Items.Add();
                    lookupItem2["Title"] = "Test Item 2";
                    lookupItem2.Update();

                    // Create the first test list
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    // Initialize the entity object with all the property values we want to apply on the new list item
                    var entityBinder = injectionScope.Resolve<ISharePointEntityBinder>();
                    var entity = new TestItemEntityWithLookups()
                    {
                        Title = "Test entity",
                        IntegerProperty = 555,
                        DoubleProperty = 5.5,
                        CurrencyProperty = 500.95,
                        BoolProperty = true,
                        BoolDefaultTrueProperty = false,
                        BoolDefaultFalseProperty = true,
                        DateTimeFormulaProperty = new DateTime(2005, 10, 21),
                        DateTimeProperty = new DateTime(2005, 10, 21),
                        TextProperty = "Text value",
                        NoteProperty = "Note value",
                        HtmlProperty = "<p class=\"some-css-class\">HTML value</p>",
                        ImageProperty = new ImageValue()
                        {
                            Hyperlink = "http://github.com/GSoft-SharePoint/",
                            ImageUrl = "/_layouts/15/MyFolder/MyImage.png"
                        },
                        UrlProperty = new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        },
                        UrlImageProperty = new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        },
                        LookupProperty = new LookupValue(1, "Test Item 1"),
                        LookupAltProperty = new LookupValue(2, "2"),
                        LookupMultiProperty = new LookupValueCollection() { new LookupValue(1, "Test Item 1"), new LookupValue(2, "Test Item 2") },
                        UserProperty = new UserValue(ensuredUser1),
                        UserMultiProperty = new UserValueCollection() { new UserValue(ensuredUser1), new UserValue(ensuredUser2) },
                        MediaProperty = new MediaValue()
                        {
                            Title = "Some media file title",
                            Url = "/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf",
                            IsAutoPlay = true,
                            IsLoop = true,
                            PreviewImageUrl = "/_layouts/15/Images/logo.png"
                        },
                        TaxonomyProperty = new TaxonomyValue(createdTermB),
                        TaxonomyMultiProperty = new TaxonomyValueCollection(
                        new List<TaxonomyValue>() 
                            { 
                                new TaxonomyValue(createdTermAA), 
                                new TaxonomyValue(createdTermAB)
                            })
                    };

                    // Act 
                    
                    // Create the list item and bind the Entity's values to it
                    var itemOnList = list.AddItem();
                    entityBinder.FromEntity<TestItemEntityWithLookups>(entity, itemOnList);
                    itemOnList.Update();

                    // Then use the list item as data source for a brand new entity
                    var copyEntity = entityBinder.Get<TestItemEntityWithLookups>(itemOnList);

                    // Assert
                    // #1: validate ListItem field values on the mapped item object
                    Assert.AreEqual(entity.Title, copyEntity.Title);
                    Assert.AreEqual(entity.IntegerProperty, copyEntity.IntegerProperty);
                    Assert.AreEqual(entity.DoubleProperty, copyEntity.DoubleProperty);
                    Assert.AreEqual(entity.CurrencyProperty, copyEntity.CurrencyProperty);
                    Assert.AreEqual(entity.BoolProperty, copyEntity.BoolProperty);
                    Assert.AreEqual(entity.BoolDefaultTrueProperty, copyEntity.BoolDefaultTrueProperty);
                    Assert.AreEqual(entity.BoolDefaultFalseProperty, copyEntity.BoolDefaultFalseProperty);
                    Assert.AreEqual(entity.DateTimeFormulaProperty, copyEntity.DateTimeFormulaProperty);
                    Assert.AreEqual(entity.DateTimeProperty, copyEntity.DateTimeProperty);
                    Assert.AreEqual(entity.TextProperty, copyEntity.TextProperty);
                    Assert.AreEqual(entity.NoteProperty, copyEntity.NoteProperty);
                    Assert.AreEqual(entity.HtmlProperty, copyEntity.HtmlProperty);
                    Assert.AreEqual(entity.ImageProperty.ImageUrl, copyEntity.ImageProperty.ImageUrl);
                    Assert.AreEqual(entity.ImageProperty.Hyperlink, copyEntity.ImageProperty.Hyperlink);
                    Assert.AreEqual(entity.UrlProperty.Url, copyEntity.UrlProperty.Url);
                    Assert.AreEqual(entity.UrlProperty.Description, copyEntity.UrlProperty.Description);
                    Assert.AreEqual(entity.UrlImageProperty.Url, copyEntity.UrlImageProperty.Url);
                    Assert.AreEqual(entity.UrlImageProperty.Description, copyEntity.UrlImageProperty.Description);
                    Assert.AreEqual(entity.LookupProperty.Id, copyEntity.LookupProperty.Id);
                    Assert.AreEqual(entity.LookupProperty.Value, copyEntity.LookupProperty.Value);
                    Assert.AreEqual(entity.LookupAltProperty.Id, copyEntity.LookupAltProperty.Id);
                    Assert.AreEqual(entity.LookupAltProperty.Value, copyEntity.LookupAltProperty.Value);
                    Assert.AreEqual(entity.LookupMultiProperty[0].Id, copyEntity.LookupMultiProperty[0].Id);
                    Assert.AreEqual(entity.LookupMultiProperty[0].Value, copyEntity.LookupMultiProperty[0].Value);
                    Assert.AreEqual(entity.LookupMultiProperty[1].Id, copyEntity.LookupMultiProperty[1].Id);
                    Assert.AreEqual(entity.LookupMultiProperty[1].Value, copyEntity.LookupMultiProperty[1].Value);
                    Assert.AreEqual(entity.UserProperty.Id, copyEntity.UserProperty.Id);
                    Assert.AreEqual(entity.UserProperty.DisplayName, copyEntity.UserProperty.DisplayName);
                    Assert.AreEqual(entity.UserMultiProperty[0].Id, copyEntity.UserMultiProperty[0].Id);
                    Assert.AreEqual(entity.UserMultiProperty[0].DisplayName, copyEntity.UserMultiProperty[0].DisplayName);
                    Assert.AreEqual(entity.UserMultiProperty[1].Id, copyEntity.UserMultiProperty[1].Id);
                    Assert.AreEqual(entity.UserMultiProperty[1].DisplayName, copyEntity.UserMultiProperty[1].DisplayName);
                    Assert.AreEqual(entity.MediaProperty.Title, copyEntity.MediaProperty.Title);
                    Assert.AreEqual(entity.MediaProperty.Url, copyEntity.MediaProperty.Url);
                    Assert.AreEqual(entity.TaxonomyProperty.Id, copyEntity.TaxonomyProperty.Id);
                    Assert.AreEqual(entity.TaxonomyProperty.Label, copyEntity.TaxonomyProperty.Label);
                    Assert.AreEqual(entity.TaxonomyMultiProperty[0].Id, copyEntity.TaxonomyMultiProperty[0].Id);
                    Assert.AreEqual(entity.TaxonomyMultiProperty[0].Label, copyEntity.TaxonomyMultiProperty[0].Label);
                    Assert.AreEqual(entity.TaxonomyMultiProperty[1].Id, copyEntity.TaxonomyMultiProperty[1].Id);
                    Assert.AreEqual(entity.TaxonomyMultiProperty[1].Label, copyEntity.TaxonomyMultiProperty[1].Label);
                }
            }
        }
Пример #58
0
        public void EnsureField_WhenOtherFieldWithSameInternalNameAlreadyExists_ShouldNotAttemptFieldCreationAndReturnExistingMatch()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    Required = RequiredType.NotRequired,
                    MaxLength = 50
                };

                TextFieldInfo alternateTextFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{9EBF5EC3-5FC4-4ACF-B404-AC0A2D74A10F}"),     // new GUID, but same internal name
                    "NameKeyAlt",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    Required = RequiredType.Required,
                    MaxLength = 500
                };

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

                    // STEP 1: Create the first field
                    int noOfFieldsBefore = fieldsCollection.Count;
                    SPField originalField = fieldHelper.EnsureField(fieldsCollection, textFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(originalField);
                    Assert.AreEqual(textFieldInfo.Id, originalField.Id);
                    Assert.AreEqual(textFieldInfo.InternalName, originalField.InternalName);

                    // STEP 2: Try to create the internal-name-clashing alternate field
                    SPField alternateEnsuredField = fieldHelper.EnsureField(fieldsCollection, alternateTextFieldInfo);

                    Assert.AreEqual(noOfFieldsBefore + 1, fieldsCollection.Count);
                    Assert.IsNotNull(alternateEnsuredField);
                    Assert.AreEqual(textFieldInfo.Id, alternateEnsuredField.Id);               // metadata should be sane as original field, not alternate field
                    Assert.AreEqual(textFieldInfo.InternalName, alternateEnsuredField.InternalName);

                    // The returned field shouldn't have gotten its properties updated
                    // (as in this shouldn't happen: "Ensure and Update existing other
                    // unrelated field which has clashing Guid/Internal name")
                    Assert.IsFalse(alternateEnsuredField.Required);     // the original field was actually returned
                    Assert.AreEqual(50, ((SPFieldText)alternateEnsuredField).MaxLength);
                }
            }
        }
Пример #59
0
        public void EnsureField_WhenEnsuringListColumnWithEnforceUniqueValue_AndFieldInfoIsSupportedFieldType_ShouldInitializeFieldToEnforceUniqueness_AndForceIndexation()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey")
                {
                    EnforceUniqueValues = true,
                    LocaleId = 3084 // fr-CA
                };

                DateTimeFieldInfo dateTimeFieldInfo = new DateTimeFieldInfo(
                    "TestInternalNameDate",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTime",
                    "DescriptionKeyDateTime",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                var ensuredUser1 = testScope.SiteCollection.RootWeb.EnsureUser(Environment.UserDomainName + "\\" + Environment.UserName);

                UserFieldInfo userFieldInfo = new UserFieldInfo(
                    "TestInternalNameUser",
                    new Guid("{5B74DD50-0D2D-4D24-95AF-0C4B8AA3F68A}"),
                    "NameKeyUser",
                    "DescriptionKeyUser",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                LookupFieldInfo lookupFieldInfo = new LookupFieldInfo(
                    "TestInternalNameLookup",
                    new Guid("{62F8127C-4A8C-4217-8BD8-C6712753AFCE}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    EnforceUniqueValues = true
                };

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKey",
                    "DescriptionKey",
                    "GroupKey")
                {
                    EnforceUniqueValues = true,
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        dateTimeFieldInfo,
                        textFieldInfo,
                        userFieldInfo,
                        lookupFieldInfo,
                        taxoFieldInfo,
                    };

                ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");

                ListInfo listInfo1 = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    FieldDefinitions = fieldsToEnsure
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Lookup field ListId setup
                    SPList lookupList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, lookupListInfo);
                    lookupFieldInfo.ListId = lookupList.ID;

                    // Create the looked-up items
                    var lookupItem1 = lookupList.Items.Add();
                    lookupItem1["Title"] = "Test Item 1";
                    lookupItem1.Update();

                    var lookupItem2 = lookupList.Items.Add();
                    lookupItem2["Title"] = "Test Item 2";
                    lookupItem2.Update();

                    // Create the test list (which should provision both site columns and list columns)
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo1);

                    // Act
                    var originalItemWithUniqueValues = list.AddItem();
                    originalItemWithUniqueValues["TestInternalNameInteger"] = 555;
                    originalItemWithUniqueValues["TestInternalNameNumber"] = 5.5;
                    originalItemWithUniqueValues["TestInternalNameCurrency"] = 500.95;
                    originalItemWithUniqueValues["TestInternalNameDate"] = new DateTime(2005, 10, 21);
                    originalItemWithUniqueValues["TestInternalNameText"] = "Text value";
                    originalItemWithUniqueValues["TestInternalNameLookup"] = new SPFieldLookupValue(1, "Test Item 1");
                    originalItemWithUniqueValues["TestInternalNameUser"] = new SPFieldUserValue(testScope.SiteCollection.RootWeb, ensuredUser1.ID, ensuredUser1.Name);
                    var taxonomyField = (TaxonomyField)originalItemWithUniqueValues.Fields.GetFieldByInternalName("TestInternalNameTaxo");
                    taxonomyField.SetFieldValue(originalItemWithUniqueValues, createdTermB);
                    originalItemWithUniqueValues.Update();

                    // Assert
                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameInteger").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameInteger"] = 555;
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Integer field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameNumber").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameNumber"] = 5.5;
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Number field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameCurrency").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameCurrency"] = 500.95;
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Currency field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameDate").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameDate"] = new DateTime(2005, 10, 21);
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this DateTime field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameText").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameText"] = "Text value";
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Text field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameLookup").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameLookup"] = new SPFieldLookupValue(1, "Test Item 1");
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Lookup field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameUser").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        uniquenessBreakingItem["TestInternalNameUser"] = new SPFieldUserValue(testScope.SiteCollection.RootWeb, ensuredUser1.ID, ensuredUser1.Name);
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this User field");
                    }
                    catch (SPException)
                    {
                    }

                    Assert.IsTrue(list.Fields.GetFieldByInternalName("TestInternalNameTaxo").Indexed);
                    try
                    {
                        var uniquenessBreakingItem = list.AddItem();
                        taxonomyField = (TaxonomyField)uniquenessBreakingItem.Fields.GetFieldByInternalName("TestInternalNameTaxo");
                        taxonomyField.SetFieldValue(uniquenessBreakingItem, createdTermB);
                        uniquenessBreakingItem.Update();
                        Assert.Fail("Should've thrown SPException because values should be unique on this Taxonomy field");
                    }
                    catch (SPException)
                    {
                    }
                }

                // Cleanup term set so that we don't pollute the metadata store
                newTermSet.Delete();
                defaultSiteCollectionTermStore.CommitAll();
            }
        }
Пример #60
0
        public void EnsureList_WhenEnsuringANonExistingListWithNotFoundLocale_ItShouldDoNothing()
        {
            // Arrange
            const string Url = "testUrl";
            const string Name = "NameFieldKey";
            const string Desc = "DescriptionFieldKey";
            const string FormulaRequiredValue = "\"Bob\"";

            var validationFormula = string.Format(
                CultureInfo.InvariantCulture,
                "={0}={1}",
                Name,
                FormulaRequiredValue);

            const string ValidationMessage = "Name needs to be Bob";
            const string ValidationLocale = "fr-FR";

            var textFieldInfo = new TextFieldInfo(
                    "TestInternalName",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    Name,
                    Desc,
                    "GroupKey");

            var listInfo = new ListInfo(Url, "NameKey", "DescriptionKey");

            listInfo.FieldDefinitions = new[]
            {
                textFieldInfo
            };

            listInfo.ValidationSettings.Add(ValidationLocale, new ListValidationInfo(validationFormula, ValidationMessage));

            using (var testScope = SiteTestScope.BlankSite())
            {
                var rootWeb = testScope.SiteCollection.RootWeb;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var numberOfListsBefore = rootWeb.Lists.Count;

                    // Act
                    var list = listHelper.EnsureList(rootWeb, listInfo);

                    // Assert
                    Assert.AreEqual(listInfo.DisplayNameResourceKey, list.TitleResource.Value);
                    list = rootWeb.GetList(Url);
                    Assert.IsNotNull(list);
                    Assert.AreEqual(numberOfListsBefore + 1, rootWeb.Lists.Count);
                    Assert.AreEqual(string.Empty, list.ValidationFormula);
                    Assert.AreEqual(string.Empty, list.ValidationMessage);
                }
            }
        }