private static void StreamNonGenericNullTest(IStreamSerializer serializer)
    {
        var type             = typeof(TestModel);
        var stream           = serializer.ToStream(type, null);
        var deserializeModel = serializer.FromStream(type, stream);

        Assert.Null(deserializeModel);
    }
Example #2
0
    private static void StreamGenericNullTest(IStreamSerializer serializer)
    {
        TestModel?model            = null;
        var       stream           = serializer.ToStream(model);
        var       deserializeModel = serializer.FromStream <TestModel>(stream);

        Assert.Null(deserializeModel);
    }
Example #3
0
    private static void StreamGenericTest(IStreamSerializer serializer, TestModel model)
    {
        var stream           = serializer.ToStream(model);
        var deserializeModel = serializer.FromStream <TestModel>(stream) !;

        Assert.Equal(
            Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender),
            Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime,
                         deserializeModel.Name, deserializeModel.Gender));
    }
Example #4
0
    private static void StreamNonGenericTest(IStreamSerializer serializer, TestModel model)
    {
        var type             = typeof(TestModel);
        var ms               = serializer.ToStream(type, model);
        var deserializeModel = (TestModel)serializer.FromStream(type, ms) !;

        Assert.Equal(
            Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender),
            Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime,
                         deserializeModel.Name, deserializeModel.Gender));
    }
    public async Task StreamFormatterNullAsync(IStreamSerializer streamSerializer, string mediaType)
    {
        var httpRequestMessage = CreateHttpRequestMessage(
            new StreamContent(streamSerializer.ToStream <List <TestDto> >(null)),
            mediaType);

        var response = await _server.CreateClient().SendAsync(httpRequestMessage);

        var result = streamSerializer.FromStream <List <TestDto> >(await response.Content.ReadAsStreamAsync());

        Assert.Null(result);
    }
    public async Task StreamFormatterAsync(IStreamSerializer streamSerializer, string mediaType)
    {
        var dtos = GetDtos();

        var httpRequestMessage = CreateHttpRequestMessage(
            new StreamContent(streamSerializer.ToStream(dtos)),
            mediaType);

        var response = await _server.CreateClient().SendAsync(httpRequestMessage);

        var result = streamSerializer.FromStream <List <TestDto> >(await response.Content.ReadAsStreamAsync());

        Assert.True(CompareDtos(dtos, result));
    }
    public override async Task <object?> GetResultAsync(Type returnType, HttpResponseMessage httpResponseMessage)
    {
        var result = await httpResponseMessage.Content.ReadAsStreamAsync();

        var type = returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task <>)
            ? returnType.GenericTypeArguments[0]
            : returnType;

        if (httpResponseMessage.IsSuccessStatusCode)
        {
            return(_serializer.FromStream(type, result));
        }

        var zaabyError = _serializer.FromStream <ZaabyError>(result) !;

        throw new ZaabyException(zaabyError.Message, zaabyError.StackTrace)
              {
                  Id        = zaabyError.Id,
                  Code      = zaabyError.Code,
                  ThrowTime = zaabyError.ThrowTime,
                  Source    = zaabyError.Source
              };
    }