Added more tests for event.d

This commit is contained in:
Johannes Loher 2017-09-27 14:53:50 +02:00
parent 59ac47c555
commit e7e135d7ea
2 changed files with 68 additions and 9 deletions

View file

@ -4,8 +4,8 @@
"Johannes Loher"
],
"dependencies": {
"vibe-d": "0.8.1",
"poodinis": "8.0.1"
"vibe-d": "~>0.8.1",
"poodinis": "~>8.0.1"
},
"description": "A simple webapplication to edit and view calendar entries",
"copyright": "Copyright © 2017, Johannes Loher",
@ -26,11 +26,11 @@
"mainSourceFile": "generated/ut.d",
"sourcePaths": ["test"],
"dependencies": {
"unit-threaded": "0.7.30"
}
"unit-threaded": "~>0.7.31"
}
}
],
"versions": [
"VibeUseOpenSSL11"
]
}
}

View file

@ -4,6 +4,9 @@ import calendarwebapp.event;
import poodinis;
import std.array;
import std.algorithm : map;
import unit_threaded.mock;
import unit_threaded.should;
@ -35,7 +38,7 @@ public:
}
}
@("Test failing getEventMongoDBEventStore.getEvent")
@("getEventMongoDBEventStore.getEvent failure")
@system unittest
{
auto collection = mock!Collection;
@ -55,7 +58,7 @@ public:
collection.verify;
}
@("Test successful MongoDBEventStore.getEvent")
@("MongoDBEventStore.getEvent success")
@system unittest
{
auto collection = mock!Collection;
@ -78,7 +81,7 @@ public:
collection.verify;
}
@("Test MongoDBEventStore.addEvent")
@("MongoDBEventStore.addEvent")
@system unittest
{
auto collection = mock!Collection;
@ -93,7 +96,7 @@ public:
event.id = id;
auto serializedEvent = event.serializeToBson;
collection.returnValue!"findOne"(Bson(null), event.serializeToBson);
collection.returnValue!"findOne"(Bson(null), serializedEvent);
collection.expect!"findOne"(["_id" : id]);
collection.expect!"insert"(serializedEvent);
@ -107,3 +110,59 @@ public:
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;
}