public async Task Create() { var sut = new GizmosController(_ctx); var maxId = _ctx.Gizmos.Max(r => r.Id); var maxRank = _ctx.Gizmos.Max(r => r.Rank); var gizmo = new Gizmo { Name = "Baz", Rank = maxRank + 1 }; var actual = await sut.Create(gizmo); Assert.Equal(typeof(CreatedAtRouteResult), actual.GetType()); var createdResult = actual as CreatedAtRouteResult; // endpoint returns gizmo Assert.Same(gizmo, createdResult.Value as Gizmo); // endpoint assigns next id to gizmo Assert.True(gizmo.Id > maxId); Assert.Equal(gizmo.Id, _ctx.Gizmos.Max(r => r.Id)); // endpoint returns correct id in route values Assert.Equal(gizmo.Id, createdResult.RouteValues["id"]); }
public async Task CreateBadRequestNull() { var sut = new GizmosController(_ctx); var actual = await sut.Create(null); Assert.Equal(typeof(BadRequestResult), actual.GetType()); }