public void UpdateSymptom(SymptomInputModel model) { SymptomName = model.SymptomName; //SymptomId = model.Id; Description = model.Description; UpdatedAt = model.UpdatedDate; }
public async Task UpdateSymptomReturnsUpdated() { Connection = new SqliteConnection("DataSource=../../../testdb.db3"); Opts = new DbContextOptionsBuilder <HealthTrackerContext>() .UseSqlite(Connection).Options; using (var db = new HealthTrackerContext(Opts)) { var service = new SymptomDataService(db); var inputmodel = new SymptomInputModel { SymptomName = "FirstSymptomUpdated", UpdatedDate = DateTimeOffset.UtcNow, Description = "I just Updated this", Id = "c89b00bd-289b-4b63-a4c5-46fe11e12f2c" }; //Act var result = await service.UpdateSymptom(inputmodel); //Assert Assert.IsTrue(result.SymptomName.Contains("Updated")); Assert.IsInstanceOf <SymptomApiModel>(result); } }
public async Task ItThrowsNullReferenceExceptionWhenInputModelFieldsAreEmpty() { var inputmodel = new SymptomInputModel(); Connection = new SqliteConnection("DataSource=../../../testdb.db3"); Opts = new DbContextOptionsBuilder <HealthTrackerContext>() .UseSqlite(Connection).Options; using (var db = new HealthTrackerContext(Opts)) { var service = new SymptomDataService(db); Assert.ThrowsAsync <NullReferenceException>(async() => await service.UpdateSymptom(inputmodel)); } }
public Task <SymptomApiModel> UpdateSymptom(SymptomInputModel model) { //if they are here then they deserve to be here try { var targetmodel = _db.Symptoms.Find(model.Id); targetmodel.UpdateSymptom(model); _db.Symptoms.Update(targetmodel); _db.SaveChangesAsync(); return(GetSymptomById(model.Id)); } catch (DbUpdateException ex) { throw; } catch (NullReferenceException ex) { throw; } }