Ejemplo n.º 1
0
 public TestScore Update(TestScore testScore)
 {
     var updatedTestScore = _dbContext.TestScores.Attach(testScore);
     _dbContext.Entry(testScore).State = EntityState.Modified;
     _dbContext.SaveChanges();
     return updatedTestScore;
 }
Ejemplo n.º 2
0
        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);
            });
        }
Ejemplo n.º 3
0
        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);
            });
        }
Ejemplo n.º 4
0
 public TestScore Create(TestScore testScore)
 {
     var createdTestScore = _dbContext.TestScores.Add(testScore);
     _dbContext.SaveChanges();
     return createdTestScore;
 }
Ejemplo n.º 5
0
        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);
            });
        }
Ejemplo n.º 6
0
        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);
            });
        }