using System.Collections.Generic;
using NUnit.Framework;

namespace eagle0.Tests {
    [TestFixture]
    public class ClientTextProviderTests {
        [Test]
        public void ChangedStreamAttemptReplacesPreviouslyDeliveredBytes() {
            var provider = new eagle.ClientTextProvider();
            provider.HandleNewStreamingText(
                    "chronicle",
                    "Old partial prefix",
                    0,
                    false,
                    "old-attempt");

            var updated = provider.HandleNewStreamingText(
                    "chronicle",
                    "New replacement text",
                    17,
                    false,
                    "retry-attempt");

            Assert.AreEqual("New replacement text", updated);
            Assert.AreEqual("retry-attempt", provider.GetTextEntry("chronicle").StreamAttemptId);
        }

        [Test]
        public void CachedCompletedTextsIgnoreEntriesWithoutContent() {
            var provider = new eagle.ClientTextProvider();

            provider.ReplaceWithCachedCompletedTexts(new Dictionary<string, string> {
                { "empty-backstory", "" },
                { "complete-backstory", "A completed backstory." }
            });

            Assert.IsFalse(provider.All().ContainsKey("empty-backstory"));
            Assert.AreEqual(
                    "A completed backstory.",
                    provider.GetTextEntry("complete-backstory").Text);
        }
    }
}
