public TestScore Update(TestScore testScore) { var updatedTestScore = _dbContext.TestScores.Attach(testScore); _dbContext.Entry(testScore).State = EntityState.Modified; _dbContext.SaveChanges(); return updatedTestScore; }
public void CanCreate() { _testDatabase.RunAndRollback(dbContext => { var testScore = new TestScore { Score = 7.5M }; var createdTestScore = new TestScoreRepository(dbContext).Create(testScore); Assert.NotNull(createdTestScore); Assert.True(createdTestScore.Id > 0); Assert.Equal(testScore.Score, createdTestScore.Score); }); }
public void CanGet() { _testDatabase.RunAndRollback(dbContext => { var testScore1 = new TestScore { Score = 7.5M }; var testScore2 = new TestScore { Score = 8.5M }; dbContext.TestScores.Add(testScore1); dbContext.TestScores.Add(testScore2); dbContext.SaveChanges(); var testScore = new TestScoreRepository(dbContext).Get(testScore2.Id); Assert.NotNull(testScore); Assert.Equal(testScore2.Id, testScore.Id); }); }
public TestScore Create(TestScore testScore) { var createdTestScore = _dbContext.TestScores.Add(testScore); _dbContext.SaveChanges(); return createdTestScore; }
public void CanUpdate() { _testDatabase.RunAndRollback(dbContext => { var updatedScore = 9.5M; var testScore = new TestScore { Score = 7.5M }; dbContext.TestScores.Add(testScore); dbContext.SaveChanges(); testScore.Score = updatedScore; var updatedTestScore = new TestScoreRepository(dbContext).Update(testScore); Assert.NotNull(updatedTestScore); Assert.Equal(testScore.Id, updatedTestScore.Id); Assert.Equal(updatedScore, updatedTestScore.Score); }); }
public void CanDelete() { _testDatabase.RunAndRollback(dbContext => { var testScore1 = new TestScore { Score = 7.5M }; var testScore2 = new TestScore { Score = 8.5M }; dbContext.TestScores.Add(testScore1); dbContext.TestScores.Add(testScore2); dbContext.SaveChanges(); new TestScoreRepository(dbContext).Delete(testScore1.Id); Assert.Equal(1, dbContext.TestScores.Count()); Assert.Equal(testScore2.Id, dbContext.TestScores.First().Id); }); }