using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Models.Dtos;

namespace Tests.UnitTests.DocumentTests {
    [TestFixture]
    public class WineQualityStatisticsTest {

        [Test]
        public async Task Test_01_AllDeliveries2020() {
            using var ctx = new AppDbContext();
            var data = await WineQualityStatisticsData.FromQuery(ctx.Deliveries.Where(d => d.Year == 2020).SelectMany(d => d.Parts));
            using var doc = new WineQualityStatistics("Saison 2020", data);
            var text = await Utils.GeneratePdfText(doc);
            Assert.Multiple(() => {
                Assert.That(text, Contains.Substring("Qualitätsstatistik"));
                Assert.That(text, Contains.Substring("Saison 2020"));
                Assert.That(text, Contains.Substring("""
                    Wein
                    75 1 2 561
                    78 1 2 901
                    79 1 1 280
                    80 1 3 198
                    87 1 3 129
                    """));
                Assert.That(text, Contains.Substring("""
                    Qualitätswein
                    73 2 4 431
                    74 2 4 203
                    75 2 2 615
                    77 1 842
                    82 1 4 002
                    """));
                Assert.That(text, Contains.Substring("""
                    Kabinett
                    84 3 8 960
                    85 3 11 181
                    86 1 2 987
                    87 1 1 873
                    89 2 4 723
                    """));
                Assert.That(text, Contains.Substring(
                    "80 5 " + "13 069 " +
                    "- 0 0 " +
                    "77 5 " + "11 568 " +
                    "85 6 " + "17 561"));
            });
        }
    }
}
