public void Create_WithExistingUserJournalDiscoveryAndNotExistingTitle_ShouldAddPublication() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int discoveryId = 1; const int journalId = 1; const int publicationId = 1; const int authorId = 1; this.SeedJournal(db); this.SeedUser(db); this.SeedRole(db, WebConstants.ModeratorRole); this.AddUserToRole(db, authorId, WebConstants.ModeratorRole); this.SeedDiscovery(db, true); Publication expected = this.GetFakePublications().First(); expected.Views = 0; expected.ReleaseDate = DateTime.UtcNow; // Act publicationService.Create(expected.Title, expected.Content, discoveryId, journalId, authorId); Publication actual = db.Publications.Find(publicationId); // Assert this.ComparePublications(expected, actual); }
public void Create_WithRepeatingPublication_ShouldReturnNegativeId() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int discoveryId = 1; const int journalId = 1; const int authorId = 1; this.SeedJournal(db); this.SeedUser(db); this.SeedDiscovery(db, true); Publication publication = GetFakePublications().First(); publication.DiscoveryId = discoveryId; publication.JournalId = journalId; db.Publications.Add(publication); db.SaveChanges(); // Act int result = publicationService.Create(publication.Title, publication.Content, discoveryId, journalId, authorId); // Assert Assert.True(result <= 0); }
public void Create_WithExistingJournalUserDiscoveryAndNotExistingTitle_ShouldReturnPublicationId() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int discoveryId = 1; const int journalId = 1; const int publicationId = 1; const int authorId = 1; this.SeedJournal(db); this.SeedUser(db); this.SeedRole(db, WebConstants.ModeratorRole); this.AddUserToRole(db, authorId, WebConstants.ModeratorRole); this.SeedDiscovery(db, true); Publication publication = this.GetFakePublications().First(); // Act int actual = publicationService.Create(publication.Title, publication.Content, discoveryId, journalId, authorId); // Assert Assert.Equal(publicationId, actual); }
public ActionResult Create(PublicationViewModel publication, HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage != null) { _publicationService.Create(publication, uploadImage); return(RedirectToAction("Index")); } return(View(publication)); }
public void Create_WithNotExistingDiscovery_ShouldReturnNegativeId() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int discoveryId = 1; const int journalId = 1; const int authorId = 1; this.SeedUser(db); this.SeedJournal(db); Publication publication = this.GetFakePublications().First(); // Act int result = publicationService.Create(publication.Title, publication.Content, discoveryId, journalId, authorId); // Assert Assert.True(result <= 0); }
public IActionResult Post(GetPublicationView publication) { publicationService.Create(publication); return(Ok(publication)); }
public ActionResult <IPublication> Create(IPublication publication) { _publicationService.Create(publication); return(CreatedAtRoute("GetPublication", new { id = publication.Id.ToString() }, publication)); //return URI generated from this new publication }