Ejemplo n.º 1
0
        public async Task <int> InsertVideoAsync(VideoMapper videoMapper)
        {
            using (var conn = _dbHelper.CreateSqlSugarConnection())
            {
                try
                {
                    conn.Ado.BeginTran();
                    var videoid = await conn.Insertable <Video>(videoMapper).ExecuteReturnIdentityAsync();

                    foreach (var item in videoMapper.Categories)
                    {
                        conn.AddQueue("insert into tvideocategory (VideoId,CategoryId) values (@VideoId,@CategoryId)", new { VideoId = videoid, CategoryId = item.Id });
                    }
                    foreach (var item in videoMapper.Tags)
                    {
                        conn.AddQueue("insert into tvideotag (VideoId,TagId) values (@VideoId,@TagId)", new { VideoId = videoid, TagId = item.Id });
                    }
                    await conn.SaveQueuesAsync();

                    conn.Ado.CommitTran();
                    return(1);
                }
                catch (Exception)
                {
                    conn.Ado.RollbackTran();
                    return(0);
                }
            }
        }
        public void Verify_MapToEntity_WithExistingEntity_AssignsVideoProperties()
        {
            // Arrange
            var mapper = new VideoMapper();
            var model  = VideosMockingSetup.DoMockingSetupForVideoModel();
            // Act
            IVideo existingEntity = new Video {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            Assert.Equal(model.Object.LowUrl, existingEntity.LowUrl);
            Assert.Equal(model.Object.HighUrl, existingEntity.HighUrl);
            Assert.Equal(model.Object.HdUrl, existingEntity.HdUrl);
            Assert.Equal(model.Object.Url, existingEntity.Url);
            Assert.Equal(model.Object.LengthSeconds, existingEntity.LengthSeconds);
            Assert.Equal(model.Object.PublishDate, existingEntity.PublishDate);
            // Related Objects
            Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
            Assert.Equal(model.Object.AuthorId, existingEntity.AuthorId);
            Assert.Equal(model.Object.VideoTypeId, existingEntity.VideoTypeId);
            // Associated Objects
            // <None>
        }
Ejemplo n.º 3
0
        public IVideoModel Update(IVideoModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = VideosRepository.Get(model.Id.Value);

            // Check if we would be applying identical information, if we are, just return the original
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (VideoMapper.AreEqual(model, existingEntity))
            {
                return(VideoMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            VideoMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            VideosRepository.Update(VideoMapper.MapToEntity(model));
            // Try to Save Changes
            VideosRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
        public void Verify_MapToSearchModel_AssignsVideoSearchProperties()
        {
            // Arrange
            var mapper = new VideoMapper();
            var model  = VideosMockingSetup.DoMockingSetupForVideoModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId);
            Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey);
            Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl);
            Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl);
            Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName);
            Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription);
            Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription);
            Assert.Equal(model.Object.AuthorId, searchModel.AuthorId);
            Assert.Equal(model.Object.Author?.CustomKey, searchModel.AuthorCustomKey);
            Assert.Equal(model.Object.Author?.ApiDetailUrl, searchModel.AuthorApiDetailUrl);
            Assert.Equal(model.Object.Author?.SiteDetailUrl, searchModel.AuthorSiteDetailUrl);
            Assert.Equal(model.Object.Author?.Name, searchModel.AuthorName);
            Assert.Equal(model.Object.Author?.ShortDescription, searchModel.AuthorShortDescription);
            Assert.Equal(model.Object.Author?.Description, searchModel.AuthorDescription);
            Assert.Equal(model.Object.VideoTypeId, searchModel.VideoTypeId);
            Assert.Equal(model.Object.VideoType?.CustomKey, searchModel.VideoTypeCustomKey);
            Assert.Equal(model.Object.VideoType?.ApiDetailUrl, searchModel.VideoTypeApiDetailUrl);
            Assert.Equal(model.Object.VideoType?.SiteDetailUrl, searchModel.VideoTypeSiteDetailUrl);
            Assert.Equal(model.Object.VideoType?.Name, searchModel.VideoTypeName);
            Assert.Equal(model.Object.VideoType?.ShortDescription, searchModel.VideoTypeShortDescription);
            Assert.Equal(model.Object.VideoType?.Description, searchModel.VideoTypeDescription);
        }
Ejemplo n.º 5
0
        public async Task <int> UpdateVideoAsync(VideoMapper videoMapper)
        {
            using (var conn = _dbHelper.CreateSqlSugarConnection())
            {
                try
                {
                    conn.Ado.BeginTran();
                    await conn.Updateable <Video>(videoMapper).ExecuteCommandAsync();

                    await conn.Deleteable <VideoTag>().Where(_ => _.VideoId == videoMapper.Id).ExecuteCommandAsync();

                    await conn.Deleteable <VideoCategory>().Where(_ => _.VideoId == videoMapper.Id).ExecuteCommandAsync();

                    foreach (var item in videoMapper.Categories)
                    {
                        conn.AddQueue("insert into tvideocategory (VideoId,CategoryId) values (@VideoId,@CategoryId)", new { VideoId = videoMapper.Id, CategoryId = item.Id });
                    }
                    foreach (var item in videoMapper.Tags)
                    {
                        conn.AddQueue("insert into tvideotag (VideoId,TagId) values (@VideoId,@TagId)", new { VideoId = videoMapper.Id, TagId = item.Id });
                    }
                    await conn.SaveQueuesAsync();

                    conn.Ado.CommitTran();
                    return(1);
                }
                catch (Exception)
                {
                    conn.Ado.RollbackTran();
                    return(0);
                }
            }
        }
Ejemplo n.º 6
0
        public IVideoModel Create(IVideoModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateIDIsNull(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Search for an Existing Record (Don't allow Duplicates
            var results = Search(VideoMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = VideoMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            VideosRepository.Add(newEntity);
            // Try to Save Changes
            VideosRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
Ejemplo n.º 7
0
        private static async Task MainAsync()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile($"appsettings.json", false)
                                    .Build();

            var feedUrl  = config["feed"];
            var location = config["location"];

            List <Video> videos = new List <Video>();

            var feed = await FeedReader.ReadAsync(feedUrl);

            var rss20feed = (CodeHollow.FeedReader.Feeds.AtomFeed)feed.SpecificFeed;

            foreach (var item in rss20feed.Items)
            {
                videos.Add(VideoMapper.XElementToVideo(item.Element));
            }

            var html = await RazorTemplateEngine.RenderAsync("~/Razor/index.cshtml", new IndexModel
            {
                Videos = videos,
            });

            await System.IO.File.WriteAllTextAsync($"{location}/Index.html", html);
        }
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new VideoMapper();
            var model  = VideosMockingSetup.DoMockingSetupForVideoModel(1);
            var entity = VideosMockingSetup.DoMockingSetupForVideo(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
        public Video update(Video newVideo)
        {
            Video oldVideo = _repository.get(newVideo.IDVideo);

            if (oldVideo == null)
            {
                return(null);
            }
            oldVideo = VideoMapper.mapModel(oldVideo, newVideo);
            if (oldVideo == null)
            {
                return(null);
            }
            _repository.update(oldVideo);
            return(oldVideo);
        }
        public void Verify_MapToModelLite_AssignsLiteOnlyVideoProperties()
        {
            // Arrange
            var mapper = new VideoMapper();
            var entity = VideosMockingSetup.DoMockingSetupForVideo();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            Assert.Equal(entity.Object.LowUrl, model.LowUrl);
            Assert.Equal(entity.Object.HighUrl, model.HighUrl);
            Assert.Equal(entity.Object.HdUrl, model.HdUrl);
            Assert.Equal(entity.Object.Url, model.Url);
            Assert.Equal(entity.Object.LengthSeconds, model.LengthSeconds);
            Assert.Equal(entity.Object.PublishDate, model.PublishDate);
            // Related Objects
            Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
            Assert.Equal(entity.Object.AuthorId, model.AuthorId);
            Assert.Equal(entity.Object.VideoTypeId, model.VideoTypeId);
        }
Ejemplo n.º 11
0
        private async Task SendResults(IDialogContext context, DocumentSearchResult results)
        {
            var message = context.MakeMessage();

            if (results.Results.Count == 0)
            {
                await context.PostAsync("There were no results found for \"" + searchText + "\".");

                context.Done <object>(null);
            }
            else
            {
                SearchHitStyler searchHitStyler = new SearchHitStyler();
                searchHitStyler.Apply(
                    ref message,
                    "Here are the results that I found:",
                    results.Results.Select(r => VideoMapper.ToSearchHit(r)).ToList().AsReadOnly());

                await context.PostAsync(message);

                context.Done <object>(null);
            }
        }
Ejemplo n.º 12
0
 public VideoController(IRepository <Video> videoRepo, VideoMapper videoMapper)
 {
     _videorepo   = videoRepo;
     _videoMapper = videoMapper;
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsVideoProperties()
 {
     // Arrange
     var mapper = new VideoMapper();
     var model = VideosMockingSetup.DoMockingSetupForVideoModel();
     // Act
     IVideo existingEntity = new Video { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.LowUrl, existingEntity.LowUrl);
     Assert.Equal(model.Object.HighUrl, existingEntity.HighUrl);
     Assert.Equal(model.Object.HdUrl, existingEntity.HdUrl);
     Assert.Equal(model.Object.Url, existingEntity.Url);
     Assert.Equal(model.Object.LengthSeconds, existingEntity.LengthSeconds);
     Assert.Equal(model.Object.PublishDate, existingEntity.PublishDate);
     // Related Objects
     Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
     Assert.Equal(model.Object.AuthorId, existingEntity.AuthorId);
     Assert.Equal(model.Object.VideoTypeId, existingEntity.VideoTypeId);
     // Associated Objects
     // <None>
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new VideoMapper();
     var model = VideosMockingSetup.DoMockingSetupForVideoModel(1);
     var entity = VideosMockingSetup.DoMockingSetupForVideo(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
 public void Verify_MapToModel_AssignsVideoProperties()
 {
     // Arrange
     var mapper = new VideoMapper();
     var entity = VideosMockingSetup.DoMockingSetupForVideo();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     Assert.Equal(entity.Object.LowUrl, model.LowUrl);
     Assert.Equal(entity.Object.HighUrl, model.HighUrl);
     Assert.Equal(entity.Object.HdUrl, model.HdUrl);
     Assert.Equal(entity.Object.Url, model.Url);
     Assert.Equal(entity.Object.LengthSeconds, model.LengthSeconds);
     Assert.Equal(entity.Object.PublishDate, model.PublishDate);
     // Related Objects
     Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
     Assert.Equal(entity.Object.AuthorId, model.AuthorId);
     Assert.Equal(entity.Object.VideoTypeId, model.VideoTypeId);
     // Associated Objects
     // <None>
 }
Ejemplo n.º 16
0
 public IVideoModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(VideoMapper.MapToModel(VideosRepository.Get(key)));
 }
Ejemplo n.º 17
0
 public IVideoModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(VideoMapper.MapToModel(VideosRepository.Get(id)));
 }
 public void Verify_MapToSearchModel_AssignsVideoSearchProperties()
 {
     // Arrange
     var mapper = new VideoMapper();
     var model = VideosMockingSetup.DoMockingSetupForVideoModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId);
     Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey);
     Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl);
     Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl);
     Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName);
     Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription);
     Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription);
     Assert.Equal(model.Object.AuthorId, searchModel.AuthorId);
     Assert.Equal(model.Object.Author?.CustomKey, searchModel.AuthorCustomKey);
     Assert.Equal(model.Object.Author?.ApiDetailUrl, searchModel.AuthorApiDetailUrl);
     Assert.Equal(model.Object.Author?.SiteDetailUrl, searchModel.AuthorSiteDetailUrl);
     Assert.Equal(model.Object.Author?.Name, searchModel.AuthorName);
     Assert.Equal(model.Object.Author?.ShortDescription, searchModel.AuthorShortDescription);
     Assert.Equal(model.Object.Author?.Description, searchModel.AuthorDescription);
     Assert.Equal(model.Object.VideoTypeId, searchModel.VideoTypeId);
     Assert.Equal(model.Object.VideoType?.CustomKey, searchModel.VideoTypeCustomKey);
     Assert.Equal(model.Object.VideoType?.ApiDetailUrl, searchModel.VideoTypeApiDetailUrl);
     Assert.Equal(model.Object.VideoType?.SiteDetailUrl, searchModel.VideoTypeSiteDetailUrl);
     Assert.Equal(model.Object.VideoType?.Name, searchModel.VideoTypeName);
     Assert.Equal(model.Object.VideoType?.ShortDescription, searchModel.VideoTypeShortDescription);
     Assert.Equal(model.Object.VideoType?.Description, searchModel.VideoTypeDescription);
 }