public void TestThatGetUserDispatches()
    {
        var postRequest            = Request.From(ConsumerByteBuffer(PostJohnDoeUserMessage));
        var postCompletes          = new MockCompletesEventuallyResponse();
        var postCompletesWithCalls = postCompletes.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(postRequest, postCompletes));
        postCompletesWithCalls.ReadFrom <int>("completed");
        Assert.NotNull(postCompletes.Response);

        var getUserMessage        = $"GET {postCompletes.Response.Get().HeaderOf(ResponseHeader.Location).Value} HTTP/1.1\nHost: vlingo.io\n\n";
        var getRequest            = Request.From(ConsumerByteBuffer(getUserMessage));
        var getCompletes          = new MockCompletesEventuallyResponse();
        var getCompletesWithCalls = getCompletes.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(getRequest, getCompletes));
        getCompletesWithCalls.ReadFrom <int>("completed");
        Assert.NotNull(getCompletes.Response);
        Assert.Equal(ResponseStatus.Ok, getCompletes.Response.Get().Status);
        var getUserData = JsonSerialization.Deserialized <UserData>(getCompletes.Response.Get().Entity.Content, _settings);

        Assert.NotNull(getUserData);
        Assert.Equal(JohnDoeUserData.NameData.Given, getUserData.NameData.Given);
        Assert.Equal(JohnDoeUserData.NameData.Family, getUserData.NameData.Family);
        Assert.Equal(JohnDoeUserData.ContactData.EmailAddress, getUserData.ContactData.EmailAddress);
        Assert.Equal(JohnDoeUserData.ContactData.TelephoneNumber, getUserData.ContactData.TelephoneNumber);
    }
Esempio n. 2
0
        public void TestThatDispatchesThroughPool()
        {
            for (var count = 0; count < 3; ++count)
            {
                var request   = Request.From(ToStream(_postDataMessage).ToArray());
                var completes = new MockCompletesEventuallyResponse();

                var outcomes = completes.ExpectWithTimes(1);
                _dispatcher.DispatchFor(new Context(request, completes));
                var responseCount = outcomes.ReadFrom <int>("completed");
                var response      = outcomes.ReadFrom <Response>("response");
                Assert.Equal(1, responseCount);

                var responseData = JsonSerialization.Deserialized <Data>(response.Entity.Content);

                Assert.Equal(TestData1, responseData);

                _output.WriteLine("previousResourceHandlerId={0} resourceHandlerId={1}", _previousResourceHandlerId,
                                  responseData.ResourceHandlerId);

                Assert.NotEqual(_previousResourceHandlerId, responseData.ResourceHandlerId);

                _previousResourceHandlerId = responseData.ResourceHandlerId;
            }
        }
    public void TestThatPostRegisterUserDispatches()
    {
        var request   = Request.From(ConsumerByteBuffer(PostJohnDoeUserMessage));
        var completes = new MockCompletesEventuallyResponse();

        var withCalls = completes.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(request, completes));
        withCalls.ReadFrom <int>("completed");

        Assert.NotNull(completes.Response);

        Assert.Equal(ResponseStatus.Created, completes.Response.Get().Status);
        Assert.Equal(2, completes.Response.Get().Headers.Count);
        Assert.Equal(ResponseHeader.Location, completes.Response.Get().Headers[0].Name);
        Assert.StartsWith("/users/", completes.Response.Get().HeaderOf(ResponseHeader.Location).Value);
        Assert.NotNull(completes.Response.Get().Entity);

        var createdUserData = (UserData)JsonSerialization.Deserialized(completes.Response.Get().Entity.Content, typeof(UserData), _settings);

        Assert.NotNull(createdUserData);
        Assert.Equal(JohnDoeUserData.NameData.Given, createdUserData.NameData.Given);
        Assert.Equal(JohnDoeUserData.NameData.Family, createdUserData.NameData.Family);
        Assert.Equal(JohnDoeUserData.ContactData.EmailAddress, createdUserData.ContactData.EmailAddress);
        Assert.Equal(JohnDoeUserData.ContactData.TelephoneNumber, createdUserData.ContactData.TelephoneNumber);
    }
        public object From(string data, Type type)
        {
            if (type == typeof(string))
            {
                return(data);
            }

            return(JsonSerialization.Deserialized(data, type));
        }
Esempio n. 5
0
        public static ExpressionSerializationInfo Deserialize(string serialized)
        {
            var deserialized = JsonSerialization.Deserialized <ExpressionSerializationInfo>(serialized);
            var i            = 0;

            foreach (var arg in deserialized.Args)
            {
                if (arg is JObject jobject && deserialized.Types.Length >= i)
                {
                    deserialized.Args[i] = jobject.ToObject(deserialized.Types[i] !);
                }
 public override object FromRawState(TextState raw)
 {
     try
     {
         var stateType = Type.GetType(raw.Type);
         return(JsonSerialization.Deserialized(raw.Data, stateType) !);
     }
     catch (Exception)
     {
         throw new InvalidOperationException($"Cannot convert to type: {raw.Type}");
     }
 }
 public ProcessMessage FromEntry(TextEntry entry)
 {
     try
     {
         var serializedMessage = JsonSerialization.Deserialized <SerializableProcessMessage>(entry.EntryData);
         var source            = JsonSerialization.Deserialized <ISource>(serializedMessage.Source);
         return(new ProcessMessage(source));
     }
     catch (Exception e)
     {
         throw new InvalidOperationException($"ProcessMessageTextAdapter failed because: {e.Message}", e);
     }
 }
Esempio n. 8
0
 public override TState FromEntry(TextEntry entry)
 {
     try
     {
         var sourceType = Type.GetType(entry.TypeName);
         var bland      = JsonSerialization.Deserialized(entry.EntryData, sourceType);
         return((TState)bland !);
     }
     catch (Exception)
     {
         throw new InvalidOperationException($"Cannot convert to type: {entry.TypeName}");
     }
 }
Esempio n. 9
0
        public void TestWriteReadJson()
        {
            ActorProxyBase <IProto> proxy = new ActorProxyBaseImpl(
                Definition.Has <Actor>(Definition.NoParameters), new TestAddress(1));

            var serialized = JsonSerialization.Serialized(proxy);

            var settings = new JsonSerializerSettings();

            settings.Converters.Add(new TestAddressConverter());
            var deserialized = JsonSerialization.Deserialized <ActorProxyBaseImpl>(serialized, settings);

            Assert.Equal(typeof(IProto), deserialized.Protocol);
            Assert.Equal(typeof(Actor), deserialized.Definition.Type);
            Assert.Equal(Definition.NoParameters, deserialized.Definition.Parameters);
            Assert.Equal(1, deserialized.Address.Id);
        }
Esempio n. 10
0
        public static ExpressionSerializationInfo Deserialize <TProtocol>(string serialized)
        {
            var deserialized = JsonSerialization.Deserialized <ExpressionSerializationInfo>(serialized);
            var i            = 0;

            foreach (var arg in deserialized.Args)
            {
                if (arg is JObject jobject)
                {
                    deserialized.Args[i] = jobject.ToObject(deserialized.Types[i]) !;
                }
                // special case as underlying serializer converts ints to longs en deserialization
                else if (arg is long && arg.GetType() != deserialized.Types[i])
                {
                    deserialized.Args[i] = int.Parse(arg.ToString());
                }

                i++;
            }

            return(deserialized);
        }
Esempio n. 11
0
 public object From(string data, Type type) => JsonSerialization.Deserialized(data, type);
Esempio n. 12
0
 public override TOtherState FromRawState <TOtherState>(TextState raw) => JsonSerialization.Deserialized <TOtherState>(raw.Data);
Esempio n. 13
0
 public override Entity1 FromRawState(TextState raw) => JsonSerialization.Deserialized <Entity1>(raw.Data);
 public override TOtherState FromRawState <TOtherState>(TextState raw) =>
 (TOtherState)JsonSerialization.Deserialized(raw.Data, typeof(TOtherState)) !;
 public TOtherState FromRawState <TOtherState>(IState raw) => JsonSerialization.Deserialized <TOtherState>(raw.RawData);
    public void TestThatPatchNameWorks()
    {
        _output.WriteLine("TestThatPatchNameWorks()");
        var postRequest1            = Request.From(ConsumerByteBuffer(PostJohnDoeUserMessage));
        var postCompletes1          = new MockCompletesEventuallyResponse();
        var postCompletes1WithCalls = postCompletes1.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(postRequest1, postCompletes1));
        postCompletes1WithCalls.ReadFrom <int>("completed");

        Assert.NotNull(postCompletes1.Response);
        _output.WriteLine("1");

        var postRequest2   = Request.From(ConsumerByteBuffer(PostJaneDoeUserMessage));
        var postCompletes2 = new MockCompletesEventuallyResponse();

        var postCompletes2WithCalls = postCompletes2.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(postRequest2, postCompletes2));
        postCompletes2WithCalls.ReadFrom <int>("completed");

        Assert.NotNull(postCompletes2.Response);
        _output.WriteLine("2");

        // John Doe and Jane Doe marry and change their family name to, of course, Doe-Doe
        var johnNameData            = NameData.From("John", "Doe-Doe");
        var johnNameSerialized      = JsonSerialization.Serialized(johnNameData);
        var patchJohnDoeUserMessage =
            $"PATCH {postCompletes1.Response.Get().HeaderOf(ResponseHeader.Location).Value}" +
            $"/name HTTP/1.1\nHost: vlingo.io\nContent-Length: {johnNameSerialized.Length}" +
            $"\n\n{johnNameSerialized}";

        _output.WriteLine($"2.0: {patchJohnDoeUserMessage}");
        var patchRequest1   = Request.From(ConsumerByteBuffer(patchJohnDoeUserMessage));
        var patchCompletes1 = new MockCompletesEventuallyResponse();

        var patchCompletes1WithCalls = patchCompletes1.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(patchRequest1, patchCompletes1));
        patchCompletes1WithCalls.ReadFrom <int>("completed");

        Assert.NotNull(patchCompletes1.Response);
        Assert.Equal(ResponseStatus.Ok, patchCompletes1.Response.Get().Status);
        var getJohnDoeDoeUserData = JsonSerialization.Deserialized <UserData>(patchCompletes1.Response.Get().Entity.Content, _settings);

        Assert.Equal(johnNameData.Given, getJohnDoeDoeUserData.NameData.Given);
        Assert.Equal(johnNameData.Family, getJohnDoeDoeUserData.NameData.Family);
        Assert.Equal(JohnDoeUserData.ContactData.EmailAddress, getJohnDoeDoeUserData.ContactData.EmailAddress);
        Assert.Equal(JohnDoeUserData.ContactData.TelephoneNumber, getJohnDoeDoeUserData.ContactData.TelephoneNumber);

        var janeNameData            = NameData.From("Jane", "Doe-Doe");
        var janeNameSerialized      = JsonSerialization.Serialized(janeNameData);
        var patchJaneDoeUserMessage =
            $"PATCH {postCompletes2.Response.Get().HeaderOf(ResponseHeader.Location).Value}" +
            $"/name HTTP/1.1\nHost: vlingo.io\nContent-Length: {janeNameSerialized.Length}" +
            $"\n\n{janeNameSerialized}";

        var patchRequest2   = Request.From(ConsumerByteBuffer(patchJaneDoeUserMessage));
        var patchCompletes2 = new MockCompletesEventuallyResponse();

        var patchCompletes2WithCalls = patchCompletes2.ExpectWithTimes(1);

        Dispatcher.DispatchFor(new Context(patchRequest2, patchCompletes2));
        patchCompletes2WithCalls.ReadFrom <int>("completed");

        Assert.NotNull(patchCompletes2.Response);
        Assert.Equal(ResponseStatus.Ok, patchCompletes2.Response.Get().Status);
        var getJaneDoeDoeUserData = JsonSerialization.Deserialized <UserData>(patchCompletes2.Response.Get().Entity.Content);

        Assert.Equal(janeNameData.Given, getJaneDoeDoeUserData.NameData.Given);
        Assert.Equal(janeNameData.Family, getJaneDoeDoeUserData.NameData.Family);
        Assert.Equal(JaneDoeUserData.ContactData.EmailAddress, getJaneDoeDoeUserData.ContactData.EmailAddress);
        Assert.Equal(JaneDoeUserData.ContactData.TelephoneNumber, getJaneDoeDoeUserData.ContactData.TelephoneNumber);
    }
Esempio n. 17
0
 public SnapshotState FromRawState(TextState raw) => (SnapshotState)JsonSerialization.Deserialized(raw.Data, raw.Typed);
Esempio n. 18
0
 public override DoCommand1 FromEntry(TextEntry entry) => JsonSerialization.Deserialized <DoCommand1>(entry.EntryRawData);
Esempio n. 19
0
 public override Test2Happened FromEntry(TextEntry entry)
 {
     return(JsonSerialization.Deserialized <Test2Happened>(entry.EntryRawData));
 }
Esempio n. 20
0
 public override Test2Source FromEntry(TextEntry entry) => JsonSerialization.Deserialized <Test2Source>(entry.EntryData);
 public T Payload <T>() => JsonSerialization.Deserialized <T>(_payload);
Esempio n. 22
0
 public override Test1Source FromEntry(IEntry entry) => JsonSerialization.Deserialized <Test1Source>(entry.EntryRawData);
Esempio n. 23
0
 public override DoStepFour FromEntry(TextEntry entry) =>
 JsonSerialization.Deserialized <DoStepFour>(entry.EntryRawData);