Example #1
0
        public async Task Dispatch_Command_ReplyReturned()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();

            var cmd = new TestCommand
            {
                Value = Guid.NewGuid().ToString()
            };

            var request = new RequestEnvelope()
            {
                Type = cmd.GetType().AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(cmd))
            };

            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull().Data.ShouldNotBeNull().ShouldNotBeEmpty();
            var responseType = System.Type.GetType(response.Type, an => Assembly.Load(an.Name ?? null !), null, true, true).ShouldNotBeNull();

            using var ms = new MemoryStream(response.Data.ToByteArray());
            JsonSerializer.Deserialize(ms, responseType).ShouldBeOfType <string>().ShouldBe(cmd.Value);
        }
Example #2
0
        public async Task Dispatch_Command_ReplyReturned()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();

            var cmd = new TestCommand
            {
                Value = Guid.NewGuid().ToString()
            };

            var request = new RequestEnvelope()
            {
                Type    = cmd.GetType().AssemblyQualifiedName,
                Content = Value.Parser.ParseJson(JsonSerializer.Serialize(cmd))
            };

            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull().Content.ShouldNotBeNull();
            var responseType = System.Type.GetType(response.Type, an => Assembly.Load(an.Name ?? null !), null, true, true).ShouldNotBeNull();

            JsonSerializer.Deserialize(JsonFormatter.Default.Format(response.Content), responseType).ShouldBeOfType <string>().ShouldBe(cmd.Value);
        }
Example #3
0
        public async Task CanSerializeErrors()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var request    = new RequestEnvelope()
            {
                Type = typeof(TestThrowErrorCommand).AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(new TestThrowErrorCommand()))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull();
        }
Example #4
0
        public async Task Dispatch_CommandWithNoReply_EmptyResponseType()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var cmd        = new TestCommandNoReturnValue();

            RequestEnvelope request = new RequestEnvelope()
            {
                Type    = cmd.GetType().AssemblyQualifiedName,
                Content = Value.Parser.ParseJson(JsonSerializer.Serialize(cmd))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.Type.ShouldBeNullOrEmpty();
            response.Content.ShouldBe(Value.ForNull());
        }
Example #5
0
        public async Task Dispatch_CommandWithNoReply_EmptyResponseType()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var cmd        = new TestCommandNoReturnValue();

            RequestEnvelope request = new RequestEnvelope()
            {
                Type = cmd.GetType().AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(cmd))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.Error.ShouldBeFalse();
            response.Type.ShouldBeNullOrEmpty();
            response.Data.IsEmpty.ShouldBeTrue();
        }