Skip to content

Commit

Permalink
proxy and engine exception handling
Browse files Browse the repository at this point in the history
also nunit test automation with cake build
  • Loading branch information
rofr committed Jun 17, 2014
1 parent 98a3e17 commit 8b286fa
Show file tree
Hide file tree
Showing 154 changed files with 21,459 additions and 22 deletions.
13 changes: 11 additions & 2 deletions build.csx
Expand Up @@ -31,15 +31,23 @@ Task("Build")
.WithTarget("clean")
.WithTarget("build"));
});

Task("Test")
.IsDependentOn("Build")
.Does( () =>
{
NUnit("./src/*Test*/bin/" + config + "/*.Test*.dll");
});

Task("Copy")
.IsDependentOn("Build")
//.IsDependentOn("Test")
.Does(() =>
{
var pattern = "src/OrigoDB.*/bin/" + config + "/OrigoDB.*";
CopyFiles(pattern, output);
});

Task("Zip")
.IsDependentOn("Copy")
.Does(() =>
Expand All @@ -58,7 +66,8 @@ Task("NuGet")
{
NuGetPack("./OrigoDB.Core.nuspec", new NuGetPackSettings {
Version = version,
OutputDirectory = "./build"
OutputDirectory = "./build",
Symbols = true
});
});

Expand Down
80 changes: 66 additions & 14 deletions src/OrigoDB.Core.UnitTests/ProxyExceptionTests.cs
Expand Up @@ -7,29 +7,81 @@ namespace OrigoDB.Core.Test
[TestFixture]
public class ProxyExceptionTests
{
[Test]
public void ExceptionInProxiedMethodIsPropagated()

ProxyExceptionTestModel _proxy;
Engine<ProxyExceptionTestModel> _engine;
int _callsToExecutíng, _callsToExecuted;

[SetUp]
public void Setup()
{
var cfg = EngineConfiguration.Create().ForIsolatedTest();
var engine = Engine.Create<ProxyExceptionTestModel>(cfg);
var proxy = engine.GetProxy();
int callsToExecutíng = 0, callsToExecuted = 0;
engine.CommandExecuting += (sender, args) => callsToExecutíng++;
engine.CommandExecuted += (sender, args) => callsToExecuted++;
Assert.Throws<CommandAbortedException>(
() => proxy.Throw(new CommandAbortedException())
);
Assert.AreEqual(1, callsToExecutíng);
Assert.AreEqual(0, callsToExecuted);
}
_engine = Engine.Create<ProxyExceptionTestModel>(cfg);
_proxy = _engine.GetProxy();
_callsToExecutíng = 0;
_callsToExecuted = 0;
_engine.CommandExecuting += (sender, args) => _callsToExecutíng++;
_engine.CommandExecuted += (sender, args) => _callsToExecuted++;

}

[Test]
public void CommandAbortedException()
{
try
{
_proxy.ModifyAndThrow(new CommandAbortedException());
}
catch (Exception ex)
{
Assert.IsInstanceOf<CommandAbortedException>(ex);
Assert.AreEqual(1, _callsToExecutíng);
Assert.AreEqual(0, _callsToExecuted);

//verify that the model wasn't rolled back
Assert.AreEqual(1, _proxy.GetState());
return;
}
Assert.Fail("Expected exception");
}

[Test]
public void UnexpectedException()
{
try
{
_proxy.ModifyAndThrow(new ArgumentException());
}
catch (Exception ex)
{
Assert.IsInstanceOf<CommandFailedException>(ex);
Assert.IsNotNull(ex.InnerException, "InnerException was null");
Assert.IsInstanceOf<ArgumentException>(ex.InnerException, "InnerException was not ArgumentException");
Assert.AreEqual(1, _callsToExecutíng, "CommandExecuting was not called");
Assert.AreEqual(0, _callsToExecuted, "CommandExecuted should not have been called");

Assert.AreEqual(0, _proxy.GetState(), "state was not rolled back");
return;
}
Assert.Fail("Expected exception");
}

}


[Serializable]
public class ProxyExceptionTestModel : Model
{
public void Throw(Exception ex)
private int _state;
public void ModifyAndThrow(Exception ex)
{
_state++;
throw ex;
}

public int GetState()
{
return _state;
}
}
}
8 changes: 6 additions & 2 deletions src/OrigoDB.Core/Engine.cs
Expand Up @@ -146,8 +146,12 @@ public object Execute(Command command)
{
exceptionThrown = true;
if (_config.PersistenceMode == PersistenceMode.Journaling) _journalAppender.AppendRollbackMarker();
if (!(ex is CommandAbortedException)) Rollback();
throw;
if (!(ex is CommandAbortedException))
{
Rollback();
ex = new CommandFailedException("Command failed with rollback, see inner exception for details", ex);
}
throw ex;
}
finally
{
Expand Down
1 change: 0 additions & 1 deletion src/OrigoDB.Core/Kernels/OptimisticKernel.cs
Expand Up @@ -25,7 +25,6 @@ public override object ExecuteCommand(Command command)
command.PrepareStub(_model);
_synchronizer.EnterWrite();
return command.ExecuteStub(_model);

}
finally
{
Expand Down
13 changes: 10 additions & 3 deletions src/OrigoDB.Core/Proxy/ProxyCommand.cs
Expand Up @@ -17,9 +17,16 @@ public ProxyCommand(string methodName, object[] inArgs)

public override object Execute(TModel model)
{
var proxyMethod = ProxyMethodMap.MapFor<TModel>().GetProxyMethodInfo(MethodName);
MethodInfo methodInfo = proxyMethod.MethodInfo;
return methodInfo.Invoke(model, Arguments);
try
{
var proxyMethod = ProxyMethodMap.MapFor<TModel>().GetProxyMethodInfo(MethodName);
MethodInfo methodInfo = proxyMethod.MethodInfo;
return methodInfo.Invoke(model, Arguments);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
}
}
Binary file modified tools/Cake/Cake.Common.dll
Binary file not shown.
Binary file modified tools/Cake/Cake.Core.dll
Binary file not shown.
Binary file modified tools/Cake/Cake.exe
Binary file not shown.
Binary file added tools/NUnit-2.6.3/Logo.ico
Binary file not shown.

0 comments on commit 8b286fa

Please sign in to comment.