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)); }
/// <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)); }
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")); }
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()); }
public void Find() { IBaseRepository <Haiku> repo = InitializeRepo(); Haiku haiku = repo.Get(_haikuId); haiku.Should().NotBeNull(); haiku.Id.Should().NotBe(0); haiku.Text.Should().NotBeNull(); }
[Fact]//Haiku.cs public void HaikuIdTest() { Haiku h = new Haiku(); h.HaikuId = 3; var expected = 3; var actual = h.HaikuId; Assert.Equal(expected, actual); }
/// <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); }
[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); }
[Fact]//Haiku.cs public void HaikuApprovedTest() { Haiku h = new Haiku(); h.Approved = false; var expected = false; var actual = h.Approved; Assert.Equal(expected, actual); }
[Fact]//Haiku.cs public void HaikuUsernameTest() { Haiku h = new Haiku(); h.Username = "******"; var expected = "AprilF"; var actual = h.Username; Assert.Equal(expected, actual); }
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; }
private void SetUpTestData() { _mockUser = new User() { IsVip = false, PublishCode = "some test publish code", Username = "******" }; _mockUser = DataManager.GetDataManager().CreateInstance <User>().Add(_mockUser); _mockHaiku = RandomDataGenerator.GenerateHaiku(); }
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 }); } }
[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); }
[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); }
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 })); } }
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(); }
[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); }
[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); }
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; }
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); }
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); }
[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); }
[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); }
/// <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); }
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); } }
/// <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); }
public AddFavorite(Haiku haiku, User user) { FavoriteHaiku = new UserFav(); FavoriteHaiku.User = user; FavoriteHaiku.Haiku = haiku; }
/// <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); }
/// <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); }
public TagEditor(Haiku haiku, string newTag) { HaikuHolder = haiku; TagLine = AddTag(haiku.Tags, newTag); }