< Summary

Class:DCLServices.WearablesCatalogService.WearableWithEntityResponseDto
Assembly:WearablesCatalogService
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/WearableResponse.cs
Covered lines:25
Uncovered lines:9
Coverable lines:34
Total lines:220
Line coverage:73.5% (25 of 34)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:6
Method coverage:83.3% (5 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetContentHashByFileName(...)0%3.043083.33%
ToWearableItem(...)0%330100%
GetMostRecentTransferTimestamp()0%17.85020%
ToWearableItem(...)0%5.075085.71%
WearableWithEntityResponseDto(...)0%110100%
WearableWithEntityResponseDto()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/WearableResponse.cs

#LineLine coverage
 1using DCLServices.Lambdas;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace DCLServices.WearablesCatalogService
 6{
 7    [Serializable]
 8    public class WearableWithoutDefinitionResponse
 9    {
 10        public List<WearableItem> wearables;
 11    }
 12
 13    [Serializable]
 14    public class WearableWithDefinitionResponse : PaginatedResponse
 15    {
 16        public List<WearableElementV1Dto> elements;
 17
 18        public WearableWithDefinitionResponse(List<WearableElementV1Dto> elements,
 19            int pageNum, int pageSize, int totalAmount)
 20        {
 21            this.elements = elements;
 22            this.pageNum = pageNum;
 23            this.pageSize = pageSize;
 24            this.totalAmount = totalAmount;
 25        }
 26
 27        public WearableWithDefinitionResponse() { }
 28    }
 29
 30    [Serializable]
 31    [Obsolete("Deprecated. Use WearableElementV2Dto instead")]
 32    public class WearableElementV1Dto
 33    {
 34        public string urn;
 35        public long maxTransferredAt;
 36        public WearableItem definition;
 37    }
 38
 39    [Serializable]
 40    public class WearableWithEntityResponseDto : PaginatedResponse
 41    {
 42        [Serializable]
 43        public class ElementDto
 44        {
 45            [Serializable]
 46            public class IndividualDataDto
 47            {
 48                public string id;
 49                public string tokenId;
 50                public string transferredAt;
 51                public string price;
 52            }
 53
 54            [Serializable]
 55            public class EntityDto
 56            {
 57                [Serializable]
 58                public class ContentDto
 59                {
 60                    public string file;
 61                    public string hash;
 62                }
 63
 64                [Serializable]
 65                public class MetadataDto
 66                {
 67                    [Serializable]
 68                    public class Representation
 69                    {
 70                        public string[] bodyShapes;
 71                        public string mainFile;
 72                        public string[] contents;
 73                        public string[] overrideHides;
 74                        public string[] overrideReplaces;
 75                    }
 76
 77                    [Serializable]
 78                    public class DataDto
 79                    {
 80                        public Representation[] representations;
 81                        public string category;
 82                        public string[] tags;
 83                        public string[] replaces;
 84                        public string[] hides;
 85                        public string[] removesDefaultHiding;
 86                        public bool blockVrmExport;
 87                    }
 88
 89                    public DataDto data;
 90                    public string id;
 91
 92                    public i18n[] i18n;
 93                    public string thumbnail;
 94
 95                    public string rarity;
 96                    public string description;
 97                }
 98
 99                public MetadataDto metadata;
 100                public ContentDto[] content;
 101                public string id;
 102
 103                public string GetContentHashByFileName(string fileName)
 104                {
 64105                    foreach (ContentDto dto in content)
 24106                        if (dto.file == fileName)
 16107                            return dto.hash;
 108
 0109                    return null;
 110                }
 111
 112                public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl, int amount)
 113                {
 8114                    WearableItem wearable = new WearableItem
 115                    {
 116                        data = new WearableItem.Data
 117                        {
 118                            representations = new WearableItem.Representation[metadata.data.representations.Length],
 119                            category = metadata.data.category,
 120                            hides = metadata.data.hides,
 121                            replaces = metadata.data.replaces,
 122                            tags = metadata.data.tags,
 123                            removesDefaultHiding = metadata.data.removesDefaultHiding,
 124                            blockVrmExport = metadata.data.blockVrmExport,
 125                        },
 126                        baseUrl = contentBaseUrl,
 127                        baseUrlBundles = bundlesBaseUrl,
 128                        emoteDataV0 = null,
 129                        description = metadata.description,
 130                        i18n = metadata.i18n,
 131                        id = metadata.id,
 132                        entityId = id,
 133                        rarity = metadata.rarity,
 134                        amount = amount,
 135                        thumbnail = GetContentHashByFileName(metadata.thumbnail),
 136                    };
 137
 32138                    for (var i = 0; i < metadata.data.representations.Length; i++)
 139                    {
 8140                        MetadataDto.Representation representation = metadata.data.representations[i];
 141
 8142                        wearable.data.representations[i] = new WearableItem.Representation
 143                        {
 144                            bodyShapes = representation.bodyShapes,
 145                            mainFile = representation.mainFile,
 146                            overrideHides = representation.overrideHides,
 147                            overrideReplaces = representation.overrideReplaces,
 148                            contents = new WearableItem.MappingPair[representation.contents.Length],
 149                        };
 150
 32151                        for (var z = 0; z < representation.contents.Length; z++)
 152                        {
 8153                            string fileName = representation.contents[z];
 8154                            string hash = GetContentHashByFileName(fileName);
 155
 8156                            wearable.data.representations[i].contents[z] = new WearableItem.MappingPair
 157                            {
 158                                url = $"{contentBaseUrl}/{hash}",
 159                                hash = hash,
 160                                key = fileName,
 161                            };
 162                        }
 163                    }
 164
 8165                    return wearable;
 166                }
 167            }
 168
 169            public string urn;
 170            public IndividualDataDto[] individualData;
 171            public EntityDto entity;
 172            public int amount;
 173            public string rarity;
 174
 175            public long GetMostRecentTransferTimestamp()
 176            {
 8177                if (individualData == null) return 0;
 178
 0179                long max = 0;
 180
 0181                foreach (IndividualDataDto dto in individualData)
 182                {
 0183                    if (!long.TryParse(dto.transferredAt, out long transferredAt))
 184                        continue;
 185
 0186                    if (transferredAt > max)
 0187                        max = transferredAt;
 188                }
 189
 0190                return max;
 191            }
 192
 193            public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl)
 194            {
 4195                string individualId = individualData != null ? individualData[0].id : string.Empty;
 4196                var wearable = entity.ToWearableItem(contentBaseUrl, bundlesBaseUrl, amount);
 197
 4198                if (!string.IsNullOrEmpty(individualId))
 0199                    wearable.id = individualId;
 200
 4201                wearable.rarity ??= rarity;
 4202                wearable.MostRecentTransferredDate = DateTimeOffset.FromUnixTimeSeconds(GetMostRecentTransferTimestamp()
 4203                return wearable;
 204            }
 205        }
 206
 207        public List<ElementDto> elements;
 208
 4209        public WearableWithEntityResponseDto(List<ElementDto> elements,
 210            int pageNum, int pageSize, int totalAmount)
 211        {
 4212            this.elements = elements;
 4213            this.pageNum = pageNum;
 4214            this.pageSize = pageSize;
 4215            this.totalAmount = totalAmount;
 4216        }
 217
 0218        public WearableWithEntityResponseDto() { }
 219    }
 220}