public string Execute(IList <string> parameters) { var userId = this.userService.GetLoggedUserId(); var myPosts = postService.GetAllMyPosts(userId); return(postService.PrintPostsToConsole(myPosts)); }
public void Should_Return_The_Right_Collection() { var ContextMock = new AnimaniaConsoleContext(Effort.DbConnectionFactory.CreateTransient()); var LocationMock = new Mock <ILocationServices>(); var AnimalTypeMock = new Mock <IAnimalTypeServices>(); var BreedTypeMock = new Mock <IBreedTypeServices>(); postServices = new PostServices(ContextMock, LocationMock.Object, AnimalTypeMock.Object, BreedTypeMock.Object); User user = new User() { Id = 1, UserName = "******", Password = "******", Email = "*****@*****.**" }; BreedType breed = new BreedType() { BreedTypeName = "TestBreed", AnimalTypeId = 1 }; AnimalType type = new AnimalType() { AnimalTypeName = "TestAnimalTypeName", }; Location location = new Location() { LocationName = "TestLocation", }; var animal = new Animal { AnimalName = "TestAnimalTypeName", Birthday = DateTime.Now, AnimalTypeId = 1, BreedTypeId = 1, LocationId = 1, UserId = 1 }; var post = new CreatePostModel() { Title = "1234567890", Description = "12345678901234567890", Status = true, Price = 12.0M, LocationName = location.LocationName, AnimalTypeName = "TestAnimalTypeName", BreedTypeName = "TestBreed", AnimalName = "TestAnimalName", Birthday = DateTime.Now }; Assert.IsInstanceOfType(postServices.GetAllMyPosts(1), typeof(IEnumerable <PostModel>)); }
public string Execute(IList <string> parameters) { var userPosts = postServices.GetAllMyPosts(userService.GetLoggedUserId()); var random = new Random().Next(); string filePath = "../../../AnimaniaConsole.Core/PDFReports/"; string fileName = $"{random}.pdf"; FileStream fs = new FileStream(filePath + fileName, FileMode.Create); // Create an instance of the document class which represents the PDF document itself. Document document = new Document(PageSize.A4, 25, 25, 30, 30); // Create an instance to the PDF file by creating an instance of the PDF // Writer class using the document and the filestrem in the constructor. PdfWriter writer = PdfWriter.GetInstance(document, fs); document.AddSubject("This is a PDF showing current posts"); // Open the document to enable you to write to the document document.Open(); // Add a simple and wellknown phrase to the document in a flow layout manner document.Add(new Paragraph("Those are the current posts:")); foreach (var item in userPosts) { var date = item.PostDate.ToString(); string status = (item.Status) ? "ACTIVE" : "INACTIVE"; document.Add(new Paragraph((date))); document.Add(new Paragraph((status))); document.Add(new Paragraph(item.Title)); document.Add(new Paragraph(item.Description)); } // Close the document document.Close(); // Close the writer instance writer.Close(); // Always close open filehandles explicity fs.Close(); return($"PDF File has been created! You can find it in the following folder: {filePath}"); }