Added more tests for event.d
This commit is contained in:
parent
59ac47c555
commit
e7e135d7ea
2 changed files with 68 additions and 9 deletions
8
dub.json
8
dub.json
|
@ -4,8 +4,8 @@
|
||||||
"Johannes Loher"
|
"Johannes Loher"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vibe-d": "0.8.1",
|
"vibe-d": "~>0.8.1",
|
||||||
"poodinis": "8.0.1"
|
"poodinis": "~>8.0.1"
|
||||||
},
|
},
|
||||||
"description": "A simple webapplication to edit and view calendar entries",
|
"description": "A simple webapplication to edit and view calendar entries",
|
||||||
"copyright": "Copyright © 2017, Johannes Loher",
|
"copyright": "Copyright © 2017, Johannes Loher",
|
||||||
|
@ -26,8 +26,8 @@
|
||||||
"mainSourceFile": "generated/ut.d",
|
"mainSourceFile": "generated/ut.d",
|
||||||
"sourcePaths": ["test"],
|
"sourcePaths": ["test"],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"unit-threaded": "0.7.30"
|
"unit-threaded": "~>0.7.31"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"versions": [
|
"versions": [
|
||||||
|
|
|
@ -4,6 +4,9 @@ import calendarwebapp.event;
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
|
import std.array;
|
||||||
|
import std.algorithm : map;
|
||||||
|
|
||||||
import unit_threaded.mock;
|
import unit_threaded.mock;
|
||||||
import unit_threaded.should;
|
import unit_threaded.should;
|
||||||
|
|
||||||
|
@ -35,7 +38,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Test failing getEventMongoDBEventStore.getEvent")
|
@("getEventMongoDBEventStore.getEvent failure")
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
auto collection = mock!Collection;
|
auto collection = mock!Collection;
|
||||||
|
@ -55,7 +58,7 @@ public:
|
||||||
collection.verify;
|
collection.verify;
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Test successful MongoDBEventStore.getEvent")
|
@("MongoDBEventStore.getEvent success")
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
auto collection = mock!Collection;
|
auto collection = mock!Collection;
|
||||||
|
@ -78,7 +81,7 @@ public:
|
||||||
collection.verify;
|
collection.verify;
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Test MongoDBEventStore.addEvent")
|
@("MongoDBEventStore.addEvent")
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
auto collection = mock!Collection;
|
auto collection = mock!Collection;
|
||||||
|
@ -93,7 +96,7 @@ public:
|
||||||
event.id = id;
|
event.id = id;
|
||||||
auto serializedEvent = event.serializeToBson;
|
auto serializedEvent = event.serializeToBson;
|
||||||
|
|
||||||
collection.returnValue!"findOne"(Bson(null), event.serializeToBson);
|
collection.returnValue!"findOne"(Bson(null), serializedEvent);
|
||||||
|
|
||||||
collection.expect!"findOne"(["_id" : id]);
|
collection.expect!"findOne"(["_id" : id]);
|
||||||
collection.expect!"insert"(serializedEvent);
|
collection.expect!"insert"(serializedEvent);
|
||||||
|
@ -107,3 +110,59 @@ public:
|
||||||
|
|
||||||
collection.verify;
|
collection.verify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@("MongoDBEventStore.removeEvent")
|
||||||
|
@system unittest
|
||||||
|
{
|
||||||
|
auto collection = mock!Collection;
|
||||||
|
auto container = new shared DependencyContainer;
|
||||||
|
container.register!(ValueInjector!Collection, CollectionInjector);
|
||||||
|
container.resolve!CollectionInjector.add("events", collection);
|
||||||
|
container.register!(EventStore, MongoDBEventStore!(Collection))(
|
||||||
|
RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||||
|
|
||||||
|
auto id = BsonObjectID.fromString("599090de97355141140fc698");
|
||||||
|
Event event;
|
||||||
|
event.id = id;
|
||||||
|
|
||||||
|
collection.returnValue!"findOne"(event.serializeToBson, Bson(null));
|
||||||
|
|
||||||
|
collection.expect!"findOne"(["_id" : id]);
|
||||||
|
collection.expect!"remove"(["_id" : id]);
|
||||||
|
collection.expect!"findOne"(["_id" : id]);
|
||||||
|
|
||||||
|
auto eventStore = container.resolve!(EventStore);
|
||||||
|
|
||||||
|
eventStore.getEvent(id).shouldEqual(event);
|
||||||
|
eventStore.removeEvent(event.id);
|
||||||
|
eventStore.getEvent(id).shouldThrowWithMessage!Exception("Expected object instead of null_");
|
||||||
|
|
||||||
|
collection.verify;
|
||||||
|
}
|
||||||
|
|
||||||
|
@("MongoDBEventStore.getAllEvents")
|
||||||
|
@system unittest
|
||||||
|
{
|
||||||
|
auto collection = mock!Collection;
|
||||||
|
auto container = new shared DependencyContainer;
|
||||||
|
container.register!(ValueInjector!Collection, CollectionInjector);
|
||||||
|
container.resolve!CollectionInjector.add("events", collection);
|
||||||
|
container.register!(EventStore, MongoDBEventStore!(Collection))(
|
||||||
|
RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||||
|
|
||||||
|
immutable ids = [
|
||||||
|
BsonObjectID.fromString("599090de97355141140fc698"), BsonObjectID.fromString("599090de97355141140fc698"),
|
||||||
|
BsonObjectID.fromString("59cb9ad8fc0ba5751c0df02b")
|
||||||
|
];
|
||||||
|
auto events = ids.map!(id => Event(id)).array;
|
||||||
|
|
||||||
|
collection.returnValue!"find"(events.map!serializeToBson.array);
|
||||||
|
|
||||||
|
collection.expect!"find"();
|
||||||
|
|
||||||
|
auto eventStore = container.resolve!(EventStore);
|
||||||
|
|
||||||
|
eventStore.getAllEvents.array.shouldEqual(events);
|
||||||
|
|
||||||
|
collection.verify;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue