public virtual void Arrange() { _lessonService = new FakeLessonService(); _controller = new LessonController( new Lazy <ILessonService>(() => _lessonService)); }
public async void BulkInsert_No_Errors() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); var mockResponse = new CreateResponse <ApiLessonResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiLessonResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLessonRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLessonResponseModel> >(mockResponse)); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiLessonRequestModel>(); records.Add(new ApiLessonRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var result = (response as OkObjectResult).Value as List <ApiLessonResponseModel>; result.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLessonRequestModel>())); }
public void When_Get_List_Lessons() { var lList = new Lesson[] { new Lesson { Id = 1, Name = "Test Lesson Name 1", Code = "TLN1", Akts = 5, Hours = 4, Guid = Guid.NewGuid().ToString(), UserId = "UserId 1" }, new Lesson { Id = 2, Name = "Test Lesson Name 2", Code = "TLN2", Akts = 6, Hours = 3, Guid = Guid.NewGuid().ToString(), UserId = "UserId 2" }, new Lesson { Id = 3, Name = "Test Lesson Name 3", Code = "TLN3", Akts = 7, Hours = 2, Guid = Guid.NewGuid().ToString(), UserId = "UserId 3" }, new Lesson { Id = 4, Name = "Test Lesson Name 4", Code = "TLN4", Akts = 8, Hours = 1, Guid = Guid.NewGuid().ToString(), UserId = "UserId 4" } }; var mockContext = new Mock <IUnitOfWork>(); var userManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); mockContext.Setup(x => x.Lessons.GetAll()).Returns(() => lList.AsQueryable()); var lessonController = new LessonController(mockContext.Object, userManager); var lessonList = (List <Lesson>)lessonController.Index().Model; Assert.Equal(lessonList.Count, 4); }
public async void Patch_No_Errors() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiLessonResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(true); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiLessonRequestModel>())) .Callback <int, ApiLessonRequestModel>( (id, model) => model.ActualEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")) ) .Returns(Task.FromResult <UpdateResponse <ApiLessonResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLessonResponseModel>(new ApiLessonResponseModel())); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiLessonModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiLessonRequestModel>(); patch.Replace(x => x.ActualEndDate, DateTime.Parse("1/1/1987 12:00:00 AM")); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiLessonRequestModel>())); }
public void LessonController_GetLesson() { //Arrange var expectedCategoryDatas = Task <List <CategoryData> > .Factory.StartNew(() => { return(new List <CategoryData> { new CategoryData { Category = "Language", Desciption = "desciption", Topics = "Topics" } }); }); //Act lessonRepository.Setup(x => x.GetCategoryData()).Returns(expectedCategoryDatas); LessonController lessonController = new LessonController(new Lazy <ILessonRepository>(() => lessonRepository.Object), new Lazy <INotificationManager>(), new Lazy <IAdminRepository>(), new Lazy <IUtility>()); var actionResult = lessonController.CreateLesson();// as Task<ActionResult>; var result = actionResult as Task <ActionResult>; //Assert Assert.IsNotNull(result); Assert.AreEqual("_CreateLesson", (result.Result as ViewResult).ViewName); }
public void Initialize() { httpContext = new MockHttpContextWrapper(); controllerToTest = new LessonController(); controllerToTest.ControllerContext = new ControllerContext(httpContext.Context.Object, new RouteData(), controllerToTest); dbContext = new DAL.SchoolContext(this.ConnectionString); controllerToTest.DbContext = dbContext; }
public void it_should_return_data_for_get() { // Arrange LessonController controller = new LessonController(); // Act var result = controller.Get().Result; // Assert Assert.IsNotNull(result); }
public async void Get_Not_Exists() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLessonResponseModel>(null)); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Delete_Errors() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async void All_Not_Exists() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiLessonResponseModel> >(new List <ApiLessonResponseModel>())); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiLessonResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public async void Update_NotFound() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiLessonResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiLessonRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiLessonResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLessonResponseModel>(null)); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiLessonModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Update(default(int), new ApiLessonRequestModel()); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Patch_Record_Not_Found() { LessonControllerMockFacade mock = new LessonControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLessonResponseModel>(null)); LessonController controller = new LessonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiLessonRequestModel>(); patch.Replace(x => x.ActualEndDate, DateTime.Parse("1/1/1987 12:00:00 AM")); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public static ApplicantViewModel MapingApplicantViewModel(string firstname, string lastname, string phone, string email, string desc, DateTime date, int lessonId, string techName) { LessonController lessonController = new LessonController(); return(new ApplicantViewModel() { FirstName = firstname, LastName = lastname, Phone1 = phone, Email = email, Description = desc, Date = date, Technology = Mapper.MapingTechnologyViewModel(techName) }); }
public void LessonController_CreateLesson() { //Arrange LessonModel expectedLessonModel = new LessonModel(); expectedLessonModel.Status = LessonStatus.Draft.ToString(); expectedLessonModel.CreatedDate = DateTime.Now; expectedLessonModel.CreatedBy = new Guid(); expectedLessonModel.Source = LessonSource.Elearning; expectedLessonModel.Lesson = new Dictionary <string, string>(); expectedLessonModel.Lesson.Add(new KeyValuePair <string, string>(LessonSource.Elearning.ToString(), "http://www.youtube.com")); Dictionary <string, string> actualLesson = new Dictionary <string, string>(); actualLesson.Add(LessonSource.Elearning.ToString(), "http://www.youtube.com"); var actualModel = Task <LessonModel> .Factory.StartNew(() => { return(new LessonModel { Source = LessonSource.Elearning, Lesson = actualLesson }); }); //Act lessonRepository.Setup(x => x.UpsertLesson(It.IsAny <LessonModel>(), true)).Returns(actualModel); LessonController lessonController = new LessonController(new Lazy <ILessonRepository>(() => lessonRepository.Object), new Lazy <INotificationManager>(), new Lazy <IAdminRepository>(), new Lazy <IUtility>()); Task <ActionResult> result = lessonController.CreateLesson() as Task <ActionResult>; //Assert Assert.IsNotNull(result); Assert.IsNull(result.Exception); Assert.AreEqual(result.Status.ToString(), "RanToCompletion"); Assert.AreEqual(expectedLessonModel.Lesson.Keys.ToString(), actualModel.Result.Lesson.Keys.ToString()); }
public async void WhenITryToLookForATutorialInACourseQ() { _controller = new LessonController(mockLessonService.Object, mockMapper.Object); _okResult = await _controller.ListByCourseIdAsyncx(course.Id); }
public void GivenInitializeMockingData() { var mock = ScenarioContext.Current.Get <MockRepository>(); var classRoomRepo = mock.Create <IClassRoomRepository>(); var likeLessonRepo = mock.Create <ILikeLessonRepository>(); var userprofileRepo = mock.Create <IUserProfileRepository>(); var classCalendarRepo = mock.Create <IClassCalendarRepository>(); var lessonCatalogRepo = mock.Create <ILessonCatalogRepository>(); var commentRepo = mock.Create <ICommentRepository>(); var friendRequestRepo = mock.Create <IFriendRequestRepository>(); var userActivityRepo = mock.Create <IUserActivityRepository>(); var likeCommentRepo = mock.Create <ILikeCommentRepository>(); var likeDiscussionRepo = mock.Create <ILikeDiscussionRepository>(); var studentKeyRepo = mock.Create <IStudentKeyRepository>(); var notificationRepo = mock.Create <INotificationRepository>(); var dateTime = mock.Create <IDateTime>(); ScenarioContext.Current.Set(classRoomRepo); ScenarioContext.Current.Set(likeLessonRepo); ScenarioContext.Current.Set(userprofileRepo); ScenarioContext.Current.Set(classCalendarRepo); ScenarioContext.Current.Set(lessonCatalogRepo); ScenarioContext.Current.Set(commentRepo); ScenarioContext.Current.Set(friendRequestRepo); ScenarioContext.Current.Set(userActivityRepo); ScenarioContext.Current.Set(likeCommentRepo); ScenarioContext.Current.Set(likeDiscussionRepo); ScenarioContext.Current.Set(studentKeyRepo); ScenarioContext.Current.Set(notificationRepo); ScenarioContext.Current.Set(dateTime); var notificationCtrl = new NotificationController(userprofileRepo.Object, notificationRepo.Object, likeLessonRepo.Object, likeCommentRepo.Object, likeDiscussionRepo.Object, commentRepo.Object, classCalendarRepo.Object, friendRequestRepo.Object, dateTime.Object); var myCourseCtrl = new LessonController(classCalendarRepo.Object, userprofileRepo.Object, classRoomRepo.Object, likeLessonRepo.Object, lessonCatalogRepo.Object, commentRepo.Object, friendRequestRepo.Object, userActivityRepo.Object, notificationCtrl, dateTime.Object); var commentCtrl = new CommentController(classCalendarRepo.Object, userprofileRepo.Object, commentRepo.Object, userActivityRepo.Object, likeCommentRepo.Object, notificationCtrl, dateTime.Object); var discussionCtrl = new DiscussionController(classCalendarRepo.Object, userprofileRepo.Object, commentRepo.Object, userActivityRepo.Object, likeDiscussionRepo.Object, notificationCtrl, dateTime.Object); var mycourseCtrl = new MyCourseController(classCalendarRepo.Object, userprofileRepo.Object, userActivityRepo.Object, classRoomRepo.Object, studentKeyRepo.Object, lessonCatalogRepo.Object, likeLessonRepo.Object, likeCommentRepo.Object, likeDiscussionRepo.Object, dateTime.Object); var friendCtrl = new FriendController(classCalendarRepo.Object, userprofileRepo.Object, friendRequestRepo.Object, userActivityRepo.Object, dateTime.Object); ScenarioContext.Current.Set(notificationCtrl); ScenarioContext.Current.Set(myCourseCtrl); ScenarioContext.Current.Set(commentCtrl); ScenarioContext.Current.Set(discussionCtrl); ScenarioContext.Current.Set(mycourseCtrl); ScenarioContext.Current.Set(friendCtrl); }
public void GivenInitializeMockingData() { var mock = ScenarioContext.Current.Get <MockRepository>(); var classRoomRepo = mock.Create <IClassRoomRepository>(); var likeLessonRepo = mock.Create <ILikeLessonRepository>(); var userprofileRepo = mock.Create <IUserProfileRepository>(); var classCalendarRepo = mock.Create <IClassCalendarRepository>(); var lessonCatalogRepo = mock.Create <ILessonCatalogRepository>(); var commentRepo = mock.Create <ICommentRepository>(); var friendRequestRepo = mock.Create <IFriendRequestRepository>(); var userActivityRepo = mock.Create <IUserActivityRepository>(); var likeCommentRepo = mock.Create <ILikeCommentRepository>(); var likeDiscussionRepo = mock.Create <ILikeDiscussionRepository>(); var studentKeyRepo = mock.Create <IStudentKeyRepository>(); var notificationRepo = mock.Create <INotificationRepository>(); var contractRepo = mock.Create <IContractRepository>(); var courseCatalogRepo = mock.Create <ICourseCatalogRepository>(); var paymentRepo = mock.Create <IPaymentRepository>(); var payment = mock.Create <Engines.IPayment>(); var logger = mock.Create <ILogger>(); var loggerFactory = mock.Create <ILoggerFactory>(); var appConfigOption = mock.Create <IOptions <AppConfigOptions> >(); var errorOption = mock.Create <IOptions <ErrorMessageOptions> >(); var httpContext = mock.Create <Microsoft.AspNet.Http.HttpContext>(); var dateTime = mock.Create <IDateTime>(); appConfigOption.Setup(it => it.Value).Returns(new AppConfigOptions()); errorOption.Setup(it => it.Value).Returns(new ErrorMessageOptions()); ScenarioContext.Current.Set(classRoomRepo); ScenarioContext.Current.Set(likeLessonRepo); ScenarioContext.Current.Set(userprofileRepo); ScenarioContext.Current.Set(classCalendarRepo); ScenarioContext.Current.Set(lessonCatalogRepo); ScenarioContext.Current.Set(commentRepo); ScenarioContext.Current.Set(friendRequestRepo); ScenarioContext.Current.Set(userActivityRepo); ScenarioContext.Current.Set(likeCommentRepo); ScenarioContext.Current.Set(likeDiscussionRepo); ScenarioContext.Current.Set(studentKeyRepo); ScenarioContext.Current.Set(notificationRepo); ScenarioContext.Current.Set(contractRepo); ScenarioContext.Current.Set(courseCatalogRepo); ScenarioContext.Current.Set(paymentRepo); ScenarioContext.Current.Set(payment); ScenarioContext.Current.Set(logger); ScenarioContext.Current.Set(loggerFactory); ScenarioContext.Current.Set(appConfigOption); ScenarioContext.Current.Set(errorOption); ScenarioContext.Current.Set(httpContext); ScenarioContext.Current.Set(dateTime); loggerFactory.Setup(it => it.CreateLogger(It.IsAny <string>())) .Returns(() => logger.Object); var notificationCtrl = new NotificationController(userprofileRepo.Object, notificationRepo.Object, likeLessonRepo.Object, likeCommentRepo.Object, likeDiscussionRepo.Object, commentRepo.Object, classCalendarRepo.Object, friendRequestRepo.Object, dateTime.Object); var lessonCtrl = new LessonController(classCalendarRepo.Object, userprofileRepo.Object, classRoomRepo.Object, likeLessonRepo.Object, lessonCatalogRepo.Object, commentRepo.Object, friendRequestRepo.Object, userActivityRepo.Object, notificationCtrl, appConfigOption.Object, dateTime.Object); var commentCtrl = new CommentController(classCalendarRepo.Object, userprofileRepo.Object, commentRepo.Object, userActivityRepo.Object, likeCommentRepo.Object, notificationCtrl, dateTime.Object); var discussionCtrl = new DiscussionController(classCalendarRepo.Object, userprofileRepo.Object, commentRepo.Object, userActivityRepo.Object, likeDiscussionRepo.Object, notificationCtrl, dateTime.Object); var myCourseCtrl = new MyCourseController(classCalendarRepo.Object, userprofileRepo.Object, userActivityRepo.Object, classRoomRepo.Object, studentKeyRepo.Object, lessonCatalogRepo.Object, likeLessonRepo.Object, likeCommentRepo.Object, likeDiscussionRepo.Object, contractRepo.Object, courseCatalogRepo.Object, loggerFactory.Object, dateTime.Object); var friendCtrl = new FriendController(classCalendarRepo.Object, userprofileRepo.Object, friendRequestRepo.Object, userActivityRepo.Object, classRoomRepo.Object, dateTime.Object); var courseCtrl = new CourseController(courseCatalogRepo.Object, appConfigOption.Object); var purchaseCtrl = new PurchaseController(courseCtrl, myCourseCtrl, userprofileRepo.Object, classRoomRepo.Object, classCalendarRepo.Object, lessonCatalogRepo.Object, userActivityRepo.Object, paymentRepo.Object, appConfigOption.Object, errorOption.Object, loggerFactory.Object, payment.Object, dateTime.Object); ScenarioContext.Current.Set(notificationCtrl); ScenarioContext.Current.Set(lessonCtrl); ScenarioContext.Current.Set(commentCtrl); ScenarioContext.Current.Set(discussionCtrl); ScenarioContext.Current.Set(myCourseCtrl); ScenarioContext.Current.Set(friendCtrl); ScenarioContext.Current.Set(purchaseCtrl); }