public void Test() { ArtistDataAccess _access = new ArtistDataAccess(mockContext.Object); Artist artist = new Artist { ArtistID = 999999, Name = "Test", Rating = 0.5f, Listens = 3, Description = "descript", WordVec = "1,2,3" }; _access.Create(999999, artist); mockSet.Verify(m => m.Add(It.IsAny <Artist>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); var artist2 = _access.Get(999999).First(); Assert.AreEqual(artist2.ArtistID, artist.ArtistID); Assert.AreEqual(artist2.Name, artist.Name); Assert.AreEqual(artist2.Rating, artist.Rating); Assert.AreEqual(artist2.Listens, artist.Listens); Assert.AreEqual(artist2.Description, artist.Description); Assert.AreEqual(artist2.WordVec, artist.WordVec); _access.Delete(999999); Assert.IsTrue(_access.Exists(999999)); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int id) { Artist.ArtistID = id; if (!ModelState.IsValid) { error = string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); error += id.ToString(); return(Page()); } Artist.Listens = 0; Artist.Rating = 1; Artist.WordVec = Vspace.ConvertToString(Vspace.Add(_textprocessor.PredictText(Artist.Name), _textprocessor.PredictText(Artist.Description))); await _access.Create(id, Artist); return(RedirectToPage("./Index")); }