diff --git a/test/session_test.dart b/test/session_test.dart new file mode 100644 index 0000000..d7192e8 --- /dev/null +++ b/test/session_test.dart @@ -0,0 +1,61 @@ +import "package:test/expect.dart"; +import "package:test/scaffolding.dart"; +import "package:wampproto/serializers.dart"; + +import "package:xconn/exports.dart"; +import "package:xconn/src/types.dart"; + +void main() { + var router = Router()..addRealm("realm1"); + + var serializer = JSONSerializer(); + var clientSideBase = ClientSideLocalBaseSession(1, "realm1", "local", "local", serializer, router); + var serverSideBase = ServerSideLocalBaseSession(1, "realm1", "local", "local", serializer, other: clientSideBase); + + router.attachClient(serverSideBase); + + var session = Session(clientSideBase); + + const procedureName = "io.xconn.test_procedure"; + late Registration registration; + test("register a procedure", () async { + registration = await session.register(procedureName, (inv) { + print("Invocation: args=${inv.args}, kwargs=${inv.kwargs}, details=${inv.details}"); + return Result(args: inv.args, kwargs: inv.kwargs, details: inv.details); + }); + + expect(registration, isA()); + }); + + test("call a procedure", () async { + var args = ["abc", 1]; + var kwargs = {"foo": 1}; + + var result = await session.call(procedureName, args: args, kwargs: kwargs); + expect(result, isA()); + expect(result.args, args); + expect(result.kwargs, kwargs); + expect(result.details, {}); + }); + + test("unregister a procedure", () async { + await session.unregister(registration); + }); + + const topicName = "io.xconn.test_topic"; + late Subscription subscription; + test("subscribe to a topic", () async { + subscription = await session.subscribe(topicName, (event) { + print("Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}"); + }); + expect(subscription, isA()); + }); + + test("publish to a topic", () async { + await session.publish(topicName, args: ["abc"], kwargs: {"one": 1}, options: {"acknowledge": true}); + }); + + test("unsubscribe from a topic", () async { + await session.unsubscribe(subscription); + }); +}