mercredi 2 mai 2018

Why do I get this error in C# test?

I'm trying to perform a controller test but I get the following code on line 19: "To fix this error either change JSON to a JSON object or change the deserialized type to an aray or a type that implements a collection interface that can be deserialized from a JSON array".

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Koa.Hosting.AspNetCore.Model;
using Newtonsoft.Json;
using PING.Business.Model;
using Xunit;

namespace PING.Api.Test.Controller
{
    public class ComentarioControllerTest : BaseTest
    {
        public ComentarioControllerTest(CompositionRootFixture fixture) : base(fixture)
        {
        }

        [Fact]
        public async Task GetAllTest()
        {
            // Act
            var response = await this.Fixture.Client.GetAsync("/api/Comentario");
            response.EnsureSuccessStatusCode();

            // Assert
            var content = await response.Content.ReadAsStringAsync();
            Assert.False(string.IsNullOrWhiteSpace(content));

            var models = JsonConvert.DeserializeObject<EnvelopedModel<ComentarioModel>>(content);
            Assert.NotNull(models);
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire