Skip to content

Commit

Permalink
Finish of Episode 4 Start of Episode 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Eforen committed Jul 14, 2017
1 parent fc98b9e commit 5c92bba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
7 changes: 5 additions & 2 deletions UberEntityComponentSystem/ObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace UberEntityComponentSystem
public abstract T CreateNew();
public override object ObjCreateNew()
{
throw new NotImplementedException();
return CreateNew();
}

/// <summary>
Expand All @@ -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);
}

}

/// <summary>
/// DO NOT EXTEND
/// </summary>
public abstract class ObjectFactoryBase
{
/// <summary>
Expand Down
50 changes: 45 additions & 5 deletions UberEntityComponentSystemTests/ObjectFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace UberEntityComponentSystemTests
class FactoryTestObjTesterCleanForReuseCalled : Exception { }
class FactoryTestObjTesterCreateNewCalled : Exception { }

class FactoryTestObjTester {}
class FactoryTestObjTester { }

/// <summary>
/// DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING!
Expand All @@ -21,14 +21,33 @@ class FactoryTestObjTesterFactory : ObjectFactory<FactoryTestObjTester>
{
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 { }

/// <summary>
/// DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING!
/// </summary>
class FactoryTestObjTesterFactory2 : ObjectFactory<FactoryTestObjTester2>
{
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
}
}

Expand All @@ -51,9 +70,11 @@ public void CleanForReuseTest()
{
//Setup
FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory();
FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2();

//Test
Assert.Throws<FactoryTestObjTesterCleanForReuseCalled>(() => fact.CleanForReuse(new FactoryTestObjTester()), "Factory New didn't work.");
Assert.Throws<FactoryTestObjTesterCleanForReuseCalled2>(() => fact2.CleanForReuse(new FactoryTestObjTester2()), "Factory New didn't work.");
}

//ObjectFactoryTest::ObjCleanForReuse();
Expand All @@ -62,9 +83,24 @@ public void CleanForReuseBaseTest()
{
//Setup
FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory();
FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2();

//Test
Assert.Throws<FactoryTestObjTesterCleanForReuseCalled>(() => fact.ObjCleanForReuse(new FactoryTestObjTester()), "Factory Base New didn't work.");
Assert.Throws<FactoryTestObjTesterCleanForReuseCalled2>(() => 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<InvalidCastException>(() => fact.ObjCleanForReuse(new FactoryTestObjTester2()), "Factory Base New didn't work.");
Assert.Throws<InvalidCastException>(() => fact2.ObjCleanForReuse(new FactoryTestObjTester()), "Factory Base New didn't work.");
}

//ObjectFactoryTest::CreateNew();
Expand All @@ -73,9 +109,11 @@ public void CreateTest()
{
//Setup
FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory();
FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2();

//Test
Assert.Throws<FactoryTestObjTesterCreateNewCalled>(() => fact.CreateNew(), "Factory New didn't work.");
Assert.Throws<FactoryTestObjTesterCreateNewCalled2>(() => fact2.CreateNew(), "Factory New didn't work.");
}

//ObjectFactoryTest::ObjCreateNew();
Expand All @@ -84,9 +122,11 @@ public void CreateObjectTest()
{
//Setup
FactoryTestObjTesterFactory fact = new FactoryTestObjTesterFactory();
FactoryTestObjTesterFactory2 fact2 = new FactoryTestObjTesterFactory2();

//Test
Assert.Throws<FactoryTestObjTesterCreateNewCalled>(() => fact.ObjCreateNew(), "Factory Base New didn't work.");
Assert.Throws<FactoryTestObjTesterCreateNewCalled2>(() => fact2.ObjCreateNew(), "Factory Base New didn't work.");
}
}
}

0 comments on commit 5c92bba

Please sign in to comment.