示例#1
0
        public void FindMemeNoMatchReturnsNull()
        {
            // arrange
            const string searchName = "blah";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNull(actualMeme);
        }
示例#2
0
        public void FindMemeLeadingWords()
        {
            // arrange
            const string searchName   = "illhave";
            const string expectedName = "I'll Have You Know";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNotNull(actualMeme);
            Assert.AreEqual(expectedName, actualMeme.Description);
        }
示例#3
0
        public void FindMemeByNameWithoutDashes()
        {
            // arrange
            const string searchName   = "successkid";
            const string expectedName = "Success Kid";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNotNull(actualMeme);
            Assert.AreEqual(expectedName, actualMeme.Description);
        }
示例#4
0
        public void FindConfessionBearByName()
        {
            // arrange
            const string searchName   = "confession-bear";
            const string expectedName = "Confession Bear";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNotNull(actualMeme);
            Assert.AreEqual(expectedName, actualMeme.Description);
        }
示例#5
0
        public void FindMemeSearchNameTrailsWithMemeName()
        {
            // arrange
            const string searchName   = "search-for-all-the-things";
            const string expectedName = "All The Things";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNotNull(actualMeme);
            Assert.AreEqual(expectedName, actualMeme.Description);
        }
示例#6
0
        public void FindMemeSearchNameLeadsWithMemeName()
        {
            // arrange
            const string searchName   = "ill-have-you-know-i-watched-the-notebook-and-only-cried-four-times";
            const string expectedName = "I'll Have You Know";

            // act
            var actualMeme = MemeUtilities.FindMeme(_MemeConfig, searchName);

            // assert
            Assert.IsNotNull(actualMeme);
            Assert.AreEqual(expectedName, actualMeme.Description);
        }
示例#7
0
        public ActionResult Builder()
        {
            var url         = Request.ServerVariables["HTTP_URL"];
            var memeRequest = MemeRequest.FromUrl(url, Server);

            var meme = MemeUtilities.FindMeme(GlobalMemeConfiguration.Memes, memeRequest.Name);


            int memeLineCount;

            if (meme == null)
            {
                memeRequest.Name  = "ihyk";
                memeRequest.Lines = new List <string>()
                {
                    "I'll have you know I tried other meme generators", "and only wasted hours and hours of my life"
                };
                memeLineCount = GlobalMemeConfiguration.Memes[memeRequest.Name].Lines.Count;
            }
            else
            {
                memeLineCount = meme.Lines.Count;
            }

            var lines = Enumerable.Range(0, memeLineCount)
                        .Select((item, index)
                                => memeRequest.Lines.Count > index
                        ? memeRequest.Lines[index]
                        : string.Empty).ToList();

            var viewModel = new BuilderViewModel
            {
                Memes        = GlobalMemeConfiguration.Memes.GetMemes(),
                SelectedMeme = memeRequest.Name,
                Lines        = lines
            };

            return(View(viewModel));
        }
示例#8
0
        public static MemeRequest FromUrl(string url, HttpServerUtilityBase serverUtility)
        {
            // decode any %-encodings
            url = serverUtility.UrlDecode(url) ?? "";

            // decode html entities, e.g. &gt;
            // Note: this would technically work for entites with a hash sign, e.g. &#39;, _but_
            // the browser doesn't send anything after the hash sign because it's part of the url
            // fragment...so we're sol when it comes to those
            url = WebUtility.HtmlDecode(url);

            // strip off any file extensions
            var isDebugMode = url.Contains("debugMode=true");

            url = _StripRegex.Replace(url, "");

            var memeRequest = MemeUtilities.GetMemeRequest(url);

            memeRequest.IsDebugMode = isDebugMode;

            return(memeRequest);
        }
示例#9
0
        public ActionResult Make()
        {
            var url         = Request.ServerVariables["HTTP_URL"];
            var memeRequest = MemeRequest.FromUrl(url, Server);
            var meme        = MemeUtilities.FindMeme(GlobalMemeConfiguration.Memes, memeRequest.Name);

            if (meme == null)
            {
                // TODO: update this flow to return a proper HTTP 404 code, too
                meme = GlobalMemeConfiguration.NotFoundMeme;
                memeRequest.Lines = new List <string> {
                    "404", "Y U NO USE VALID MEME NAME?"
                };
            }

            // if we want to do this earlier in the process consider
            // if we still need to worry about png vs. jpg. The browser
            // probably doesn't care, but it might be weird if the extension
            // doesn't match the mimetype
            var hasExtension = UrlExtension.IsMatch(url);

            if (!hasExtension)
            {
                return(Redirect(url + Path.GetExtension(meme.ImageFileName)));
            }

            var renderParameters = new RenderParameters
            {
                FullImagePath = HttpContext.Server.MapPath(meme.ImagePath),
                DebugMode     = memeRequest.IsDebugMode,
                FullWatermarkImageFilePath = HttpContext.Server.MapPath("~/Content/UpBoatWatermark.png"),
                WatermarkImageHeight       = 25,
                WatermarkImageWidth        = 25,
                WatermarkText        = "upboat.me",
                WatermarkFont        = "Arial",
                WatermarkFontStyle   = FontStyle.Regular,
                WatermarkFontSize    = 9,
                WatermarkStroke      = Color.Black,
                WatermarkFill        = Color.White,
                WatermarkStrokeWidth = 1,
                PrivateFonts         = MemeConfig.PrivateFontCollection,
                Lines = meme.Lines.Select(l => new LineParameters
                {
                    Bounds = l.Bounds,
                    DoForceTextToAllCaps = l.DoForceTextToAllCaps,
                    Fill          = l.Fill,
                    Font          = l.Font,
                    FontSize      = l.FontSize,
                    FontStyle     = l.FontStyle,
                    HeightPercent = l.HeightPercent,
                    Stroke        = l.Stroke,
                    StrokeWidth   = l.StrokeWidth,
                    TextAlignment = l.TextAlignment,
                    HugBottom     = l.HugBottom
                }).ToList()
            };

            for (var x = 0; x < renderParameters.Lines.Count; x++)
            {
                if (x < memeRequest.Lines.Count)
                {
                    renderParameters.Lines[x].Text = memeRequest.Lines[x].SanitizeMemeText(renderParameters.Lines[x].DoForceTextToAllCaps);
                }
            }

            var renderer = new Renderer();

            var bytes = renderer.Render(renderParameters);

            Analytics.TrackMeme(HttpContext, memeRequest.Name);

            return(new FileContentResult(bytes, meme.ImageType));
        }