< Summary

Information
Class: CounterDrone.Core.Services.ModelService
Assembly: CounterDrone.Core
File(s): C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Services\ModelService.cs
Line coverage
96%
Covered lines: 31
Uncovered lines: 1
Coverable lines: 32
Total lines: 59
Line coverage: 96.8%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ImportModel(...)92.85%141494.44%
DeleteModel(...)100%11100%
GetAllModels()100%11100%
GetModel(...)100%11100%

File(s)

C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Services\ModelService.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using CounterDrone.Core.Models;
 5using CounterDrone.Core.Repository;
 6
 7namespace CounterDrone.Core.Services
 8{
 9    public class ModelService : IModelService
 10    {
 11        private readonly ModelRepository _repo;
 12        private readonly IPathProvider _paths;
 13
 714        public ModelService(ModelRepository repo, IPathProvider paths)
 715        {
 716            _repo = repo;
 717            _paths = paths;
 718        }
 19
 20        public ModelInfo ImportModel(string filePath, string name)
 1121        {
 1122            if (string.IsNullOrWhiteSpace(name))
 123                throw new ArgumentException("模型名称不能为空");
 24
 1025            var ext = Path.GetExtension(filePath).ToLowerInvariant();
 1026            if (ext != ".fbx" && ext != ".obj" && ext != ".stl" && ext != ".glb" && ext != ".gltf")
 127                throw new ArgumentException($"不支持的模型格式:{ext}");
 28
 929            var fileInfo = new FileInfo(filePath);
 930            if (fileInfo.Length > 500 * 1024 * 1024)
 031                throw new ArgumentException("模型文件大小超过 500MB 限制");
 32
 933            var model = new ModelInfo
 934            {
 935                Name = name,
 936                FilePath = filePath,
 937                FileSize = fileInfo.Length / (1024.0 * 1024.0),
 938            };
 39
 940            _repo.Insert(model);
 941            return model;
 942        }
 43
 44        public void DeleteModel(string id)
 145        {
 146            _repo.Delete(id);
 147        }
 48
 49        public List<ModelInfo> GetAllModels()
 150        {
 151            return _repo.GetAll();
 152        }
 53
 54        public ModelInfo GetModel(string id)
 255        {
 256            return _repo.GetById(id);
 257        }
 58    }
 59}