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); }
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); }
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); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }