< Summary

Class:DCLServices.WearablesCatalogService.WearableWithDefinitionResponse
Assembly:WearablesCatalogService
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/WearableResponse.cs
Covered lines:1
Uncovered lines:6
Coverable lines:7
Total lines:220
Line coverage:14.2% (1 of 7)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:2
Method coverage:50% (1 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WearableWithDefinitionResponse(...)0%2100%
WearableWithDefinitionResponse()0%110100%

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
 018        public WearableWithDefinitionResponse(List<WearableElementV1Dto> elements,
 19            int pageNum, int pageSize, int totalAmount)
 20        {
 021            this.elements = elements;
 022            this.pageNum = pageNum;
 023            this.pageSize = pageSize;
 024            this.totalAmount = totalAmount;
 025        }
 26
 5627        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                {
 105                    foreach (ContentDto dto in content)
 106                        if (dto.file == fileName)
 107                            return dto.hash;
 108
 109                    return null;
 110                }
 111
 112                public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl, int amount)
 113                {
 114                    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
 138                    for (var i = 0; i < metadata.data.representations.Length; i++)
 139                    {
 140                        MetadataDto.Representation representation = metadata.data.representations[i];
 141
 142                        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
 151                        for (var z = 0; z < representation.contents.Length; z++)
 152                        {
 153                            string fileName = representation.contents[z];
 154                            string hash = GetContentHashByFileName(fileName);
 155
 156                            wearable.data.representations[i].contents[z] = new WearableItem.MappingPair
 157                            {
 158                                url = $"{contentBaseUrl}/{hash}",
 159                                hash = hash,
 160                                key = fileName,
 161                            };
 162                        }
 163                    }
 164
 165                    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            {
 177                if (individualData == null) return 0;
 178
 179                long max = 0;
 180
 181                foreach (IndividualDataDto dto in individualData)
 182                {
 183                    if (!long.TryParse(dto.transferredAt, out long transferredAt))
 184                        continue;
 185
 186                    if (transferredAt > max)
 187                        max = transferredAt;
 188                }
 189
 190                return max;
 191            }
 192
 193            public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl)
 194            {
 195                string individualId = individualData != null ? individualData[0].id : string.Empty;
 196                var wearable = entity.ToWearableItem(contentBaseUrl, bundlesBaseUrl, amount);
 197
 198                if (!string.IsNullOrEmpty(individualId))
 199                    wearable.id = individualId;
 200
 201                wearable.rarity ??= rarity;
 202                wearable.MostRecentTransferredDate = DateTimeOffset.FromUnixTimeSeconds(GetMostRecentTransferTimestamp()
 203                return wearable;
 204            }
 205        }
 206
 207        public List<ElementDto> elements;
 208
 209        public WearableWithEntityResponseDto(List<ElementDto> elements,
 210            int pageNum, int pageSize, int totalAmount)
 211        {
 212            this.elements = elements;
 213            this.pageNum = pageNum;
 214            this.pageSize = pageSize;
 215            this.totalAmount = totalAmount;
 216        }
 217
 218        public WearableWithEntityResponseDto() { }
 219    }
 220}