Exemplo n.º 1
0
        public int AddNewStudent(Student student)
        {
            int insertSuccess = 0;
            int maxId         = _context.Students.Max(p => p.sid);

            student.sid = (short)(maxId + 1);
            _context.Students.Add(student);
            insertSuccess = _context.SaveChanges();
            return(insertSuccess);
        }
Exemplo n.º 2
0
        public int AddNewCourse(Course course)
        {
            int insertSuccess = 0;
            int maxId         = _context.Records.Max(p => p.cid);

            course.cid = (short)(maxId + 1);
            _context.Courses.Add(course);
            insertSuccess = _context.SaveChanges();
            return(insertSuccess);
        }
Exemplo n.º 3
0
        // Better to use EntityState.Modified to update for unit testing
        public int UpdateActorById(int id, Record record)
        {
            int updateSuccess = 0;
            var target        = _context.Records.SingleOrDefault(a => a.rid == id);

            if (target != null)
            {
                _context.Entry(target).CurrentValues.SetValues(record);
                updateSuccess = _context.SaveChanges();
            }
            return(updateSuccess);
        }
        public void UpdateActorByIdEntityState_Should_Return_1_When_Actor_Exists_In_DB()
        {
            // Arrange
            int   id       = 1;
            Actor newActor = new Actor {
                ActorId = 1, FirstName = "Updated", LastName = "Actor", LastUpdate = DateTime.Now, FilmActor = new List <FilmActor>()
            };
            var counter = 0;

            // Act
            _mockSakilaContext.When(x => x.MarkAsModified(newActor)).Do(x => counter++);
            _mockSakilaContext.SaveChanges().Returns(1);
            int success = _actors.UpdateActorByIdEntityState(id, newActor);

            // Assert
            success.Should().Be(1);
        }