Unit Testing Issue

samSol 1 Reputation point
2021-06-03T15:50:36.433+00:00

Dear All,

I want to add Unit testing functionality for my following code

public class MyImage
    {
        public string ImageID { get; set; }
        public string ImageFullName { get; set; }
        public string ImageURL { get; set; }
        public string ImageDimensions { get; set; }
    }
[Route("api/[controller]")]
    [ApiController]
    public class ImageController : ControllerBase
    {
        [HttpGet("{id}")]
        public string Get(string date)
        {
            string result = string.Empty;
            var url = "https://myurl.com";
            var httpRequest = (HttpWebRequest)WebRequest.Create(url);
            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                result = streamReader.ReadToEnd();

            }
            return result;
        }

    }

Any help would be greatly appreciated

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,207 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes