protected string UniqueJaneDoe()
    {
        var unique =
            UserData.From(
                $"{_uniqueId}",
                NameData.From("Jane", "Doe"),
                ContactData.From("*****@*****.**", "+1 212-555-1212"));

        ++_uniqueId;

        string serialized = JsonSerialization.Serialized(unique);

        return(serialized);
    }
    protected string UniqueJohnDoe()
    {
        var id = $"{_uniqueId}";

        if (id.Length == 1)
        {
            id = $"00{id}";
        }
        if (id.Length == 2)
        {
            id = $"0{id}";
        }
        var unique =
            UserData.From(
                id, //"" + uniqueId,
                NameData.From("John", "Doe"),
                ContactData.From("*****@*****.**", "+1 212-555-1212"));

        ++_uniqueId;

        var serialized = JsonSerialization.Serialized(unique);

        return(serialized);
    }
    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. 4
0
 public static UserData From(UserState userState) =>
 new UserData(userState.Id, NameData.From(userState.Name), ContactData.From(userState.Contact));