<commit_before>﻿using NUnit.Framework;
using CSF.Screenplay.Reporting.Models;
using CSF.Screenplay.Reporting.Html.Tests.Autofixture;
using System.Text;
using System.IO;

namespace CSF.Screenplay.Reporting.Html.Tests
{
  [TestFixture]
  public class HtmlReportWriterTests
  {
    [Test,AutoMoqData]
    public void Write_can_create_a_document_without_crashing([RandomReport] Report report,
                                                             [StringFormat] IObjectFormattingService formatService)
    {
      // Arrange
      using(var writer = GetReportOutput())
      {
        var sut = new HtmlReportWriter(writer, formatService);

        // Act & assert
        Assert.DoesNotThrow(() => sut.Write(report));
      }
    }

    TextWriter GetReportOutput()
    {
      // Uncomment this line to write the report to a file instead of a throwaway string
      //return new StreamWriter("HtmlReportWriterTests.html");

      var sb = new StringBuilder();
      return new StringWriter(sb);
    }
  }
}<commit_msg>WIP #131 - Add two unit tests to reproduce this bug<commit_after>﻿using NUnit.Framework;
using CSF.Screenplay.Reporting.Models;
using CSF.Screenplay.Reporting.Html.Tests.Autofixture;
using System.Text;
using System.IO;
using System.Linq;
using CSF.Screenplay.Actors;
using CSF.Screenplay.Abilities;
using System;
using CSF.Screenplay.Performables;

namespace CSF.Screenplay.Reporting.Html.Tests
{
  [TestFixture]
  public class HtmlReportWriterTests
  {
    [Test,AutoMoqData]
    public void Write_can_create_a_document_without_crashing([RandomReport] Report report,
                                                             [StringFormat] IObjectFormattingService formatService)
    {
      // Arrange
      using(var writer = GetReportOutput())
      {
        var sut = new HtmlReportWriter(writer, formatService);

        // Act & assert
        Assert.DoesNotThrow(() => sut.Write(report));
      }
    }

    [Test,AutoMoqData,Description("Reproduces #131")]
    public void Write_does_not_crash_when_using_ability_with_no_public_methods([RandomReport] Report report,
                                                                               [StringFormat] IObjectFormattingService formatService,
                                                                               IActor actor,
                                                                               PerformanceOutcome outcome)
    {
      // Arrange
      var ability = new AbilityWithOnlyExplicitInterfaceImplementations();
      report.Scenarios.First().Reportables.Add(new GainAbility(actor, outcome, ability));

      using(var writer = GetReportOutput())
      {
        var sut = new HtmlReportWriter(writer, formatService);

        // Act & assert
        Assert.DoesNotThrow(() => sut.Write(report));
      }
    }

    [Test,AutoMoqData,Description("Reproduces #131")]
    public void Write_does_not_crash_when_using_performance_with_no_public_methods([RandomReport] Report report,
                                                                                   [StringFormat] IObjectFormattingService formatService,
                                                                                   IActor actor,
                                                                                   PerformanceOutcome outcome)
    {
      // Arrange
      var performable = new PerformableWithOnlyExplicitInterfaceImplementations();
      report.Scenarios.First().Reportables.Add(new Performance(actor, outcome, performable));

      using(var writer = GetReportOutput())
      {
        var sut = new HtmlReportWriter(writer, formatService);

        // Act & assert
        Assert.DoesNotThrow(() => sut.Write(report));
      }
    }

    TextWriter GetReportOutput()
    {
      // Uncomment this line to write the report to a file instead of a throwaway string
      //return new StreamWriter("HtmlReportWriterTests.html");

      var sb = new StringBuilder();
      return new StringWriter(sb);
    }

    public class AbilityWithOnlyExplicitInterfaceImplementations : IAbility
    {
      void IDisposable.Dispose() { /* Intentional no-op */ }

      string IReportable.GetReport(INamed actor) => "Sample string";
    }

    public class PerformableWithOnlyExplicitInterfaceImplementations : IPerformable
    {
      string IReportable.GetReport(INamed actor) => "Sample string";

      void IPerformable.PerformAs(IPerformer actor) { /* Intentional no-op */ }
    }
  }
}
{'fraction_non_alphanumeric': 0.08181413961760782, 'fraction_numerical': 0.0020008892841262785, 'mean_word_length': 2.0984848484848486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '15951', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1108, 'n_words': 246}