public override async Task <ExerciseDto> Handle(Input request, CancellationToken cancellationToken) { Exercise exercise; if (request.Id == Guid.Empty) { exercise = ExerciseFactory.Create(request.Type); Context.Exercises.Add(exercise); } else { switch (request.Type) { case "fill": exercise = await Context.Exercises.OfType <FillTheBlanksExercise>() .Include(x => x.Sentences) .SingleOrDefaultAsync(x => x.Id == request.Id, cancellationToken); break; default: throw new Exception("Unrecognized exercise type"); } } Mapper.Map(request, exercise); await Context.SaveChangesAsync(cancellationToken); return(Mapper.Map <ExerciseDto>(exercise)); }
public void CreateAdvancedTest() { var exercise = ExerciseFactory.Create(RankLevel.Advanced, 1); Assert.AreEqual(RankLevel.Advanced, exercise.Rank); Assert.AreEqual(1, exercise.QuestionNumber); }
public void CreateExpertTest() { var exercise = ExerciseFactory.Create(RankLevel.Expert, 2); Assert.AreEqual(RankLevel.Expert, exercise.Rank); Assert.AreEqual(2, exercise.QuestionNumber); }
public void CreateIntermediateTest() { var exercise = ExerciseFactory.Create(RankLevel.Intermediate, 3); Assert.AreEqual(RankLevel.Intermediate, exercise.Rank); Assert.AreEqual(3, exercise.QuestionNumber); }
public void CreateTalentedTest() { var exercise = ExerciseFactory.Create(RankLevel.Talented, 2); Assert.AreEqual(RankLevel.Talented, exercise.Rank); Assert.AreEqual(2, exercise.QuestionNumber); }
public void CreateBeginnerTest() { var exercise = ExerciseFactory.Create(RankLevel.Beginner, 1); Assert.AreEqual(RankLevel.Beginner, exercise.Rank); Assert.AreEqual(1, exercise.QuestionNumber); }
public void CreateExercise_ReturnsNotFinishedExercise() { var fixture = new Fixture(); var words = fixture.CreateMany <Word>(); var userMock = new Mock <IUser>(); userMock.SetupGet(mock => mock.StudiedWords).Returns(new StudiedWord[0]); var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock .Setup(mock => mock.Load(It.IsAny <Guid>())) .Returns(userMock.Object); var wordRepositoryMock = new Mock <IWordsRepository>(); wordRepositoryMock.Setup(mock => mock.LoadAll()).Returns(words); var settings = new TranslationTrainerSettings(5, 3); var factory = new ExerciseFactory( userRepositoryMock.Object, wordRepositoryMock.Object, settings); var exercise = factory.Create(Guid.NewGuid()); Assert.IsFalse(exercise.Status.IsFinished); }
static void Main(string[] args) { Console.WriteLine("Exercises!"); // My goal here // I want to see all available exercises in the system // I select one specific exercise and see the basic information about it (description, parameters, example, test action) // Test action: executes the test with the provided parameters and returns the result // exercise.Execute var collection = new ServiceCollection(); collection.AddScoped <IExerciseRepository, ExerciseRepository>(); collection.AddScoped <IExerciseManager, ExerciseManager>(); collection.AddScoped <IParameter, ParameterValue>(); var serviceProvider = collection.BuildServiceProvider(); var manager = serviceProvider.GetService <IExerciseManager>(); var exercises = manager.GetAll(); foreach (var exercise in exercises) { Console.WriteLine(exercise.ToString()); } var arrayIntSumExercise = exercises.ElementAt(0); var exerciseInstance = ExerciseFactory.Create(arrayIntSumExercise.AssemblyName, arrayIntSumExercise.ParameterTypeEnum); var param = ParamFactory.CreateParameter("1 2 9 10", ParameterTypeEnum.ArrayInt); var expectedResult = new int[5] { 1, 2, 9, 1, 1 }; var result = exerciseInstance.Execute(param); if (result == expectedResult) { Console.WriteLine("Test: Ok"); } else { Console.WriteLine("Test: Failed"); } // My goal in future // I want to see all available exercises in the system // I select one specific exercise and see the basic information about it (description, parameters, example, submit code, see results) // Submit code action: system interprets the code (must have the same parameters), compiles and executes using unit tests (mock data) // See results action: system show results of unit tests (when they finish) Console.ReadLine(); }
public Exercise GetNextExercise(Exercise exercise) { if (exercise == null) { return(ExerciseFactory.Create(RankLevel.Beginner)); } if (PromoteToNextLevel(exercise.QuestionNumber)) { var currentRank = GetNextLevel(exercise.Rank); return(ExerciseFactory.Create(currentRank)); } return(ExerciseFactory.Create(exercise.Rank, exercise.QuestionNumber + 1)); }
static void ExecuteExerciseAsync(int exerciseCode) { IExercise Exercise; Exercise = ExerciseFactory.Create(exerciseCode); if (Exercise == null) { Console.WriteLine("Error 404! Exercise not found!"); } else { Exercise.Execute(); Console.WriteLine("Exercise successfully executed!"); } }
public ExerciseResult <T> ExecuteExercise <T>(string parameterValue, IExercise exercise) { // 1 - Instantiate the Exercise var execution = ExerciseFactory.Create(exercise.AssemblyName, exercise.ParameterTypeEnum); // 2 - Convert the provided parameter values to the respective parameter of the exercise var parameterValueConverted = ParamFactory.CreateParameter(parameterValue, exercise.ParameterTypeEnum); // 3 - Execute the exercise based on the parameter values var result = execution.Execute(parameterValueConverted); return(new ExerciseResult <T>() { Success = true, ResultValue = (T)result }); }
private void AddExercise(ExerciseType type, List <IdiomInCollection> idioms) { this.Exercises.Add(exerciseFactory.Create(type, idioms)); }
public Exercise GetFirstExercise() { return(ExerciseFactory.Create(RankLevel.Beginner)); }