Ejemplo n.º 1
0
        public void GetByName_ShouldReturnCorrectWorkoutInformationWhenNameIsFound()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var list       = new List <WorkoutInformation>();
            var workoutOne = new WorkoutInformation();

            workoutOne.Name = "gosho";
            var workoutTwo = new WorkoutInformation
            {
                Name = "pesho"
            };

            list.Add(workoutOne);
            list.Add(workoutTwo);

            var dbSetStub = list.AsQueryable();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

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

            var result = sut.GetByName("gosho");

            Assert.AreSame(result, workoutOne);
        }
Ejemplo n.º 2
0
        public void GetAllNames_ShouldReturnICollectionOfTwoStringsWhenTwoExercisesArePresentInTheRepo()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var list       = new List <WorkoutInformation>();
            var workoutOne = new WorkoutInformation();

            workoutOne.Name = "gosho";
            var workoutTwo = new WorkoutInformation
            {
                Name = "pesho"
            };

            list.Add(workoutOne);
            list.Add(workoutTwo);

            var dbSetStub = list.AsQueryable();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

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

            var result = sut.GetAllNames();

            Assert.AreEqual(2, result.Count);
        }
Ejemplo n.º 3
0
        public void Constructor_ShouldCreateCorrectServiceWhenAllParametersAreValid()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            Assert.IsInstanceOf <WorkoutInformationService>(sut);
        }
Ejemplo n.º 4
0
        public void GetByName_ShouldThrowWhenInvalidNameIsPassed()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            Assert.Throws <ArgumentException>(() => sut.GetByName(null));
        }
Ejemplo n.º 5
0
        public void InsertMultipleExercisesToWorkoutInformation_ShouldThrowWhenPassedWorkoutInformationAndExercisesAreInvalid()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.Update(It.IsAny <WorkoutInformation>()));
            unitOfWorkStub.Setup(x => x.Commit());

            Assert.Throws <ArgumentException>(() => sut.InsertMultipleExercisesToWorkoutInformation(null, null));
        }
Ejemplo n.º 6
0
        public void AddWorkoutInformation_ShouldThrowWhenInvalidWorkoutInformationIsPassed()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.Add(It.IsAny <WorkoutInformation>()));
            unitOfWorkStub.Setup(x => x.Commit());

            Assert.Throws <ArgumentException>(() => sut.AddWorkoutInformation(null));
        }
Ejemplo n.º 7
0
        public void GetAllNames_ShouldCallWorkoutInformationRepoAllPropertyOnce()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();
            var dbSetStub = new List <WorkoutInformation>().AsQueryable();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

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

            var result = sut.GetAllNames();

            workoutInformationRepoStub.Verify(x => x.All, Times.Once);
        }
Ejemplo n.º 8
0
        public void GetAll_ShouldReturnAnICollectionOfWorkoutInformation()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();
            var dbSetStub = new Mock <IList <WorkoutInformation> >().As <IQueryable <WorkoutInformation> >();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.All).Returns(dbSetStub.Object);

            var result = sut.GetAll();

            Assert.IsInstanceOf(typeof(ICollection <WorkoutInformation>), result);
        }
Ejemplo n.º 9
0
        public void AddWorkoutInformation_ShouldCallUnitOfWorkCommitOnce()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.Update(It.IsAny <WorkoutInformation>()));
            unitOfWorkStub.Setup(x => x.Commit());

            var workout = new WorkoutInformation();

            sut.AddWorkoutInformation(workout);

            unitOfWorkStub.Verify(x => x.Commit(), Times.Once);
        }
Ejemplo n.º 10
0
        public void GetAllNames_ShouldReturnICollectionOfStrings()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var list    = new List <WorkoutInformation>();
            var workout = new WorkoutInformation();

            workout.Name = "murph";
            list.Add(workout);

            var dbSetStub = list.AsQueryable();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

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

            var result = sut.GetAllNames();

            Assert.IsInstanceOf(typeof(ICollection <string>), result);
        }
Ejemplo n.º 11
0
        public void InsertMultipleExercisesToWorkoutInformation_CallCommitOnTheUnitOfWork()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.Update(It.IsAny <WorkoutInformation>()));
            unitOfWorkStub.Setup(x => x.Commit());

            var workout     = new WorkoutInformation();
            var exercises   = new List <Exercise>();
            var exerciseOne = new Exercise();
            var exerciseTwo = new Exercise();

            exercises.Add(exerciseOne);
            exercises.Add(exerciseTwo);

            sut.InsertMultipleExercisesToWorkoutInformation(workout, exercises);

            unitOfWorkStub.Verify(x => x.Commit(), Times.Once);
        }
Ejemplo n.º 12
0
        public void InsertMultipleExercisesToWorkoutInformation_ShouldInsertTwoExercisesInTheWorkoutWhenTheExercisesCollectionHasTwoElements()
        {
            var workoutInformationRepoStub = new Mock <IEfRepostory <WorkoutInformation> >();
            var unitOfWorkStub             = new Mock <IUnitOfWork>();

            var sut = new WorkoutInformationService(workoutInformationRepoStub.Object, unitOfWorkStub.Object);

            workoutInformationRepoStub.Setup(x => x.Update(It.IsAny <WorkoutInformation>()));
            unitOfWorkStub.Setup(x => x.Commit());

            var workout     = new WorkoutInformation();
            var exercises   = new List <Exercise>();
            var exerciseOne = new Exercise();
            var exerciseTwo = new Exercise();

            exercises.Add(exerciseOne);
            exercises.Add(exerciseTwo);

            sut.InsertMultipleExercisesToWorkoutInformation(workout, exercises);

            Assert.AreEqual(2, workout.Exercises.Count);
        }