public void Init()
 {
     _MemeConfig = new MemeConfiguration();
     _MemeConfig.Add(new Meme("Success Kid", "", new[] {"sk", "successkid"}));
     _MemeConfig.Add(new Meme("I'll Have You Know", "", new[] {"ihyk", "illhaveyouknow"}));
     _MemeConfig.Add(new Meme("Foo", "", new[] { "f", "foo" }));
     _MemeConfig.Add(new Meme("All The Things", "", new[] { "att", "allthethings" }));
     _MemeConfig.Add(new Meme("Chubby Bubbles Girl", "", new[] {"cbg", "chubbybubblesgirl"}));
     _MemeConfig.Add(new Meme("Confession Bear", "", new[] {"cb", "confessionbear"}));
 }
Beispiel #2
0
        public static void AutoRegisterMemesByFile(MemeConfiguration memes, string[] filenames)
        {
            var usedAliases = new HashSet<string>();

            foreach (var filename in filenames.OrderBy(f => f))
            {
                var lowerFilename = filename.ToLowerInvariant();

                var name = Path.GetFileNameWithoutExtension(lowerFilename);

                if (name == null)
                {
                    throw new NullReferenceException("name cannot be null");
                }
                // strip off number prefix (used for ordering)
                name = name.Substring(lowerFilename.IndexOf("-", StringComparison.Ordinal) + 1);

                var extension = Path.GetExtension(lowerFilename);
                
                if (extension == null)
                {
                    throw new NullReferenceException("extension cannot be null");
                }
                extension = extension.Substring(1); // strip off the dot

                var aliases = new List<string>
                                  {
                                      name.ToInitialism(),
                                      NonWordStripCharacters.Replace(name, ""),
                                  };

                var memeName = name.ToTitleString();

                var filteredAliases =
                    aliases.Where(a => a.Length > 1) // don't use single character aliases
                           .Distinct()
                           .ToList();

                var survivingAliases = new List<string>();
                // Note: don't follow resharper's advice on this loop. It be cray cray
                foreach (var alias in filteredAliases)
                {
                    if (usedAliases.Add(alias))
                    {
                        survivingAliases.Add(alias);
                    }
                }

                // TODO: image/jpg isn't acutally valid. Fix this or get rid of it
                var imageType = "image/" + extension;

                memes.Add(new Meme(memeName, filename, survivingAliases, imageType));
            }
        }
        public void InitialismWithApostropheTest()
        {
            // arrange
            var filenames = new string[] { "01-I'll-have-you-know.png" };
            const string expectedAlias = "ihyk";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.IsTrue(meme.Aliases.Contains(expectedAlias));
        }
        public void InitialismMixedCaseTest()
        {
            // arrange
            var filenames = new string[] { "01-Success-Kid.png" };
            const string expectedAlias = "sk";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.IsTrue(meme.Aliases.Contains(expectedAlias));
        }
        public void InitialismOneWordTest()
        {
            // arrange
            var filenames = new string[] { "01-Fry.png" };
            const string expectedAlias = "fry"; // no single character aliases are allowed

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.IsTrue(meme.Aliases.Contains(expectedAlias));
        }
        public void NameWithJpgExtensionTest()
        {
            // arrange
            var filenames = new string[] { "100-file.jpg" };
            const string expectedDescription = "File";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.AreEqual(expectedDescription, meme.Description);
        }
        public void NameWithApostropheTest()
        {
            // arrange
            var filenames = new string[] { "100-I'll-have-you-know.png" };
            const string expectedDescription = "I'll Have You Know";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.AreEqual(expectedDescription, meme.Description);
        }
        public void TitleCaseTest()
        {
            // arrange
            var filenames = new string[] { "100-success-kid.png" };
            const string expectedDescription = "Success Kid";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.AreEqual(expectedDescription, meme.Description);
        }
Beispiel #9
0
        public static Meme FindMeme(MemeConfiguration memes, string memeName)
        {
            var sanitizedName = "";
            if (!String.IsNullOrEmpty(memeName))
            {
                sanitizedName = memeName.Replace("-", "");
            }

            if (string.IsNullOrEmpty(sanitizedName))
            {
                return null;
            }

            var meme = memes[sanitizedName]
                       ?? memes.GetMemes().FirstOrDefault(m => m.Aliases.Any(a => a.StartsWith(sanitizedName)))
                       ?? memes.GetMemes().FirstOrDefault(m => m.Aliases.Any(a => a.EndsWith(sanitizedName)))
                       ?? memes.GetMemes().FirstOrDefault(m => m.Aliases.Any(a => sanitizedName.StartsWith(a)))
                       ?? memes.GetMemes().FirstOrDefault(m => m.Aliases.Any(a => sanitizedName.EndsWith(a)));


            return meme;
        }
        public void InitialismWithSingleCharacterWordsTest()
        {
            // arrange
            var filenames = new string[] { "01-y-u-no.png" };
            const string expectedAlias = "yun";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.IsTrue(meme.Aliases.Contains(expectedAlias));
        }
        public void InitialismWithNumberPrefix()
        {
            // arrange
            var filenames = new string[] { "01-1950s-guy.png" };
            const string expectedAlias = "1950g";

            // act
            var memes = new MemeConfiguration();
            MemeConfig.AutoRegisterMemesByFile(memes, filenames);

            // assert
            Assert.AreEqual(1, memes.GetMemes().Count);
            var meme = memes.GetMemes()[0];

            Assert.IsTrue(meme.Aliases.Contains(expectedAlias));
        }
 static GlobalMemeConfiguration()
 {
     _memes = new MemeConfiguration();
 }
Beispiel #13
0
        public static void RegisterManualMemes(MemeConfiguration memes)
        {
            var batmanFontPath = HttpRuntime.AppDomainAppPath + @"Fonts\SFActionManExtended.ttf";
            PrivateFontCollection.AddFontFile(batmanFontPath);

            // overrides
            memes["10guy"].Aliases.Add("tenguy");
            memes["allthethings"].Aliases.Add("xallthey");
            memes["angrywalter"].Aliases.Add("amitheonlyone", "aitoo");
            memes["annoyedpicard"].Aliases.Add("whythefuck");
            memes["braceyourselves"].Aliases.Add("imminentned", "iscoming");
            memes["ermahgerd"].Aliases.Add("emg");
            memes["everyonelosestheirminds"].Aliases.Add("joker");
            memes["futuramafry"].Aliases.Add("notsureif");
            memes["grumpycat"].Aliases.Add("sadcat");
            memes["idontwanttoliveonthisplanetanymore"].Aliases.Add("farnsworth");
            memes["illhaveyouknow"].Aliases.Add("spongebob");
            memes["officespacelumbergh"].Aliases.Add("thatdbegreat", "yeah");
            memes["onedoesnotsimply"].Aliases.Add("boromir", "mordor");
            memes["schrutefacts"].Aliases.Add("schrute", "dwight", "correction", "false");
            memes["technologicallyimpairedduck"].Aliases.Add("technologyduck");
            memes["boythatescalatedquickly"].Aliases.Add("wteq", "ronburgundy");
            memes["themostinterestingmanintheworld"].Aliases.Add("idontalways");
            memes["toystoryeverywhere"].Aliases.Add("buzzwoody", "xxeverywhere");
            memes["unhelpfulhighschoolteacher"].Aliases.Add("scumbagteacher");
            memes["mckaylamaroneynotimpressed"].Aliases.Add("nim", "um", "unimpressedmckayla");

            var batman = memes["batmanslappingrobin"];
            foreach (var line in batman.Lines)
            {
                line.Font = "SF Action Man Extended";
                line.Fill = Color.FromArgb(255, 63, 63, 63);
                line.StrokeWidth = -1;
                line.FontStyle = FontStyle.Italic;
            }
            batman.Lines[0].Bounds = new Rectangle(10, 5, 180, 75);
            batman.Lines[1].Bounds = new Rectangle(220, 5, 170, 75);
            batman.Lines[1].HugBottom = false;

            var resharper = memes["resharpertip"];
            foreach (var line in resharper.Lines)
            {
                line.Font = "Segoe UI";
                line.TextAlignment = StringAlignment.Near;
                line.Fill = Color.WhiteSmoke;
                line.StrokeWidth = -1;
                line.DoForceTextToAllCaps = false;
            }
            resharper.Lines[0].Bounds = new Rectangle(78, 72, 481, 22);
            resharper.Lines[1].Bounds = new Rectangle(78, 97, 462, 22);
            resharper.Lines[1].HugBottom = false;

            var doge = memes["doge"];
            doge.Lines = Enumerable.Range(0, 6).Select(i => new LineConfig()).ToList();
            foreach (var line in doge.Lines)
            {
                line.Font = "Comic Sans MS";
                line.TextAlignment = StringAlignment.Near;
                line.StrokeWidth = -1;
                //line.FontStyle = FontStyle.Bold;
            }
            doge.Lines[0].Bounds = new Rectangle(30, 30, 400, 100);
            doge.Lines[0].Fill = Color.HotPink;
            doge.Lines[0].FontSize = 50;
            
            doge.Lines[1].Bounds = new Rectangle(20, 120, 550, 100);
            doge.Lines[1].TextAlignment = StringAlignment.Far;
            doge.Lines[1].Fill = Color.ForestGreen;
            doge.Lines[1].FontSize = 32;
            
            doge.Lines[2].Bounds = new Rectangle(50, 460, 400, 100);
            doge.Lines[2].Fill = Color.Yellow;
            doge.Lines[2].FontSize = 24;
            
            doge.Lines[3].Bounds = new Rectangle(20, 530, 580, 100);
            doge.Lines[3].TextAlignment = StringAlignment.Far;
            doge.Lines[3].Fill = Color.Blue;
            doge.Lines[3].FontSize = 20;

            doge.Lines[4].Bounds = new Rectangle(20, 350, 510, 100);
            doge.Lines[4].TextAlignment = StringAlignment.Far;
            doge.Lines[4].Fill = Color.Orange;
            doge.Lines[4].FontSize = 36;

            doge.Lines[5].Bounds = new Rectangle(20, 220, 560, 100);
            doge.Lines[5].TextAlignment = StringAlignment.Far;
            doge.Lines[5].Fill = Color.Red;
            doge.Lines[5].FontSize = 22;
        }
 static GlobalMemeConfiguration()
 {
     _memes = new MemeConfiguration();
 }