37 lines
1.9 KiB
C#
37 lines
1.9 KiB
C#
using Activity;
|
|
using asap.core;
|
|
|
|
void Check(bool value,string message){if(!value)throw new Exception(message);}
|
|
var evt=new cfg.FishingEvent{Type=1,SubType=2};
|
|
ActivitySentryManager.InitActivitySentryType(typeof(Sentry));
|
|
var first=GContext.container;
|
|
Check(first.Registrations.Count==1,"first container registration");
|
|
ActivitySentryManager.InitActivitySentryType(typeof(Sentry));
|
|
Check(first.Registrations.Count==1,"same container must not register twice");
|
|
Check(ActivitySentryManager.GetActivitySentryType(evt)==typeof(Sentry),"first discovery");
|
|
GContext.container=new Container();
|
|
ActivitySentryManager.InitActivitySentryType(typeof(Sentry));
|
|
Check(GContext.container.Registrations.Count==1,"new container must register cached type");
|
|
Check(ActivitySentryManager.GetTypeKey(typeof(Sentry))==(1,2),"new type key index");
|
|
GContext.container=new Container();
|
|
Check(ActivitySentryManager.GetActivitySentryType(evt)==typeof(Sentry),"lazy discovery after container replacement");
|
|
Check(GContext.container.Registrations.Count==1,"lazy discovery must register in new container");
|
|
Check(first.Registrations.Count==1,"old container remains untouched");
|
|
Console.WriteLine("PASS real ActivitySentryManager: explicit/lazy container replacement, duplicate guard, type-key cache");
|
|
|
|
[ActivitySentry(1,2)] public class Sentry:IActivitySentry{}
|
|
namespace Activity{public interface IActivitySentry{}}
|
|
namespace cfg{public class FishingEvent{public int Type,SubType;}}
|
|
namespace asap.core{
|
|
public static class GContext{public static Container container=new();}
|
|
public class Container{
|
|
public Dictionary<(Type,string),Type> Registrations=new();
|
|
public Container Register(Type service,string name,Type implementation){Registrations.Add((service,name),implementation);return this;}
|
|
public void PerScope(){}
|
|
}
|
|
}
|
|
namespace UnityEngine{public static class Debug{
|
|
public static void LogWarning(string message){}
|
|
public static void LogError(string message){throw new Exception(message);}
|
|
}}
|