예제 #1
0
        public void CreateVideoExistingShouldFailTest()
        {
            StaticCache.LoadStaticCache();
            VideoController vc = new VideoController();

            var config  = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:22121/api/video/CreateVideo");
            var route   = config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {
                { "controller", "video" }
            });

            vc.ControllerContext = new HttpControllerContext(config, routeData, request);
            request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            ShawCodeExercise.Models.VideoModel video = new ShawCodeExercise.Models.VideoModel()
            {
                ID          = 1,
                Title       = "video 1 title",
                Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Hic ambiguo ludimur. Que Manilium, ab iisque M. Efficiens dici potest. Falli igitur possumus. Quae sequuntur igitur? Duo Reges: constructio interrete.",
                SeasonNo    = "S012",
                EpisodeNo   = "E01",
                IsLocked    = false,
            };

            var response = vc.CreateVideo(video);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Conflict);
        }
        public void CreateCategoryShouldPassTest()
        {
            StaticCache.LoadStaticCache();
            VideoController vc = new VideoController();

            var config  = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:22121/api/category/CreateCategory");
            var route   = config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {
                { "controller", "category" }
            });

            vc.ControllerContext = new HttpControllerContext(config, routeData, request);
            request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            ShawCodeExercise.Models.VideoModel video = new ShawCodeExercise.Models.VideoModel()
            {
                ID          = 6,
                Title       = "Mock title",
                Description = "Mock Description",
                SeasonNo    = "S012",
                EpisodeNo   = "E01",
                IsLocked    = false,
            };

            var response = vc.CreateVideo(video);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
        }
예제 #3
0
        public HttpResponseMessage AddVideo(VideoInfo videoDto)
        {
            try
            {
                Requires.NotNull("videoDto", videoDto);
                Requires.NotNegative("videoDto.CourseId", videoDto.CourseId);
                Requires.NotNegative("videoDto.ModuleId", videoDto.ModuleId);
                Requires.NotNegative("videoDto.OrderIndex", videoDto.OrderIndex);
                Requires.NotNegative("videoDto.CreatedByUserId", videoDto.CreatedByUserId);
                Requires.NotNegative("videoDto.LastModifiedByUserId", videoDto.LastModifiedByUserId);

                if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName))
                {
                    var vc = new VideoController();

                    // get the video from the database to maintain data integrity
                    var video = vc.GetVideo(videoDto.VideoId, videoDto.ModuleId);

                    if (video == null)
                    {
                        // this is a new video
                        // update all values
                        video = new VideoInfo()
                        {
                            VimeoId              = videoDto.VimeoId,
                            CourseId             = videoDto.CourseId,
                            ModuleId             = videoDto.ModuleId,
                            OrderIndex           = videoDto.OrderIndex,
                            CreatedByUserId      = videoDto.CreatedByUserId,
                            LastModifiedByUserId = videoDto.LastModifiedByUserId,
                            LastModifiedOnDate   = DateTime.Now,
                            CreatedOnDate        = DateTime.Now
                        };

                        vc.CreateVideo(video);
                    }
                    else
                    {
                        // this is an existing video that's getting updated
                        // we'll only update the values that are allowed to be updated
                        video.VimeoId              = videoDto.VimeoId;
                        video.CourseId             = videoDto.CourseId;
                        video.OrderIndex           = videoDto.OrderIndex;
                        video.LastModifiedByUserId = videoDto.LastModifiedByUserId;
                        video.LastModifiedOnDate   = DateTime.Now;

                        vc.UpdateVideo(video);
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }