Example #1
0
        /// <summary>
        /// This method will add a haiku line to the database and then return the
        /// newly create haiku line back
        /// </summary>
        /// <param name="haikuline"></param>
        /// <returns></returns>
        public HaikuLine SaveLine(HaikuLine haikuline)
        {
            var newLine = _dbContext.HaikuLines.Add(haikuline);//add the new line to the database

            _dbContext.SaveChanges();
            return(_dbContext.HaikuLines.FirstOrDefault(h => h.HaikuLineId == haikuline.HaikuLineId));
        }
Example #2
0
        [Fact]//Repository.HaikuRepo.cs
        public void HaikuRepoTest1()
        {
            HaikuRepo haikurepo = new HaikuRepo(hContext);
            HaikuLine haikuline = new HaikuLine();

            haikuline.Line     = "Coffee is my life";
            haikuline.Tags     = "coffee life silly";
            haikuline.Syllable = 5;
            haikuline.Approved = false;
            haikuline.Username = "******";
            RawUser rawuser = new RawUser();

            rawuser.Username  = "******";
            rawuser.FirstName = "Chris";
            rawuser.LastName  = "Larson";
            rawuser.Password  = "******";
            UserRepo    userrepo    = new UserRepo(hContext);
            UserMethods usermethods = new UserMethods(userrepo);
            User        user        = usermethods.UserRegister(rawuser);

            haikuline.User = user;
            var actual   = haikurepo.SaveLine(haikuline).Username;
            var expected = "Chris123";

            Assert.Equal(expected, actual);
        }
Example #3
0
        [Fact]//Repository.HaikuRepo.cs
        public void HaikuRepoTest3()
        {
            HaikuRepo haikurepo = new HaikuRepo(hContext);
            HaikuLine haikuline = new HaikuLine();

            haikuline.Line     = "I can not live without it";
            haikuline.Tags     = "life silly";
            haikuline.Syllable = 7;
            haikuline.Approved = true;
            haikuline.Username = "******";
            RawUser rawuser = new RawUser();

            rawuser.Username  = "******";
            rawuser.FirstName = "Chris";
            rawuser.LastName  = "Larson";
            rawuser.Password  = "******";
            UserRepo    userrepo    = new UserRepo(hContext);
            UserMethods usermethods = new UserMethods(userrepo);
            User        user        = usermethods.GetUser(rawuser.Username);

            haikuline.User = user;
            var actual   = haikurepo.SaveLine(haikuline).Username;
            var expected = "Chris123";

            Assert.Equal(expected, actual);
        }
Example #4
0
        [Fact]//Repository.HaikuRepo.cs
        public void HaikuRepoTest8()
        {
            HaikuRepo haikurepo = new HaikuRepo(hContext);
            HaikuLine haikuline = haikurepo.GetHaiku5();
            var       expected  = 5;
            var       actual    = haikuline.Syllable;

            Assert.Equal(expected, actual);
        }
Example #5
0
        [Fact]//Haiku.cs
        public void HaikuTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.Username = "******";
            var expected = "DavidP";
            var actual   = hl.Username;

            Assert.Equal(expected, actual);
        }
Example #6
0
        [Fact]//HaikuLine.cs
        public void HaikuLineIdTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.HaikuLineId = 1;
            var expected = 1;
            var actual   = hl.HaikuLineId;

            Assert.Equal(expected, actual);
        }
Example #7
0
        [Fact]//HaikuLine.cs
        public void HaikuLineSyllableTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.Syllable = 5;
            var expected = 5;
            var actual   = hl.Syllable;

            Assert.Equal(expected, actual);
        }
Example #8
0
        /// <summary>
        /// Method that will query the database for the haiku line that matches the id sent
        /// Then will change the approval status to true and send back the haiku's approval status
        /// </summary>
        /// <param name="hlid"></param>
        /// <returns></returns>
        public bool ApproveHaikuLine(int hlid)
        {
            HaikuLine haikuLine = _dbContext.HaikuLines.Where(hl => hl.HaikuLineId == hlid).FirstOrDefault();

            haikuLine.Approved = true;
            _dbContext.SaveChanges();
            bool haikuLineApproval = _dbContext.HaikuLines.Where(h1 => h1.HaikuLineId == hlid).FirstOrDefault().Approved;

            return(haikuLineApproval);
        }
Example #9
0
        [Fact]//HaikuLine.cs
        public void HaikuLineTagsTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.Tags = "Comedy Dark Satirical";
            var expected = "Comedy Dark Satirical";
            var actual   = hl.Tags;

            Assert.Equal(expected, actual);
        }
Example #10
0
        [Fact]//HaikuLine.cs
        public void HaikuLineLineTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.Line = "A storm is coming";
            var expected = "A storm is coming";
            var actual   = hl.Line;

            Assert.Equal(expected, actual);
        }
Example #11
0
        [Fact]//HaikuLine.cs
        public void HaikuLineApprovedTest()
        {
            HaikuLine hl = new HaikuLine();

            hl.Approved = true;
            var expected = true;
            var actual   = hl.Approved;

            Assert.Equal(expected, actual);
        }
Example #12
0
        [Fact]//HaikuLine.cs
        public void HaikuLineUserTest()
        {
            HaikuLine hl   = new HaikuLine();
            User      user = new User();

            user.Username = "******";
            hl.User       = user;
            var expected = "DavidP";
            var actual   = hl.User.Username;

            Assert.Equal(expected, actual);
        }
Example #13
0
        /// <summary>
        /// This method will get tags from three lines and combine them into one
        /// ta string
        /// </summary>
        /// <param name="hl"></param>
        /// <param name="hl2"></param>
        /// <param name="hl3"></param>
        /// <returns></returns>
        public string GetTags(HaikuLine hl, HaikuLine hl2, HaikuLine hl3)
        {
            List <string> tagholder       = CombineTags(hl, hl2, hl3);
            List <string> uniquetagholder = tagholder.Distinct().ToList();
            string        tags            = "";

            //compare tags
            foreach (string tag in uniquetagholder)
            {
                tags += tag + " ";
            }
            tags = tags.Trim();
            return(tags);
        }
Example #14
0
        public ActionResult <HaikuLine> SubmitHaikuLine([FromBody] RawHaikuLine haikuLine)
        {
            HaikuLine hl = new HaikuLine
            {
                Line     = haikuLine.line,
                Tags     = haikuLine.tags,
                Syllable = haikuLine.syllable,
                Approved = false,
                Username = haikuLine.username
            };

            HaikuLine newline = _haikuMethod.SubmitHaikuLine(hl);

            return(newline);
        }
Example #15
0
        /// <summary>
        /// This method will query the database for the haiku line by given id and then delete it from the
        /// database. If the operation was successful, return true
        /// </summary>
        /// <param name="hlid"></param>
        /// <returns></returns>
        public bool DeleteHaikuLine(int hlid)
        {
            bool deletionSuccessful = false;

            HaikuLine haikuLine = _dbContext.HaikuLines.Where(hl => hl.HaikuLineId == hlid).FirstOrDefault();

            _dbContext.HaikuLines.Remove(haikuLine);
            _dbContext.SaveChanges();
            haikuLine = _dbContext.HaikuLines.Where(hl => hl.HaikuLineId == hlid).FirstOrDefault();

            if (haikuLine == null)
            {
                deletionSuccessful = true;
            }

            return(deletionSuccessful);
        }
Example #16
0
        [Fact]//User.cs
        public void UserHaikuLines2()
        {
            ICollection <HaikuLine> haikulines = new List <HaikuLine>();
            HaikuLine hline1 = new HaikuLine();
            HaikuLine hline2 = new HaikuLine();

            hline1.HaikuLineId = 1;
            hline2.HaikuLineId = 2;
            haikulines.Add(hline1);
            haikulines.Add(hline2);
            User user = new User();

            user.HaikuLines = haikulines;
            var expected            = 2;
            List <HaikuLine> actual = user.HaikuLines.ToList();

            Assert.Equal(expected, actual[1].HaikuLineId);
        }
Example #17
0
        /// <summary>
        /// This method will compare the usernames of each line and return a username string
        /// of combines usernames
        /// </summary>
        /// <param name="hl"></param>
        /// <param name="hl2"></param>
        /// <param name="hl3"></param>
        /// <returns></returns>
        public static string GetUsername(HaikuLine hl, HaikuLine hl2, HaikuLine hl3)
        {
            string username  = "";
            string username1 = hl.Username;
            string username2 = hl2.Username;
            string username3 = hl3.Username;

            username = username1;
            if (!username1.Equals(username2))
            {
                username += " " + username2;
            }
            if (!username3.Equals(username1) && !username3.Equals(username2))
            {
                username += " " + username3;
            }

            return(username);
        }
Example #18
0
        /// <summary>
        /// This method will check to see if the haiku line that is retrieved from the database is different from the haiku line
        /// that was give, if it is the same, it will query the db for another line and check again. If it is different it will return the line
        /// </summary>
        /// <param name="alreadyUsed"></param>
        /// <returns></returns>
        public HaikuLine GetHaiku5(HaikuLine alreadyUsed)
        {
            //get haiku line from DB
            HaikuLine newHaikuLine = GetHaiku5();

            //If the haikuline is not the same as the first line, return
            if (newHaikuLine != alreadyUsed)
            {
                return(newHaikuLine); //Passes the new haiku line to the caller
            }
            else
            {
                //If the lines are the same, recursively call the method again
                // It will check if the new line recieved is the same or not
                // It will call the method again if they are the same again
                // It will return here, if they are not the same.
                return(GetHaiku5(alreadyUsed));
            }
        }
Example #19
0
        [Fact]//HaikuGenerator.cs
        public void HaikuGeneratorTest1()
        {
            HaikuRepo      haikurepo = new HaikuRepo(hContext);
            HaikuGenerator haikugen  = new HaikuGenerator(haikurepo);
            HaikuLine      line1     = new HaikuLine();
            HaikuLine      line2     = new HaikuLine();
            HaikuLine      line3     = new HaikuLine();

            line1.Line     = "Coffee is my life";
            line2.Line     = "I can not live without it";
            line3.Line     = "Sleep is for the weak";
            haikugen.Line1 = line1;
            haikugen.Line2 = line2;
            haikugen.Line3 = line3;
            var expected = "Coffee is my life I can not live without it Sleep is for the weak";
            var actual   = haikugen.Line1.Line + " " +
                           haikugen.Line2.Line + " " +
                           haikugen.Line3.Line;

            Assert.Equal(expected, actual);
        }
Example #20
0
        /// <summary>
        /// This method will take string arrays of haiku tags and combine them
        /// into one array
        /// </summary>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <param name="t3"></param>
        /// <returns></returns>
        public List <string> CombineTags(HaikuLine hl, HaikuLine hl2, HaikuLine hl3)
        {
            // New List to hold tags
            List <string> tags = new List <string>();

            // Split tag string from eahc haiku
            string[] t1 = SplitTags(hl);
            string[] t2 = SplitTags(hl2);
            string[] t3 = SplitTags(hl3);

            foreach (string tag in t1)
            {
                tags.Add(tag);
            }
            foreach (string tag in t2)
            {
                tags.Add(tag);
            }
            foreach (string tag in t3)
            {
                tags.Add(tag);
            }
            return(tags);
        }
Example #21
0
 public TagEditor(HaikuLine haikuline, string newTag)
 {
     HaikuLineHolder = haikuline;
     TagLine         = AddTag(HaikuLineHolder.Tags, newTag);
 }
Example #22
0
 public void MakeHaiku()
 {
     Line1 = _repo.GetHaiku5();
     Line2 = _repo.GetHaiku7();
     Line3 = _repo.GetHaiku5(Line1);
 }
Example #23
0
 /// <summary>
 /// This method will take a haikuline and then split the tags by space
 /// It will return a string array of tags
 /// </summary>
 /// <param name="hl"></param>
 /// <returns></returns>
 public static string[] SplitTags(HaikuLine hl)
 {
     string[] tags = hl.Tags.Split(' ');
     return(tags);
 }
Example #24
0
        /// <summary>
        /// Method will pass a haiku line to the repolayer so a haiku line
        /// that was submitted can be saved to the db and later be reviewed by
        /// an admin user
        /// </summary>
        /// <param name="hl"></param>
        /// <returns></returns>
        public HaikuLine SubmitHaikuLine(HaikuLine hl)
        {
            HaikuLine newline = _repolayer.SaveLine(hl);

            return(newline);
        }
Example #25
0
        /// <summary>
        /// Will query the database for a haiku line based on given haiku id
        /// </summary>
        /// <param name="hlid"></param>
        /// <returns></returns>
        public HaikuLine GetHaikuLine(int hlid)
        {
            HaikuLine hl = _dbContext.HaikuLines.Where(h => h.HaikuLineId == hlid).FirstOrDefault();

            return(hl);
        }