namespace Tests
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using API;
    using API.Controllers;
    using FluentAssertions;
    using Microsoft.AspNetCore.Mvc;
    using MyTested.AspNetCore.Mvc;
    using MyTested.AspNetCore.Mvc.Utilities.Extensions;
    using Xunit;


    public class WeatherForecastControllerTests
    {
        [Fact]
        public void ListShouldReturnWeatherForecastItems_Variant_1()
            => MyController<WeatherForecastController>
                .Instance()
                .Calling(c => c.Get())
                .ShouldReturn()
                .ActionResult<IEnumerable<WeatherForecast>>(result =>
                {
                    result.Passing(model => model.Count().Should().Be(5));
                });
        
        [Fact]
        public void ListShouldReturnWeatherForecastItems_Variant_2()
            => MyController<WeatherForecastController>
                .Instance()
                .Calling(c => c.Get())
                .ShouldReturn()
                .ResultOfType<Task<ActionResult<IEnumerable<WeatherForecast>>>>(x =>
                {
                    x.Passing(task =>
                    {
                        var result = task.Result.Value;
                            result.Count().Should().Be(5);
                    });
                });
        
        [Fact]
        public void ListShouldReturnWeatherForecastItems_Variant_3()
            => MyController<WeatherForecastController>
                .Instance()
                .Calling(c => c.Get())
                .ShouldReturn()
                .ResultOfType<ObjectResult>(x =>
                {
                    x.Passing(objectResult =>
                    {
                        objectResult.Should().TryCastTo<IEnumerable<WeatherForecast>>();

                        var result = (IEnumerable<WeatherForecast>)objectResult.Value;
                        result.Count().Should().Be(5);
                    });
                });

        [Fact]
        public void ListShouldReturnWeatherForecastItems_Variant_4()
            => MyController<WeatherForecastController>
                .Instance()
                .Calling(c => c.Get())
                .ShouldReturn()
                .Object(result => result.WithModelOfType<IEnumerable<WeatherForecast>>()
                    .Passing(model => model.Count().Should().Be(5)));
    }
}