public void GivenAValidEntityId_WhenRequestingTheEntityById_TheEntityIsReturned() { var fakeEntities = Enumerable.Range(0, 100) .Select(id => new Entity { Id = id }); var targetId = 5; contextMock.SetupGet(r => r.Entities).Returns(fakeEntities.ToDbSet()); var result = entitiesController.GetEntity(targetId) as JsonResult; Assert.IsInstanceOfType(result, typeof(JsonResult)); var entity = result.Value as Entity; Assert.IsInstanceOfType(entity, typeof(Entity)); Assert.AreEqual(targetId, entity.Id); }