< Summary

Class:WinSolutions.Sveta.Server.Data.DataModel.Extensions.PhotosExtension
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Helpers/PhotosExtension.cs
Covered lines:20
Uncovered lines:12
Coverable lines:32
Total lines:53
Line coverage:62.5% (20 of 32)
Covered branches:2
Total branches:8
Branch coverage:25% (2 of 8)

Metrics

MethodLine coverage Branch coverage
.cctor()100%100%
SetPhotoUrl(...)50%33.33%
SetDefault(...)100%100%
AddRootUrl(...)100%100%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Helpers/PhotosExtension.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Drawing;
 3using SVETA.Api.Data.Domain;
 4using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 5
 6namespace WinSolutions.Sveta.Server.Data.DataModel.Extensions
 7{
 8    public static class PhotosExtension
 9    {
 110        static char[] trimChars = new char[] { '/', '\\' };
 11        public static void SetPhotoUrl(this List<Photo> photos, ImagesSettings imageSettings)
 1112        {
 1113            if (photos == null)
 014                photos = new List<Photo>();
 1115            if (photos.Count == 0)
 1116            {
 1117                photos.Add(new Photo().SetDefault(imageSettings));
 1118                return;
 19            }
 20            string CreateUrl(string path)
 021            {
 022                if (path == default)
 023                    return imageSettings.PlaceholderImageUrl.AddRootUrl(imageSettings.ImageUrl);
 24                else
 025                    return path.AddRootUrl(imageSettings.ImageUrl);
 026            }
 027            foreach (var photo in photos)
 028            {
 029                photo.PreviewUrl = CreateUrl(photo.PreviewUrl);
 030                photo.FullSizeUrl = CreateUrl(photo.FullSizeUrl);
 031            }
 32
 033            return;
 1134        }
 35
 36        public static Photo SetDefault(this Photo photo, ImagesSettings imageSettings)
 1137        {
 1138            return new Photo
 1139            {
 1140                FullSizeHeight = imageSettings.ImageFullsizeHeight,
 1141                FullSizeWidth = imageSettings.ImageFullsizeWidth,
 1142                FullSizeUrl = imageSettings.PlaceholderImageUrl.AddRootUrl(imageSettings.ImageUrl),
 1143                PreviewHeight = imageSettings.ImagePreveiwHeight,
 1144                PreviewWidth = imageSettings.ImagePreveiwWidth,
 1145                PreviewUrl = imageSettings.PlaceholderImageUrl.AddRootUrl(imageSettings.ImageUrl)
 1146            };
 1147        }
 48
 49        public static string AddRootUrl(this string path, string root) =>
 2250            root.TrimEnd(trimChars) + '/' + path.TrimStart(trimChars);
 51
 52    }
 53}