public void Details_WithExistingId_ShouldReturnValidPublicationDetails() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int publicationId = 1; const int journalId = 1; const int discoveryId = 1; const int telescopeId = 1; const int authorId = 1; this.SeedJournal(db); this.SeedUser(db); Discovery discovery = new Discovery { Id = discoveryId, StarSystem = "Star System Name" }; Telescope telescope = new Telescope { Id = telescopeId, Name = "Telescope Name", Discoveries = new List <Discovery> { discovery } }; List <Publication> publications = this.GetFakePublications(); foreach (var publication in publications) { publication.DiscoveryId = discoveryId; publication.JournalId = journalId; publication.AuthorId = authorId; } db.Telescopes.Add(telescope); db.Publications.AddRange(publications); db.SaveChanges(); Publication expected = publications.First(); // Act PublicationDetailsServiceModel actual = publicationService.Details(publicationId); // Assert this.ComparePublications(expected, actual); }
public void Details_WithNotExistingId_ShouldReturnNull() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); const int journalId = 1; const int discoveryId = 1; const int telescopeId = 1; this.SeedJournal(db); Discovery discovery = new Discovery { Id = discoveryId }; Telescope telescope = new Telescope { Id = telescopeId, Discoveries = new List <Discovery> { discovery } }; List <Publication> publications = this.GetFakePublications(); foreach (var publication in publications) { publication.DiscoveryId = discoveryId; publication.JournalId = journalId; } db.Telescopes.Add(telescope); db.Publications.AddRange(publications); db.SaveChanges(); // Act PublicationDetailsServiceModel result = publicationService.Details(11); // Assert Assert.Null(result); }
public void Details_ShouldIncreaseViews() { // Arrange StarStuffDbContext db = this.Database; PublicationService publicationService = new PublicationService(db); this.SeedDatabase(db); const int publicationId = 1; int expected = 2; // Act publicationService.Details(publicationId); Publication publication = db.Publications.Find(publicationId); // Assert Assert.Equal(expected, publication.Views); }