< Summary

Class:DCLFeatures.CameraReel.Section.CameraReelModel
Assembly:CameraReel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/Section/Scripts/CameraReelModel.cs
Covered lines:0
Uncovered lines:30
Coverable lines:30
Total lines:72
Line coverage:0% (0 of 30)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:13
Method coverage:0% (0 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CameraReelModel()0%2100%
SetStorageStatus(...)0%6200%
AddScreenshotAsFirst(...)0%2100%
AddScreenshotAsFirst(...)0%12300%
AddScreenshotAsLast(...)0%12300%
RemoveScreenshot(...)0%12300%
GetNextScreenshot(...)0%12300%
GetPreviousScreenshot(...)0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/Section/Scripts/CameraReelModel.cs

#LineLine coverage
 1using DCLServices.CameraReelService;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace DCLFeatures.CameraReel.Section
 7{
 8    public class CameraReelModel
 9    {
 10        public delegate void StorageUpdatedHandler(int totalScreenshots, int maxScreenshots);
 011        private readonly LinkedList<CameraReelResponse> reels = new ();
 12
 013        public int LoadedScreenshotCount => reels.Count;
 014        public int TotalScreenshotsInStorage { get; private set; }
 015        public int MaxScreenshotsInStorage { get; private set; }
 16
 17        public event Action<CameraReelResponse> ScreenshotRemoved;
 18        public event Action<bool, CameraReelResponse> ScreenshotAdded;
 19        public event StorageUpdatedHandler StorageUpdated;
 20
 21        public void SetStorageStatus(int totalScreenshots, int maxScreenshots)
 22        {
 023            TotalScreenshotsInStorage = totalScreenshots;
 024            MaxScreenshotsInStorage = maxScreenshots;
 025            StorageUpdated?.Invoke(totalScreenshots, maxScreenshots);
 026        }
 27
 28        public void AddScreenshotAsFirst(CameraReelResponse screenshot, CameraReelStorageStatus storage)
 29        {
 030            AddScreenshotAsFirst(screenshot);
 031            SetStorageStatus(storage.CurrentScreenshots, storage.MaxScreenshots);
 032        }
 33
 34        private void AddScreenshotAsFirst(CameraReelResponse screenshot)
 35        {
 036            CameraReelResponse existingScreenshot = reels.FirstOrDefault(s => s.id == screenshot.id);
 37
 038            if (existingScreenshot != null)
 039                RemoveScreenshot(existingScreenshot);
 40
 041            reels.AddFirst(screenshot);
 042            ScreenshotAdded?.Invoke(true, screenshot);
 043        }
 44
 45        public void AddScreenshotAsLast(CameraReelResponse screenshot)
 46        {
 047            CameraReelResponse existingScreenshot = reels.FirstOrDefault(s => s.id == screenshot.id);
 48
 049            if (existingScreenshot != null)
 050                RemoveScreenshot(existingScreenshot);
 51
 052            reels.AddLast(screenshot);
 053            ScreenshotAdded?.Invoke(false, screenshot);
 054        }
 55
 56        public void RemoveScreenshot(CameraReelResponse current)
 57        {
 058            LinkedListNode<CameraReelResponse> nodeToRemove = reels.Find(current);
 59
 060            if (nodeToRemove != null)
 061                reels.Remove(nodeToRemove);
 62
 063            ScreenshotRemoved?.Invoke(current);
 064        }
 65
 66        public CameraReelResponse GetNextScreenshot(CameraReelResponse current) =>
 067            reels.Find(current)?.Next?.Value;
 68
 69        public CameraReelResponse GetPreviousScreenshot(CameraReelResponse current) =>
 070            reels.Find(current)?.Previous?.Value;
 71    }
 72}