예제 #1
0
        public async Task <ActionResult> UpdateForm(int id, string publishCode)
        {
            Haiku h = await base.GetByIdAsync <Haiku>(ControllerName, id);

            h.PublishCode = publishCode;
            return(this.View("UpdateForm", h));
        }
예제 #2
0
        /// <summary>
        /// This method will add a haiku to the database and return the saved haiku back
        /// </summary>
        /// <param name="haiku"></param>
        /// <returns></returns>
        public Haiku SaveHaiku(Haiku haiku)
        {
            var newHaiku = _dbContext.Haikus.Add(haiku);

            _dbContext.SaveChanges();
            return(_dbContext.Haikus.FirstOrDefault(h => h.HaikuId == haiku.HaikuId));
        }
예제 #3
0
        public void CanReadShouldReturnTrueIfTheSuppliedLinesAreAHaiku()
        {
            var hk = new Haiku();

            Assert.True(hk.CanRead("An old silent pond... A frog jumps into the pond, splash! Silence again"));
            Assert.False(hk.CanRead("An old silent pond... A frogernator jumps into the pond, splash! Silence again"));
        }
예제 #4
0
        public void ReadFromShouldReturnAHaikuFromInputText()
        {
            var hk = new Haiku();

            hk.ReadFrom(new StringReader("An old silent pond... A frog jumps into the pond, splash! Silence again"));
            Assert.AreEqual("An old silent pond...\r\nA frog jumps into the pond,\r\nsplash! Silence again\r\n",
                            hk.ToString());
        }
예제 #5
0
        public void Find()
        {
            IBaseRepository <Haiku> repo = InitializeRepo();

            Haiku haiku = repo.Get(_haikuId);

            haiku.Should().NotBeNull();
            haiku.Id.Should().NotBe(0);
            haiku.Text.Should().NotBeNull();
        }
예제 #6
0
        [Fact]//Haiku.cs
        public void HaikuIdTest()
        {
            Haiku h = new Haiku();

            h.HaikuId = 3;
            var expected = 3;
            var actual   = h.HaikuId;

            Assert.Equal(expected, actual);
        }
예제 #7
0
        /// <summary>
        /// Method will query the database for a haiku and then set the approval status
        /// to true then return the approval vaule
        /// </summary>
        /// <param name="hlid"></param>
        /// <returns></returns>
        public bool ApproveHaiku(int hlid)
        {
            Haiku haiku = _dbContext.Haikus.Where(h => h.HaikuId == hlid).FirstOrDefault();

            haiku.Approved = true;
            _dbContext.SaveChanges();
            bool haikuLineApproval = _dbContext.Haikus.Where(h => h.HaikuId == hlid).FirstOrDefault().Approved;

            return(haikuLineApproval);
        }
예제 #8
0
        [Fact]//Haiku.cs
        public void HaikuTagTest()
        {
            Haiku h = new Haiku();

            h.Tags = "Life Existential";
            var expected = "Life Existential";
            var actual   = h.Tags;

            Assert.Equal(expected, actual);
        }
예제 #9
0
        [Fact]//Haiku.cs
        public void HaikuApprovedTest()
        {
            Haiku h = new Haiku();

            h.Approved = false;
            var expected = false;
            var actual   = h.Approved;

            Assert.Equal(expected, actual);
        }
예제 #10
0
        [Fact]//Haiku.cs
        public void HaikuUsernameTest()
        {
            Haiku h = new Haiku();

            h.Username = "******";
            var expected = "AprilF";
            var actual   = h.Username;

            Assert.Equal(expected, actual);
        }
예제 #11
0
 public HaikuDTO(Haiku h)
 {
     this.Id           = h.Id;
     this.IsDeleted    = h.IsDeleted;
     this.Text         = h.Text;
     this.UserId       = h.UserId;
     this.ActualRating = h.ActualRating;
     this.Date         = h.Date;
     this.Username     = h.Username;
 }
예제 #12
0
        private void SetUpTestData()
        {
            _mockUser = new User()
            {
                IsVip       = false,
                PublishCode = "some test publish code",
                Username    = "******"
            };

            _mockUser  = DataManager.GetDataManager().CreateInstance <User>().Add(_mockUser);
            _mockHaiku = RandomDataGenerator.GenerateHaiku();
        }
예제 #13
0
        public async Task<ActionResult> Update(int id, string publishCode, Haiku entity)
        {
            entity.Date = DateTime.Now;

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("publishKey", publishCode);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                await httpClient.PutAsJsonAsync(string.Format(uriFormatBase, ControllerName), entity);
                return this.RedirectToAction("Details", ControllerName, new { entity.Id });
            }
        }
예제 #14
0
        [Fact]//Haiku.cs
        public void HaikuHaikuLineTest()
        {
            Haiku h = new Haiku();

            h.HaikuLine1 = "a";
            h.HaikuLine2 = "b";
            h.HaikuLine3 = "c";
            var expected = "abc";
            var actual   = h.HaikuLine1 + h.HaikuLine2 + h.HaikuLine3;

            Assert.Equal(expected, actual);
        }
예제 #15
0
        [Fact]//Haiku.cs
        public void HaikuUserTest()
        {
            Haiku h = new Haiku();
            User  u = new User();

            u.Username = "******";
            h.User     = u;
            var expected = "Dude";
            var actual   = h.User.Username;

            Assert.Equal(expected, actual);
        }
예제 #16
0
        public async Task <ActionResult> Update(int id, string publishCode, Haiku entity)
        {
            entity.Date = DateTime.Now;

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("publishKey", publishCode);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                await httpClient.PutAsJsonAsync(string.Format(uriFormatBase, ControllerName), entity);

                return(this.RedirectToAction("Details", ControllerName, new { entity.Id }));
            }
        }
예제 #17
0
    public static void Main()
    {
        var haiku = new Haiku(/*"words.txt"*/);

        //* Write out all 4 patterns
        haiku.Pattern1();
        Console.WriteLine();
        haiku.Pattern2();
        Console.WriteLine();
        haiku.Pattern3();
        Console.WriteLine();
        haiku.Pattern4();
    }
예제 #18
0
        [Fact]//Haiku.cs
        public void HaikuUserFavTest()
        {
            Haiku   h    = new Haiku();
            UserFav ufav = new UserFav();
            ICollection <UserFav> faves = new List <UserFav>();

            faves.Add(ufav);
            h.UserFavs = faves;
            var expected = true;
            var actual   = (h.UserFavs != null);

            Assert.Equal(expected, actual);
        }
예제 #19
0
        [Fact]//BusinessLogic.AddFavorite.cs
        public void AddFavoriteTest2()
        {
            Haiku haiku = new Haiku();
            User  user  = new User();

            user.Username = "******";
            haiku.HaikuId = 1;
            AddFavorite addFavorite = new AddFavorite(haiku, user);
            var         expected    = 1;
            var         actual      = addFavorite.FavoriteHaiku.Haiku.HaikuId;

            Assert.Equal(expected, actual);
        }
예제 #20
0
        public void Insert()
        {
            SetUpTestData();
            IBaseRepository <Haiku> repo = InitializeRepo();

            _mockHaiku = repo.Add(_mockHaiku, _mockUser.Id);



            _mockHaiku.Id.Should().NotBe(0);
            _mockHaiku.Text.Should().NotBeNull();
            _mockHaiku.RatersCount.Should().Be(0);
            _mockHaiku.RatingValue.Should().Be(0);
            _mockHaiku.ActualRating.Should().Be(0);
            _haikuId = (long)_mockHaiku.Id;
        }
예제 #21
0
        public ActionResult <Haiku> SubmitHaiku([FromBody] HaikuDTO haiku)
        {
            Haiku h = new Haiku
            {
                HaikuLine1 = haiku.haikuLine1,
                HaikuLine2 = haiku.haikuLine2,
                HaikuLine3 = haiku.haikuLine2,
                Tags       = haiku.tags,
                Approved   = false,
                Username   = haiku.username
            };

            Haiku newhaiku = _haikuMethod.SubmitHaiku(h);

            return(newhaiku);
        }
예제 #22
0
        public ActionResult <Boolean> SaveHaikuToFavorites([FromBody] SaveHaikuDTO haiku)
        {
            Haiku newhaiku = new Haiku {
                HaikuLine1 = haiku.haikuLine1,
                HaikuLine2 = haiku.haikuLine2,
                HaikuLine3 = haiku.haikuLine3,
                Tags       = haiku.tags,
                Approved   = true,
                Username   = haiku.username
            };

            string currentusername = haiku.currentuser;

            bool saveSuccessful = _haikuMethod.SaveHaikuToFavorites(currentusername, newhaiku);

            return(saveSuccessful);
        }
예제 #23
0
        [Fact]//UserFav.cs
        public void UserFavTest4()
        {
            string name = "JohnyAwesome123";
            User   user = new User();

            user.Username = name;
            Haiku haiku = new Haiku();

            haiku.HaikuId = 5;
            UserFav userFav = new UserFav();

            userFav.Haiku = haiku;
            var expected = 5;
            var actual   = userFav.Haiku.HaikuId;

            Assert.Equal(expected, actual);
        }
예제 #24
0
        [Fact]//User.cs
        public void UserHaikus2()
        {
            ICollection <Haiku> haikus = new List <Haiku>();
            Haiku haiku1 = new Haiku();
            Haiku haiku2 = new Haiku();

            haiku1.HaikuId = 1;
            haiku2.HaikuId = 2;
            haikus.Add(haiku1);
            haikus.Add(haiku2);
            User user = new User();

            user.Haikus = haikus;
            var expected = 2;
            var actual   = user.Haikus.ToList();

            Assert.Equal(expected, actual[1].HaikuId);
        }
예제 #25
0
        /// <summary>
        /// This method will query the database for a haiku by given haikuid and then delete it from the database
        /// /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public bool DeleteHaiku(int hid)
        {
            System.Console.Write("made it to repo");

            bool deletionSuccessful = false;

            Haiku haiku = _dbContext.Haikus.Where(h => h.HaikuId == hid).FirstOrDefault();

            _dbContext.Haikus.Remove(haiku);
            _dbContext.SaveChanges();
            haiku = _dbContext.Haikus.Where(h => h.HaikuId == hid).FirstOrDefault();

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

            return(deletionSuccessful);
        }
예제 #26
0
 static void Main(string[] args)
 {
     while (true)
     {
         Haiku haiku = new Haiku();
         foreach (Line line in haiku.Lines)
         {
             Console.WriteLine(line.ToString());
         }
         string tweetBody = haiku.Lines[0] + "; " + haiku.Lines[1] + "; " + haiku.Lines[2] + ".";
         Auth.SetUserCredentials(
             "CUSTOMER KEY GOES HERE",
             "CUSTOMER SECRET GOES HERE",
             "AUTHORIZATION KEY GOES HERE",
             "AUTHORIZATION SECRET GOES HERE"
             );
         Tweet.PublishTweet(tweetBody);
         Thread.Sleep(300000);
     }
 }
예제 #27
0
        /// <summary>
        /// Method will save a haiku to db under user's favorites
        /// </summary>
        /// <param name="username"></param>
        /// <param name="haiku"></param>
        /// <returns></returns>
        public bool AddToUserFavorites(string username, Haiku haiku)
        {
            bool addSuccesful = false;

            //add haiku to db
            Haiku   savedHaiku = SaveHaiku(haiku);
            UserFav userFav    = new UserFav();

            userFav.Username = username;
            userFav.Haiku    = haiku;
            _dbContext.UserFavs.Add(userFav);
            _dbContext.SaveChanges();

            userFav = _dbContext.UserFavs.Where(uf => uf.Username == username && uf.Haiku.HaikuId == savedHaiku.HaikuId).FirstOrDefault();
            if (userFav != null)
            {
                addSuccesful = true;
            }

            return(addSuccesful);
        }
예제 #28
0
 public AddFavorite(Haiku haiku, User user)
 {
     FavoriteHaiku       = new UserFav();
     FavoriteHaiku.User  = user;
     FavoriteHaiku.Haiku = haiku;
 }
예제 #29
0
        /// <summary>
        /// This method will pass a haiku to the repolyaer to be saved
        /// to the database
        /// </summary>
        /// <param name="h"></param>
        /// <returns></returns>
        public Haiku SubmitHaiku(Haiku h)
        {
            Haiku newhaiku = _repolayer.SaveHaiku(h);

            return(newhaiku);
        }
예제 #30
0
        /// <summary>
        /// This method will pass a haiku and username to add to user favorites
        /// </summary>
        /// <param name="username"></param>
        /// <param name="haiku"></param>
        /// <returns></returns>
        public bool SaveHaikuToFavorites(string username, Haiku haiku)
        {
            bool saveSuccessful = _repolayer.AddToUserFavorites(username, haiku);

            return(saveSuccessful);
        }
예제 #31
0
 public TagEditor(Haiku haiku, string newTag)
 {
     HaikuHolder = haiku;
     TagLine     = AddTag(haiku.Tags, newTag);
 }