From 5c92bba207ea58bfd96a1fb8b1521b7d73d1a2a0 Mon Sep 17 00:00:00 2001 From: Ariel Lothlorien Date: Fri, 14 Jul 2017 03:39:57 -0500 Subject: [PATCH] Finish of Episode 4 Start of Episode 5 --- UberEntityComponentSystem/ObjectFactory.cs | 7 ++- .../ObjectFactoryTest.cs | 50 +++++++++++++++++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/UberEntityComponentSystem/ObjectFactory.cs b/UberEntityComponentSystem/ObjectFactory.cs index 5e0786c..12b38e0 100644 --- a/UberEntityComponentSystem/ObjectFactory.cs +++ b/UberEntityComponentSystem/ObjectFactory.cs @@ -11,7 +11,7 @@ namespace UberEntityComponentSystem public abstract T CreateNew(); public override object ObjCreateNew() { - throw new NotImplementedException(); + return CreateNew(); } /// @@ -22,11 +22,14 @@ public override object ObjCreateNew() public abstract T CleanForReuse(T obj); public override object ObjCleanForReuse(object obj) { - throw new NotImplementedException(); + return CleanForReuse((T) obj); } } + /// + /// DO NOT EXTEND + /// public abstract class ObjectFactoryBase { /// diff --git a/UberEntityComponentSystemTests/ObjectFactoryTest.cs b/UberEntityComponentSystemTests/ObjectFactoryTest.cs index 75859ca..b53a35c 100644 --- a/UberEntityComponentSystemTests/ObjectFactoryTest.cs +++ b/UberEntityComponentSystemTests/ObjectFactoryTest.cs @@ -12,7 +12,7 @@ namespace UberEntityComponentSystemTests class FactoryTestObjTesterCleanForReuseCalled : Exception { } class FactoryTestObjTesterCreateNewCalled : Exception { } - class FactoryTestObjTester {} + class FactoryTestObjTester { } /// /// DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING! @@ -21,14 +21,33 @@ class FactoryTestObjTesterFactory : ObjectFactory { public override FactoryTestObjTester CleanForReuse(FactoryTestObjTester obj) { - //throw new FactoryTestObjTesterCleanForReuseCalled(); //Prove the method was called - throw new NotImplementedException(); + throw new FactoryTestObjTesterCleanForReuseCalled(); //Prove the method was called } public override FactoryTestObjTester CreateNew() { - //throw new FactoryTestObjTesterCreateNewCalled(); //Prove the method was called - throw new NotImplementedException(); + throw new FactoryTestObjTesterCreateNewCalled(); //Prove the method was called + } + } + + class FactoryTestObjTesterCleanForReuseCalled2 : Exception { } + class FactoryTestObjTesterCreateNewCalled2 : Exception { } + + class FactoryTestObjTester2 { } + + /// + /// DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING! + /// + class FactoryTestObjTesterFactory2 : ObjectFactory + { + public override FactoryTestObjTester2 CleanForReuse(FactoryTestObjTester2 obj) + { + throw new FactoryTestObjTesterCleanForReuseCalled2(); //Prove the method was called + } + + public override FactoryTestObjTester2 CreateNew() + { + throw new FactoryTestObjTesterCreateNewCalled2(); //Prove the method was called } } @@ -51,9 +70,11 @@ public void CleanForReuseTest() { //Setup FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory(); + FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2(); //Test Assert.Throws(() => fact.CleanForReuse(new FactoryTestObjTester()), "Factory New didn't work."); + Assert.Throws(() => fact2.CleanForReuse(new FactoryTestObjTester2()), "Factory New didn't work."); } //ObjectFactoryTest::ObjCleanForReuse(); @@ -62,9 +83,24 @@ public void CleanForReuseBaseTest() { //Setup FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory(); + FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2(); //Test Assert.Throws(() => fact.ObjCleanForReuse(new FactoryTestObjTester()), "Factory Base New didn't work."); + Assert.Throws(() => fact2.ObjCleanForReuse(new FactoryTestObjTester2()), "Factory Base New didn't work."); + } + + //ObjectFactoryTest::ObjCleanForReuse(); + [Test] + public void CleanForReuseBaseExplodeTest() + { + //Setup + FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory(); + FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2(); + + //Test + Assert.Throws(() => fact.ObjCleanForReuse(new FactoryTestObjTester2()), "Factory Base New didn't work."); + Assert.Throws(() => fact2.ObjCleanForReuse(new FactoryTestObjTester()), "Factory Base New didn't work."); } //ObjectFactoryTest::CreateNew(); @@ -73,9 +109,11 @@ public void CreateTest() { //Setup FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory(); + FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2(); //Test Assert.Throws(() => fact.CreateNew(), "Factory New didn't work."); + Assert.Throws(() => fact2.CreateNew(), "Factory New didn't work."); } //ObjectFactoryTest::ObjCreateNew(); @@ -84,9 +122,11 @@ public void CreateObjectTest() { //Setup FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory(); + FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2(); //Test Assert.Throws(() => fact.ObjCreateNew(), "Factory Base New didn't work."); + Assert.Throws(() => fact2.ObjCreateNew(), "Factory Base New didn't work."); } } }