public void PutTest()
        {
            var testFile      = @"D:\iCanFileData\upload\4JMQBV.gif";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".gif"));

            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            //測試資料
            var formData = new NameValueCollection
            {
                { "icantoken", "4a01b7ed-27d7-4312-9a63-71c53a70dc81" },
                { "classid", "9999testcourse" },
                { "title", string.Format("[修改單元測試] {0} ", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")) },
                { "content", "修改單元測試內容" },
                { "activityOuterKey", "135EF2B9-7D44-4C43-8EA4-F59C28C74F39" }
            };

            foreach (string key in formData)
            {
                multiPartContent.Add(new StringContent(formData[key]), key);
            }
            var controller = new DiscussionController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Put
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Put
                    }
                }
            };

            var targetResponse = controller.Put().Result; //List<Infrastructure.Entity.FileStorage>

            Assert.IsInstanceOfType(targetResponse, typeof(OkNegotiatedContentResult <BaseResponse <string> >));
            var targetResponseData = targetResponse as OkNegotiatedContentResult <BaseResponse <string> >;

            Assert.IsNotNull(targetResponseData.Content);
        }
        public void GetTest()
        {
            getTestValue = "A6D3B148-5CF7-427B-99DE-4674048EB0E9";

            target = new DiscussionController();
            var targetResponse = target.Get(getTestValue);

            Assert.IsInstanceOfType(targetResponse, getResponse);
            var targetResData = targetResponse as OkNegotiatedContentResult <ResultBaseModel <DiscussionDetail> >;

            Assert.IsNotNull(targetResData.Content);
            Assert.IsTrue(targetResData.Content.Success);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }