Exemplo n.º 1
0
        public async Task ParseSingleApodAsync_CorrectContent()
        {
            var httpResponseParser = new HttpResponseParser();
            var input = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(_singleApodExampleContent, Encoding.UTF8, "application/json")
            };

            var expected = new ApodContent()
            {
                Copyright      = "R Jay Gabany",
                Date           = new DateTime(2019, 11, 16),
                Explanation    = "Grand tidal streams of stars seem to surround galaxy NGC 5907. The arcing structures form tenuous loops extending more than 150,000 light-years from the narrow, edge-on spiral, also known as the Splinter or Knife Edge Galaxy.Recorded only in very deep exposures, the streams likely represent the ghostly trail of a dwarf galaxy - debris left along the orbit of a smaller satellite galaxy that was gradually torn apart and merged with NGC 5907 over four billion years ago.Ultimately this remarkable discovery image, from a small robotic observatory in New Mexico, supports the cosmological scenario in which large spiral galaxies, including our own Milky Way, were formed by the accretion of smaller ones. NGC 5907 lies about 40 million light-years distant in the northern constellation Draco.",
                ContentUrlHD   = "https://apod.nasa.gov/apod/image/1911/ngc5907_gabany_rcl.jpg",
                MediaType      = MediaType.Image,
                ServiceVersion = "v1",
                Title          = "The Star Streams of NGC 5907",
                ContentUrl     = "https://apod.nasa.gov/apod/image/1911/ngc5907_gabany_rcl1024.jpg"
            };

            var actual = (await httpResponseParser.ParseSingleApodAsync(input)).Content;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void NotEqualsOperator_InputBNull_ReturnsTrue()
        {
            ApodContent inputA = _exampleContent;
            ApodContent inputB = null;

            Assert.True(inputA != inputB);
        }
Exemplo n.º 3
0
        public void NotEqualsOperator_BothNull_ReturnsFalse()
        {
            ApodContent inputA = null;
            ApodContent inputB = null;

            Assert.False(inputA != inputB);
        }
Exemplo n.º 4
0
        public void EqualsOperator_InputBNull_ReturnsFalse()
        {
            ApodContent inputA = _exampleContent;
            ApodContent inputB = null;

            Assert.False(inputA == inputB);
        }
Exemplo n.º 5
0
        public void EqualsOperator_BothNull_ReturnsTrue()
        {
            ApodContent inputA = null;
            ApodContent inputB = null;

            Assert.True(inputA == inputB);
        }
Exemplo n.º 6
0
 /// <summary>
 /// The default constructor for an <see cref="ApodResponse"/>.
 /// </summary>
 /// <remarks>
 /// Unless you are overriding internal behaviour, you should not need to call this constructor.
 /// </remarks>
 /// <param name="statusCode">The <see cref="StatusCode"/> value.</param>
 /// <param name="allContent">The <see cref="AllContent"/> value.</param>
 /// <param name="error">The <see cref="Error"/> value.</param>
 public ApodResponse(ApodStatusCode statusCode, ApodContent[] allContent = null, ApodError error = null)
 {
     StatusCode = statusCode;
     AllContent = allContent;
     // Set the Content to the latest entry from AllContent
     Content = AllContent?[AllContent.Length > 1 ? AllContent.Length - 1: 0];
     Error   = error;
 }
Exemplo n.º 7
0
        public void ApodResponse_CorrectContent_SingleContent()
        {
            var allContent = new ApodContent[1] {
                _lastContent
            };
            var apodResponse = new ApodResponse(ApodStatusCode.OK, allContent: allContent);

            var expected = _lastContent;

            var actual = apodResponse.Content;

            Assert.Equal(expected.Title, actual.Title);
        }
Exemplo n.º 8
0
        public async ValueTask <ApodResponse> ParseSingleApodAsync(HttpResponseMessage httpResponse)
        {
            ApodContent apodContent = null;

            using (var responseStream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false))
            {
                apodContent = await JsonSerializer.DeserializeAsync <ApodContent>(responseStream, _jsonSerializerOptions).ConfigureAwait(false);
            }

            httpResponse.Dispose();

            var apodArray = new ApodContent[1] {
                apodContent
            };

            return(new ApodResponse(ApodStatusCode.OK, apodArray));
        }
Exemplo n.º 9
0
        public async Task ParseMultipleApodsAsync_CorrectContent()
        {
            var httpResponseParser = new HttpResponseParser();
            var input = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(_multipleApodExampleContent, Encoding.UTF8, "application/json")
            };

            var expected = new ApodContent[]
            {
                new ApodContent()
                {
                    Date           = new DateTime(2006, 11, 07),
                    Explanation    = "Janus is one of the stranger moons of Saturn.First, Janus travels in an unusual orbit around Saturn where it periodically trades places with its sister moon Epimetheus, which typically orbits about 50 kilometers away.Janus, although slightly larger than Epimetheus, is potato-shaped and has a largest diameter of about 190 kilometers.Next, Janus is covered with large craters but strangely appears to lack small craters.One possible reason for this is a fine dust that might cover the small moon, a surface also hypothesized for Pandora and Telesto.Pictured above, Janus was captured in front of the cloud tops of Saturn in late September.",
                    ContentUrlHD   = "https://apod.nasa.gov/apod/image/0611/janus_cassini_big.jpg",
                    MediaType      = MediaType.Image,
                    ServiceVersion = "v1",
                    Title          = "Janus: Potato Shaped Moon of Saturn",
                    ContentUrl     = "https://apod.nasa.gov/apod/image/0611/janus_cassini.jpg"
                },
                new ApodContent()
                {
                    Copyright      = "Misti\nMountain Observatory",
                    Date           = new DateTime(2005, 07, 28),
                    Explanation    = "Ghostly in appearance, Abell 39 is a remarkably simple, spherical nebula about five light-years across. Well within our own Milky Way galaxy, the cosmic sphere is roughly 7,000 light-years distant toward the constellation Hercules. Abell 39 is a planetary nebula, formed as a once sun-like star's outer atmosphere was expelled over a period of thousands of years. Still visible, the nebula's central star is evolving into a hot white dwarf. Although faint, the nebula's simple geometry has proven to be a boon to astronomers exploring the chemical abundances and life cycles of stars. In this deep image recorded under dark night skies, very distant background galaxies can be found -- some visible right through the nebula itself.",
                    ContentUrlHD   = "https://apod.nasa.gov/apod/image/0507/abell39_misti_f.jpg",
                    MediaType      = MediaType.Image,
                    ServiceVersion = "v1",
                    Title          = "Spherical Planetary Nebula Abell 39",
                    ContentUrl     = "https://apod.nasa.gov/apod/image/0507/abell39_misti_c50.jpg"
                }
            };

            var actual = (await httpResponseParser.ParseMultipleApodsAsync(input)).AllContent;

            Assert.Equal(expected, actual);
            Assert.Equal(expected[1], actual[1]);
        }