Ejemplo n.º 1
0
        public void WriteValueToListItem_GivenDateTimeFieldInfo_ShouldUseDateTimeValueWriter()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var correctWriterWasUsed = false;
                var fieldInfo            = new DateTimeFieldInfo("InternalName", Guid.NewGuid(), string.Empty, string.Empty, string.Empty);

                ShimDateTimeValueWriter.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 DateTimeValueWriter should have been used for the DateTimeFieldInfo type.");
            }
        }
Ejemplo n.º 2
0
        public void WriteValueToListItem_WhenGivenFieldValue_ShouldUpdateFieldValue()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var setValue = "SomeTitle";
                var setField = BuiltInFields.Title;

                var fakeListItemShim = new ShimSPListItem()
                {
                    ItemSetStringObject = (internalName, value) =>
                    {
                        Assert.AreEqual(setValue, value as string);
                        Assert.AreEqual(setField.InternalName, internalName);
                    }
                };

                IFieldValueWriter writer;
                SPListItem        fakeListItem = fakeListItemShim.Instance;

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

                // Act
                writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(setField, setValue));

                // Assert
            }
        }
Ejemplo n.º 3
0
        public void WebPartHelper_ShouldCreateAResponsivePlaceholderWebPartWithCorrectValues()
        {
            // Arrange
            ILogger    logger;
            IXmlHelper xmlHelper;

            using (var scope = UnitTestServiceLocator.BeginLifetimeScope())
            {
                logger    = scope.Resolve <ILogger>();
                xmlHelper = scope.Resolve <IXmlHelper>();
            }

            var webPartHelper = new WebPartHelper(xmlHelper, logger);

            // Define values for the placeholder
            var height          = 300;
            var backgroundColor = "#0092d7";
            var fontColor       = "#ffffff";
            var text            = "Testing";

            var expectedWebPartContent = string.Format(
                CultureInfo.InvariantCulture,
                "<div class='responsive-placeholder' style='height:{0}px;line-height:{0}px;background-color:{1};color:{2};text-align:center;'>{3}</div>",
                height,
                backgroundColor,
                fontColor,
                text);

            // Act
            var responsivePlaceholderWebPart = webPartHelper.CreateResponsivePlaceholderWebPart(height, backgroundColor, fontColor, text);

            // Assert
            Assert.IsNotNull(responsivePlaceholderWebPart);
            Assert.AreEqual(expectedWebPartContent, responsivePlaceholderWebPart.Content.InnerText);
        }
Ejemplo n.º 4
0
        public void WriteValuesToListItem_WhenGivenNullUrl_ShouldCopyNullUrl()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var expectedField  = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null);
                var actualUrlValue = new SPFieldUrlValue();

                var fakeListItemShim = new ShimSPListItem()
                {
                    ItemSetStringObject = (internalName, value) =>
                    {
                        actualUrlValue = value as SPFieldUrlValue;
                    }
                };

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

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

                // Assert
                Assert.IsNull(actualUrlValue);
            }
        }
Ejemplo n.º 5
0
        public void WriteValuesToListItem_WhenGivenValueAndDescription_ShouldCopyValueAndDescription()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var actualFieldName = string.Empty;
                var expectedField   = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null);

                var actualUrlValue   = new SPFieldUrlValue();
                var expectedUrlValue = new UrlValue()
                {
                    Description = "Awesome sauce description!",
                    Url         = "http://www.gsoft.com/team"
                };

                var fakeListItemShim = new ShimSPListItem()
                {
                    ItemSetStringObject = (internalName, value) =>
                    {
                        actualUrlValue  = value as SPFieldUrlValue;
                        actualFieldName = internalName;
                    }
                };

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

                // Act
                writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, expectedUrlValue));

                // Assert
                Assert.AreEqual(expectedUrlValue.Url, actualUrlValue.Url);
                Assert.AreEqual(expectedUrlValue.Description, actualUrlValue.Description);
                Assert.AreEqual(expectedField.InternalName, actualFieldName);
            }
        }
Ejemplo n.º 6
0
        public void WriteValuesToListItem_WhenGiven5FieldValues_ShouldCallWriteValueToListItem5Times()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var actualCallCount   = 0;
                var expectedCallCount = 5;

                var fieldValueInfos = new List <FieldValueInfo>()
                {
                    new FieldValueInfo(BuiltInFields.Title, null),
                    new FieldValueInfo(BuiltInFields.Title, null),
                    new FieldValueInfo(BuiltInFields.Title, null),
                    new FieldValueInfo(BuiltInFields.Title, null),
                    new FieldValueInfo(BuiltInFields.Title, null)
                };

                ShimFieldValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (writerInst, listItemParam, fieldValuesParam) =>
                {
                    actualCallCount++;
                };

                var fakeListItem = new ShimSPListItem().Instance;

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

                // Act
                writer.WriteValuesToListItem(fakeListItem, fieldValueInfos);

                // Assert
                Assert.AreEqual(expectedCallCount, actualCallCount, string.Format("The call was made {0} out of {1} times.", actualCallCount, expectedCallCount));
            }
        }