MyTested.WebApi icon indicating copy to clipboard operation
MyTested.WebApi copied to clipboard

1.3.0 breaks tests

Open aueelis opened this issue 4 years ago • 1 comments

We are trying to upgrade an existing project from 1.2.6 to 1.3.0 and are having problems with suddenly breaking tests.

What's the problem with the following test that works in 1.2.6 but not in 1.3.0?

using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using MyTested.WebApi;
using NUnit.Framework;

namespace TestApi.Tests.Controllers
{
    public class ValuesController : ApiController
    {
        [HttpPost]
        [Route("api/value")]
        public async Task<int> GetValue(TestRequest request)
        {
            return await (Task.FromResult(request.Value));
        }
    }

    public class TestRequest
    {
        public int Value { get; set; }
    }

    [TestFixture]
    public class ValuesControllerTest
    {
        [Test]
        public void Has_Correct_Route()
        {
            MyWebApi.Routes()
                .ShouldMap("api/value")
                .WithHttpMethod(HttpMethod.Post)
                .WithJsonContent("{ value: 1 }")
                .To<ValuesController>(c => c.GetValue(new TestRequest { Value = 1 }));
        }
    }
}

aueelis avatar Mar 13 '20 15:03 aueelis

We have a similar issue. With 1.2.6, the following did work:

                MyWebApi
                    .Routes()
                    .ShouldMap(requestUrl)
                    .WithHttpMethod(routesToActionMapPost.ContainsKey(routeActionPair.Key) ? HttpMethod.Post : HttpMethod.Get)
                    .ToAction(routeActionPair.Value);

and now with 1.3.0 it fails with the following error:

Expected route '/api/projects/54?var=20' to match 'Get' action but instead matched ''.

Roemer avatar May 11 '22 20:05 Roemer