예제 #1
0
        public void TestGetLinkedEntitiesWithEmptyValue()
        {
            // arrange
            var parser = new RelatedLinks2Parser();

            object propValue = null;

            // act
            var result = parser.GetLinkedEntities(propValue);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(0, entities.Count());
        }
예제 #2
0
        public void TestGetLinkedEntitiesWithValue()
        {
            // arrange
            var key = "6e79e3fc615c4e47bb7ba0115b8dfd87";

            var guid = Guid.Parse(key);

            var contentId = 1079;

            string propValue = $@"[
                      {{
                        ""caption"": ""External"",
                        ""link"": ""http://www.google.be"",
                        ""newWindow"": false,
                        ""edit"": false,
                        ""isInternal"": false,
                        ""type"": ""external"",
                        ""title"": ""External""
                      }},
                      {{
                        ""caption"": ""Internal page empty"",
                        ""link"": null,
                        ""newWindow"": false,
                        ""internal"": null,
                        ""edit"": false,
                        ""isInternal"": true,
                        ""internalName"": """",
                        ""type"": ""internal"",
                        ""title"": ""Internal page empty""
                      }},
                      {{
                        ""caption"": ""Internal page"",
                        ""link"": ""umb://document/{key}"",
                        ""newWindow"": false,
                        ""internal"": ""umb://document/{key}"",
                        ""edit"": false,
                        ""isInternal"": true,
                        ""internalName"": ""Contact"",
                        ""type"": ""internal"",
                        ""title"": ""Internal page""
                      }},
                      {{
                        ""caption"": ""Empty external"",
                        ""link"": ""http://"",
                        ""newWindow"": false,
                        ""edit"": false,
                        ""isInternal"": false,
                        ""type"": ""external"",
                        ""title"": ""Empty external""
                      }}
                    ]";

            var contentMock = new Mock <IContent>();

            contentMock.SetupGet(x => x.Id).Returns(contentId);

            var contentServiceMock = new Mock <IContentService>();

            contentServiceMock.Setup(x => x.GetById(guid)).Returns(contentMock.Object);

            var cacheProviderMock = new Mock <ICacheProvider>();

            cacheProviderMock.Setup(x => x.GetCacheItem(It.IsAny <string>(), It.IsAny <Func <object> >()))
            .Returns((string k, Func <object> action) => action());


            var parser = new RelatedLinks2Parser(contentServiceMock.Object, cacheProviderMock.Object);

            // act
            var result = parser.GetLinkedEntities(propValue);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(1, entities.Count());


            Assert.IsTrue(entities.Exists(x => x.LinkedEntityType == LinkedEntityType.Document && x.Id == contentId));
        }