< Summary

Class:DCL.Environment
Assembly:Environment
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Environment.cs
Covered lines:23
Uncovered lines:4
Coverable lines:27
Total lines:78
Line coverage:85.1% (23 of 27)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Environment()0%110100%
WaitUntilInitialized()0%220100%
Setup(...)0%220100%
SetupAsync(...)0%6200%
Dispose()0%330100%
Model(...)0%110100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Environment.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Helpers;
 3using System;
 4using System.Threading;
 5
 6namespace DCL
 7{
 8    public class Environment
 9    {
 110        public static Model i = new Model(new ServiceLocator());
 11
 12        private static CancellationTokenSource cancellationTokenSource;
 13
 14        private static bool initialized;
 15
 16        public static UniTask WaitUntilInitialized() =>
 117            UniTaskUtils.WaitForBoolean(ref initialized, cancellationToken: cancellationTokenSource?.Token ?? Cancellati
 18
 19        /// <summary>
 20        /// Setup the environment with the configured builder funcs.
 21        /// </summary>
 22        public static void Setup(ServiceLocator serviceLocator)
 23        {
 75924            i.Dispose();
 75925            i = new Model(serviceLocator);
 75926            cancellationTokenSource = new CancellationTokenSource();
 148927            serviceLocator.Initialize(cancellationTokenSource.Token).ContinueWith(() => initialized = true).Forget();
 75928        }
 29
 30        public static UniTask SetupAsync(ServiceLocator serviceLocator)
 31        {
 032            i.Dispose();
 033            i = new Model(serviceLocator);
 034            cancellationTokenSource = new CancellationTokenSource();
 035            return serviceLocator.Initialize(cancellationTokenSource.Token).ContinueWith(() => initialized = true);
 36        }
 37
 38        /// <summary>
 39        /// Dispose() all the current environment systems.
 40        /// </summary>
 41        public static void Dispose()
 42        {
 63343            i?.Dispose();
 44
 63345            if (cancellationTokenSource != null)
 46            {
 62847                cancellationTokenSource.Cancel();
 62848                cancellationTokenSource.Dispose();
 62849                cancellationTokenSource = null;
 50            }
 51
 63352            initialized = false;
 63353        }
 54
 55        public class Model : IDisposable
 56        {
 57            public readonly ServiceLocator serviceLocator;
 58            public readonly MessagingContext messaging;
 59            public readonly PlatformContext platform;
 60            public readonly WorldRuntimeContext world;
 61            public readonly HUDContext hud;
 62
 76063            public Model (ServiceLocator serviceLocator)
 64            {
 76065                this.serviceLocator = serviceLocator;
 76066                messaging = new MessagingContext(serviceLocator);
 76067                platform = new PlatformContext(serviceLocator);
 76068                world = new WorldRuntimeContext(serviceLocator);
 76069                hud = new HUDContext(serviceLocator);
 76070            }
 71
 72            public void Dispose()
 73            {
 139274                this.serviceLocator.Dispose();
 139275            }
 76        }
 77    }
 78}