Beispiel #1
0
        public void RenderMetaTags_NoValueForSiteUsername_ExceptionThrown()
        {
            var tagHelper = new TwitterCardApp()
            {
                SiteUsername = string.Empty,
                IPhone       = "307234931",
                IPad         = "307234931",
                GooglePlay   = "com.android.app",
            };
            var context = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
            var output = new TagHelperOutput(
                "meta",
                new TagHelperAttributeList(),
                (cache, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var validationException = Assert.Throws <ValidationException>(() => tagHelper.Process(context, output));

            Assert.Contains(nameof(TwitterCardApp.SiteUsername), validationException.Message, StringComparison.Ordinal);
        }
Beispiel #2
0
        public void RenderMetaTags_RenderedCorrectTwitterCardTypeTag_Match()
        {
            var tagHelper = new TwitterCardApp()
            {
                SiteUsername = TwitterCardAnswerKey.SiteUsernameValue,
                IPhone       = "307234931",
                IPad         = "307234931",
                GooglePlay   = "com.android.app"
            };

            var context = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N"));

            var output = new TagHelperOutput(
                "meta",
                new TagHelperAttributeList(),
                (cache, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            tagHelper.Process(context, output);
            Assert.Contains("name=\"twitter:card\" content=\"app\"", output.Content.GetContent());
        }
Beispiel #3
0
        public void RenderMetaTags_NoValueForGooglePlay_ExceptionThrown()
        {
            var tagHelper = new TwitterCardApp()
            {
                SiteUsername = TwitterCardAnswerKey.SiteUsernameValue,
                IPhone       = "307234931",
                IPad         = "307234931",
                GooglePlay   = string.Empty
            };
            var context = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N"));
            var output = new TagHelperOutput(
                "meta",
                new TagHelperAttributeList(),
                (cache, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var validationException = Assert.Throws <ValidationException>(() => tagHelper.Process(context, output));

            Assert.Contains(nameof(TwitterCardApp.GooglePlay), validationException.Message);
        }
Beispiel #4
0
        public void RenderMetaTags_NoValueForIPad_ExceptionThrown()
        {
            var       expected        = typeof(System.ArgumentNullException);
            Exception thrownException = null;

            var tagHelper = new TwitterCardApp()
            {
                SiteUsername = TwitterCardAnswerKey.SiteUsernameValue,
                IPhone       = "307234931",
                IPad         = string.Empty,
                GooglePlay   = "com.android.app"
            };

            try
            {
                var context = new TagHelperContext(
                    new TagHelperAttributeList(),
                    new Dictionary <object, object>(),
                    Guid.NewGuid().ToString("N"));

                var output = new TagHelperOutput(
                    "meta",
                    new TagHelperAttributeList(),
                    (cache, encoder) =>
                {
                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.SetContent(string.Empty);
                    return(Task.FromResult <TagHelperContent>(tagHelperContent));
                });

                tagHelper.Process(context, output);
            }
            catch (Exception e)
            {
                thrownException = e;
            }

            Assert.Equal(expected, thrownException.GetType());
            Assert.Equal("IPad", ((System.ArgumentException)thrownException).ParamName.ToString());
        }