public async Task AddMemeToCollectionAsync_Should_Pass() { // Arrange MemeDto expectedMemeDto = new MemeDto { Id = "a0Q558q", ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg", VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4", PageUrl = "http://9gag.com/gag/a0Q558q", Title = "Old but Gold" }; Meme entity = DtoToEntityConverter.Convert <Meme, MemeDto>(expectedMemeDto); Assert.IsTrue(await MemeRepository.CreateAsync(entity)); AddMemeToCollectionDto addMemeToCollectionDto = new AddMemeToCollectionDto { MemeId = "a0Q558q", UserId = 1, CollectionId = 1 }; // Act ServiceResponseDto addMemeToCollectionResultDto = await CollectionItemDetailService.AddMemeToCollectionAsync(addMemeToCollectionDto); // Assert Assert.IsTrue(addMemeToCollectionResultDto.Success); Assert.AreEqual(addMemeToCollectionResultDto.Message, "Successfully added meme to the collection."); CollectionItemDetail actualCollectionItemDetail = (await CollectionItemDetailRepository.GetAllAsync()).First(); Assert.IsTrue( actualCollectionItemDetail.MemeId.Equals("a0Q558q") && actualCollectionItemDetail.AddedByUserId.Equals(1) && actualCollectionItemDetail.CollectionId.Equals(1)); }
public async Task GetRandomMemeAsync_Should_Return_2_Unique_Memes() { // Arrange // in TestInitialize // Act MemeDto memeDto1 = await MemeService.GetRandomMemeAsync(); MemeDto memeDto2 = await MemeService.GetRandomMemeAsync(); // Assert Assert.AreNotEqual(memeDto1, memeDto2); }
public async Task <MemeDto> GetRandomMemeAsync() { MemeDto memeDto = await _memeFetcherService.GetRandomMemeAsync(); while (await _memeRepository.ExistsAsync(meme => meme.Id.Equals(memeDto.Id))) { memeDto = await _memeFetcherService.GetRandomMemeAsync(); } Meme actualMeme = DtoToEntityConverter.Convert <Meme, MemeDto>(memeDto); await _memeRepository.CreateAsync(actualMeme); return(memeDto); }
public IHttpActionResult Create(MemeDto memeDto) { if (!ModelState.IsValid) { return(BadRequest()); } var memeToDb = Mapper.Map <MemeDto, MemeModel>(memeDto); _context.MemeModels.Add(memeToDb); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + memeToDb.Id), memeDto)); }
public async Task <MemeDto> GetRandomMemeAsync() { while (true) { string memeAsJson = await GetAsync("RandomMeme.php"); MemeDto meme = JsonConvert.DeserializeObject <MemeDto>(memeAsJson, new MemeConverter()); meme.Id = meme.GetMemeIdFromUrl(); if (meme.Title == null) { continue; } return(meme); } }
public async Task <ActionResult> PostMeme([FromBody] MemeDto memeDto) { try { memeDto.CerationDate = DateTime.Now; var meme = _mapper.Map <Meme>(memeDto); await _memeService.CreateMemeAsync(meme); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IHttpActionResult Put(int id, MemeDto memeDto) { if (!ModelState.IsValid) { return(BadRequest()); } var memeInDb = _context.MemeModels.ToList().SingleOrDefault(m => m.Id == id); if (memeInDb == null) { return(NotFound()); } Mapper.Map(memeDto, memeInDb); _context.SaveChanges(); return(Ok()); }
/// <summary> /// button -> sending your new meme properties to a server /// </summary> public async void CreateByServer() { Bitmap bitmap = ImageHelper.BitmapImage2Bitmap(Image); MemeDto meme = new MemeDto("meme", TopText, BottomText, bitmap); meme.Key = client.Key; try { string response = await Task.Run(() => clientRequests.CreateRequest(meme)); MessageBox.Show("Server reponse: " + response); } catch (Exception) { MessageBox.Show("server not response"); } }
public async Task <IActionResult> MemeByIdAsync(string id) { if (string.IsNullOrWhiteSpace(id)) { return(NotFound()); } // TODO: fix try { MemeDto meme = await _memeService.GetMemeAsync(id); return(View("SharedMemeExpanded", meme)); } catch (Exception) { return(NotFound()); } }
public static Image GenerateMeme(MemeDto message) { string firstText = message.TopText; string secondText = message.BottomText; var image = message.Image; RectangleF TopSize = new RectangleF(new Point(0, 0), new SizeF(image.Width, image.Height / 8)); int y = (int)(image.Height * (7.0 / 8.0)); RectangleF BottomSize = new RectangleF(new Point(0, y), new SizeF(image.Width, image.Height / 8)); StringFormat format = new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; PutText(firstText, secondText, image, TopSize, BottomSize, format); // var path = AppDomain.CurrentDomain.BaseDirectory + "test.jpg"; //message.Image.Save(path); return(image); }
private static async Task<MemeDto> ExtractMemeFromMetaNodesAsync(IEnumerable<HtmlNode> collection) { MemeDto meme = new MemeDto(); foreach (HtmlNode htmlNode in collection) { string content = htmlNode.Attributes["content"].DeEntitizeValue; if (htmlNode.Attributes["property"].DeEntitizeValue == "og:title") meme.Title = content; else if (htmlNode.Attributes["property"].DeEntitizeValue == "og:url") meme.PageUrl = content; else if (htmlNode.Attributes["property"].DeEntitizeValue == "og:image") meme.ImageUrl = content; } meme.Id = meme.GetMemeIdFromUrl(); string videoUrl = NineGagPhotoCacheUrl + meme.Id + Mp4Tag; if (await HasVideoUrlAsync(videoUrl)) { meme.VideoUrl = videoUrl; } return meme; }
public async Task GetMemeAsync_With_Id_a0Q558q_Should_Return_MemeAsync() { // Arrange MemeDto expectedMemeDto = new MemeDto { Id = "a0Q558q", ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg", VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4", PageUrl = "http://9gag.com/gag/a0Q558q", Title = "Old but Gold" }; Meme entity = DtoToEntityConverter.Convert <Meme, MemeDto>(expectedMemeDto); Assert.IsTrue(await MemeRepository.CreateAsync(entity)); // Act MemeDto actualMemeDto = await MemeService.GetMemeAsync("a0Q558q"); // Assert Assert.AreEqual(expectedMemeDto, actualMemeDto); }
public async Task RemoveMemeFromCollectionAsync_Should_Throw_ApplicationUserIsNotAuthorizedException() { // Arrange MemeDto expectedMemeDto = new MemeDto { Id = "a0Q558q", ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg", VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4", PageUrl = "http://9gag.com/gag/a0Q558q", Title = "Old but Gold" }; Meme entity = DtoToEntityConverter.Convert <Meme, MemeDto>(expectedMemeDto); Assert.IsTrue(await MemeRepository.CreateAsync(entity)); AddMemeToCollectionDto addMemeToCollectionDto = new AddMemeToCollectionDto { MemeId = "a0Q558q", UserId = 1, CollectionId = 1 }; ServiceResponseDto addMemeToCollectionResultDto = await CollectionItemDetailService.AddMemeToCollectionAsync(addMemeToCollectionDto); Assert.IsTrue(addMemeToCollectionResultDto.Success); RemoveMemeFromCollectionDto removeMemeFromCollectionDto = new RemoveMemeFromCollectionDto { CollectionId = 1, CollectionItemDetailId = 1, UserId = 2 }; // Act & Assert ServiceResponseDto serviceResponseDto = await CollectionItemDetailService.RemoveMemeFromCollectionAsync(removeMemeFromCollectionDto); Assert.IsFalse(serviceResponseDto.Success); Assert.AreEqual(serviceResponseDto.Message, "Failed to remove meme because user is not authorized."); }
public async Task RemoveMemeFromCollectionAsync_Should_Pass() { // Arrange MemeDto expectedMemeDto = new MemeDto { Id = "a0Q558q", ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg", VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4", PageUrl = "http://9gag.com/gag/a0Q558q", Title = "Old but Gold" }; Meme entity = DtoToEntityConverter.Convert <Meme, MemeDto>(expectedMemeDto); Assert.IsTrue(await MemeRepository.CreateAsync(entity)); AddMemeToCollectionDto addMemeToCollectionDto = new AddMemeToCollectionDto { MemeId = "a0Q558q", UserId = 1, CollectionId = 1 }; ServiceResponseDto addMemeToCollectionResultDto = await CollectionItemDetailService.AddMemeToCollectionAsync(addMemeToCollectionDto); Assert.IsTrue(addMemeToCollectionResultDto.Success); RemoveMemeFromCollectionDto removeMemeFromCollectionDto = new RemoveMemeFromCollectionDto { CollectionId = 1, CollectionItemDetailId = 1, UserId = 1 }; // Act ServiceResponseDto serviceResponseDto = await CollectionItemDetailService.RemoveMemeFromCollectionAsync(removeMemeFromCollectionDto); // Assert Assert.IsTrue(serviceResponseDto.Success); List <CollectionItemDetail> collectionItemDetails = (await CollectionItemDetailRepository.GetAllAsync()).ToList(); Assert.AreEqual(collectionItemDetails.Count, 0); }
public async Task <IActionResult> MemeAsync() { MemeDto meme = await _memeService.GetRandomMemeAsync(); return(PartialView("Meme", meme)); }
internal static string GetMemeIdFromUrl(this MemeDto meme) { return(meme.PageUrl.Replace(NineGagGagUrl, "")); }
public string CreateRequest(MemeDto memeDto) { return(serverConnection? .SendReceiveObject <MemeDto, string> (PacketTypes.CreateMeme.Request, PacketTypes.CreateMeme.Response, 20000, memeDto)); }
public string CreateRequest(MemeDto memeDto) { throw new NotImplementedException(); }
/// <summary> /// Generete new meme by a server and add to a database /// </summary> public async void GenerateMemeRequest(PacketHeader header, Connection connection, MemeDto message) { var key = message.Key; var userId = dummyAuthentication.LoggedUsers[key]; var memeContent = MemeBuilder.GenerateMeme(message); Meme meme = new Meme() { Content = imageToByteArray(memeContent), CreatedDate = DateTime.Now, UserId = userId, Title = message.ImageName }; try { memeRepository.Add(meme); await memeRepository.SaveAsync(); connection.SendObject(PacketTypes.CreateMeme.Response, "Meme added."); } catch (Exception ex) { Console.WriteLine("\nError :( \nmessage: " + ex.Message); connection.SendObject(PacketTypes.CreateMeme.Response, "Error ocured."); } }