|
using System; |
|
using NUnit.Framework; |
|
|
|
namespace Custom.Sources |
|
{ |
|
[TestFixture] |
|
public class TestDestroyWithFeature |
|
{ |
|
private Contexts _contexts; |
|
|
|
[SetUp] |
|
public void SetUp( ) |
|
{ |
|
_contexts = new Contexts( ); |
|
_contexts.SubscribeId( ); |
|
} |
|
|
|
[TestCase( 1, 2, false )] |
|
[TestCase( 19, 19, true )] |
|
[TestCase( -1, -1, false )] |
|
[TestCase( 1, -1, false )] |
|
[TestCase( -1, 1, false )] |
|
public void Test_DestroyWith( Int32 emitId, Int32 subscribeId, Boolean expected ) |
|
{ |
|
// given |
|
_contexts.SubscribeDestroyWith( _contexts.gameC, |
|
_contexts.gameC.GetGroup( GameCMatcher.AllOf( GameCMatcher.Destroy, GameCMatcher.DestroyWith_Emit ) ) ); |
|
|
|
var ent = _contexts.gameC.CreateEntity( ); |
|
if ( emitId >= 0 ) |
|
{ |
|
ent.AddDestroyWith_Emit( emitId ); |
|
} |
|
|
|
var entSubscribe = _contexts.gameC.CreateEntity( ); |
|
if ( subscribeId >= 0 ) |
|
{ |
|
entSubscribe.AddDestroyWith_Subscribe( subscribeId ); |
|
} |
|
|
|
// when |
|
ent.isDestroy = true; |
|
|
|
// then |
|
Assert.AreEqual( expected, entSubscribe.isDestroy ); |
|
} |
|
|
|
[Test] |
|
public void Test_DestroyWith_Chain( ) |
|
{ |
|
// given |
|
_contexts.SubscribeDestroyWith( _contexts.gameC, |
|
_contexts.gameC.GetGroup( GameCMatcher.AllOf( GameCMatcher.Destroy, GameCMatcher.DestroyWith_Emit ) ) ); |
|
|
|
var emitId = 100; |
|
var ent = _contexts.gameC.CreateEntity( ); |
|
ent.AddDestroyWith_Emit( emitId ); |
|
|
|
var entSubscribe = _contexts.gameC.CreateEntity( ); |
|
entSubscribe.AddDestroyWith_Subscribe( emitId ); |
|
|
|
var emitId2 = 122; |
|
entSubscribe.AddDestroyWith_Emit( emitId2 ); |
|
|
|
var entSubscribe2 = _contexts.gameC.CreateEntity( ); |
|
entSubscribe2.AddDestroyWith_Subscribe( emitId2 ); |
|
|
|
// when |
|
ent.isDestroy = true; |
|
|
|
// then |
|
Assert.AreEqual( true, entSubscribe.isDestroy ); |
|
Assert.AreEqual( true, entSubscribe2.isDestroy ); |
|
} |
|
|
|
[Test] |
|
public void Test_DestroyWith_CircularDependency( ) |
|
{ |
|
// given |
|
_contexts.SubscribeDestroyWith( _contexts.gameC, |
|
_contexts.gameC.GetGroup( GameCMatcher.AllOf( GameCMatcher.Destroy, GameCMatcher.DestroyWith_Emit ) ) ); |
|
|
|
var ent = _contexts.gameC.CreateEntity( ); |
|
var entSubscribe = _contexts.gameC.CreateEntity( ); |
|
|
|
var emitId = 100; |
|
ent.AddDestroyWith_Emit( emitId ); |
|
entSubscribe.AddDestroyWith_Subscribe( emitId ); |
|
|
|
var emitId2 = 122; |
|
entSubscribe.AddDestroyWith_Emit( emitId2 ); |
|
ent.AddDestroyWith_Subscribe( emitId2 ); |
|
|
|
// when |
|
ent.isDestroy = true; |
|
|
|
// then |
|
Assert.AreEqual( true, ent.isDestroy ); |
|
Assert.AreEqual( true, entSubscribe.isDestroy ); |
|
} |
|
|
|
[Test] |
|
public void Test_DestroyWith_CircularDependency2( ) |
|
{ |
|
// given |
|
_contexts.SubscribeDestroyWith( _contexts.gameC, |
|
_contexts.gameC.GetGroup( GameCMatcher.AllOf( GameCMatcher.Destroy, GameCMatcher.DestroyWith_Emit ) ) ); |
|
|
|
var ent = _contexts.gameC.CreateEntity( ); |
|
var entSubscribe = _contexts.gameC.CreateEntity( ); |
|
|
|
var emitId = 100; |
|
ent.AddDestroyWith_Emit( emitId ); |
|
entSubscribe.AddDestroyWith_Subscribe( emitId ); |
|
|
|
var emitId2 = 122; |
|
entSubscribe.AddDestroyWith_Emit( emitId2 ); |
|
ent.AddDestroyWith_Subscribe( emitId2 ); |
|
|
|
// when |
|
entSubscribe.isDestroy = true; |
|
|
|
// then |
|
Assert.AreEqual( true, ent.isDestroy ); |
|
Assert.AreEqual( true, entSubscribe.isDestroy ); |
|
} |
|
|
|
[Test] |
|
public void Test_DestroyWith_CircularDependency_Chain( ) |
|
{ |
|
// given |
|
_contexts.SubscribeDestroyWith( _contexts.gameC, |
|
_contexts.gameC.GetGroup( GameCMatcher.AllOf( GameCMatcher.Destroy, GameCMatcher.DestroyWith_Emit ) ) ); |
|
|
|
var ent = _contexts.gameC.CreateEntity( ); |
|
var entSubscribe = _contexts.gameC.CreateEntity( ); |
|
var entSubscribe2 = _contexts.gameC.CreateEntity( ); |
|
|
|
var emitId = 100; |
|
ent.AddDestroyWith_Emit( emitId ); |
|
entSubscribe.AddDestroyWith_Subscribe( emitId ); |
|
entSubscribe2.AddDestroyWith_Subscribe( emitId ); |
|
|
|
var emitId2 = 122; |
|
entSubscribe2.AddDestroyWith_Emit( emitId2 ); |
|
ent.AddDestroyWith_Subscribe( emitId2 ); |
|
|
|
// when |
|
entSubscribe2.isDestroy = true; |
|
|
|
// then |
|
Assert.AreEqual( true, ent.isDestroy ); |
|
Assert.AreEqual( true, entSubscribe.isDestroy ); |
|
Assert.AreEqual( true, entSubscribe2.isDestroy ); |
|
} |
|
} |
|
} |