コード例 #1
0
        private void MethodGetByIdReturnsCorrectExercise()
        {
            _repository.Setup(repo => repo.GetById(1)).Returns(_exercise1);

            var actionResult = _service.GetById(1);

            Assert.Equal(_exerciseDTO1, actionResult);
        }
コード例 #2
0
        public void GetById_ShouldCallExercisesRepoAllPropertyOnce()
        {
            var exercisesRepoStub = new Mock <IEfRepostory <Exercise> >();
            var unitOfWorkStub    = new Mock <IUnitOfWork>();
            var dbSetStub         = new List <Exercise>().AsQueryable();
            var id = new Guid();

            var sut = new ExerciseService(exercisesRepoStub.Object, unitOfWorkStub.Object);

            exercisesRepoStub.Setup(x => x.All).Returns(dbSetStub);

            var result = sut.GetById(id);

            exercisesRepoStub.Verify(x => x.All, Times.Once);
        }
コード例 #3
0
        public void GetById_ShouldReturnCorrectEntryWhenIdMatchesThePasedId()
        {
            var exercisesRepoStub = new Mock <IEfRepostory <Exercise> >();
            var unitOfWorkStub    = new Mock <IUnitOfWork>();

            var list     = new List <Exercise>();
            var exercise = new Exercise();

            list.Add(exercise);

            var dbSetStub = list.AsQueryable();

            var sut = new ExerciseService(exercisesRepoStub.Object, unitOfWorkStub.Object);

            exercisesRepoStub.Setup(x => x.All).Returns(dbSetStub);

            var result = sut.GetById(exercise.Id);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <Exercise>(result);
            Assert.AreSame(result, exercise);
        }
コード例 #4
0
        public void GetById_ShouldReturnNullWhenNoEntryMatchesTheId()
        {
            var exercisesRepoStub = new Mock <IEfRepostory <Exercise> >();
            var unitOfWorkStub    = new Mock <IUnitOfWork>();

            var list     = new List <Exercise>();
            var exercise = new Exercise();

            list.Add(exercise);

            var dbSetStub = list.AsQueryable();

            var sut = new ExerciseService(exercisesRepoStub.Object, unitOfWorkStub.Object);

            exercisesRepoStub.Setup(x => x.All).Returns(dbSetStub);

            var newId = new Guid();

            var result = sut.GetById(newId);

            Assert.IsNull(result);
        }