public async Task Get_Lesson_With_A_Valid_Exercise(Mock <IAuthorizationService> authorizationService, IStateService stateService, Lesson lesson, Lesson invalidLesson, User user)
        {
            authorizationService.Setup(x => x.HasWriteAccess(user, It.IsAny <Lesson>(), It.IsAny <CancellationToken>())).ReturnsAsync(false);

            lesson.Exercises.First().Questions.First().Answers.First().Valid = true;

            invalidLesson.Exercises.First().Questions.First().Answers.ForEach(x => x.Valid = false);

            var context     = TestSetup.SetupContext();
            var httpContext = TestSetup.SetupHttpContext().SetupSession(user);

            await context.Lessons.AddAsync(lesson);

            await context.Lessons.AddAsync(invalidLesson);

            await context.SaveChangesAsync();

            var service = new LessonService(context, httpContext, authorizationService.Object, stateService);
            var result  = await service.Get(lesson.Id);

            var invalidResult = await service.Get(invalidLesson.Id);

            result.Should().NotBeNull().And.BeEquivalentTo(lesson);
            invalidResult.Should().BeNull();
        }
Beispiel #2
0
 public ActionResult <List <LessonQ> > Get(LessonQ lesson)
 {
     try
     {
         var response = service.Get(lesson);
         if (response == null)
         {
             return(NotFound());
         }
         return(response);
     }
     catch (Exception e)
     {
         return(Content(e.Message));
     }
 }
Beispiel #3
0
        public ActionResult Index()
        {
            // Fetch the lesson from the Typsy API
            Lesson lesson = LessonService.Get(100);

            string timestamp            = DateTime.UtcNow.ToString("O");
            string encryptedKeyTemplate = $"{TYPSY_KEY}:{timestamp}";
            string encryptedKey         = EncryptionHelper.CreateHmacSha256(encryptedKeyTemplate, TYPSY_KEY);

            // INSERT LOGIC TO LOOKUP THE EMAIL ADDRESS OF THE USER ACCESSING THE PAGE
            string email     = "*****@*****.**";
            string firstname = "Bob";
            string lastname  = "Smith";

            var referrer = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.Path}{this.Request.QueryString}";

            PlayerViewModel viewModel = new PlayerViewModel();

            viewModel.ApiEndpoint  = "https://api.typsy.com";
            viewModel.Lesson       = lesson;
            viewModel.AccountId    = TYPSY_ACCOUNT_ID;
            viewModel.EncryptedKey = encryptedKey;
            viewModel.Source       = TYPSY_SOURCE;
            viewModel.Referrer     = referrer;
            viewModel.Timestamp    = timestamp;
            viewModel.Email        = email;
            viewModel.Firstname    = firstname;
            viewModel.Lastname     = lastname;

            return(View(viewModel));
        }
        public async Task Get_Single_Lesson_Or_Null(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target)
        {
            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddRangeAsync(entities);

            await context.Lessons.AddAsync(target);

            await context.SaveChangesAsync();

            var result = await service.Get(target.Id);

            var invalidResult = await service.Get(Guid.Empty);

            result.Should().NotBeNull().And.BeEquivalentTo(target);
            invalidResult.Should().BeNull();
        }
        // GET: api/lesson/5
        public LessonViewModel Get(int id)
        {
            LessonViewModel group = new LessonViewModel();

            using (ILessonService ls = new LessonService(WebApiApplication.connection))
            {
                group = Mapper.Map <LessonViewModel>(ls.Get(id));
            }
            return(group);
        }
        // DELETE: api/lesson/5
        public HttpResponseMessage Delete(int id)
        {
            HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.Conflict);

            using (ILessonService ls = new LessonService(WebApiApplication.connection))
            {
                ls.Remove(ls.Get(id));
                msg.StatusCode = HttpStatusCode.OK;
            }
            return(msg);
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ILessonRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Lesson>(null));
            var service = new LessonService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.LessonModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLLessonMapperMock,
                                            mock.DALMapperMockFactory.DALLessonMapperMock,
                                            mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock,
                                            mock.DALMapperMockFactory.DALLessonXStudentMapperMock,
                                            mock.BOLMapperMockFactory.BOLLessonXTeacherMapperMock,
                                            mock.DALMapperMockFactory.DALLessonXTeacherMapperMock);

            ApiLessonResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public IHttpActionResult GetLesson(string id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var models  = new List <LessonModel>();
                var service = new LessonService();

                return(Ok(BindingManager.ToLessonModel(service.Get(int.Parse(id)))));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
        public async Task Get_Latest_Version(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target)
        {
            var request = new LessonRequest();

            request.CloneFrom(target);

            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddRangeAsync(entities);

            await context.Lessons.AddAsync(target);

            await context.SaveChangesAsync();

            var newLesson = await service.Update(target.Id, request);

            var result = await service.Get(target.Id);

            result.Should().NotBeNull().And.BeEquivalentTo(newLesson);
        }