using TUnit.Assertions.AssertConditions.Throws; namespace IRCSharp.Tests.State; public class Cap { private readonly Server _server = new("test"); [Test] public async Task LSOneLine() { await Assert.That(_server.HasCap).IsFalse(); await Assert.That(_server.AvailableCaps).IsEmpty(); _server.Parse(new Line("CAP * LS :a b")); await Assert.That(_server.AvailableCaps).ContainsKey("a").And.ContainsKey("b"); await Assert.That(_server.AvailableCaps) .IsEquivalentTo(new Dictionary { { "a", "" }, { "b", "" } }); } [Test] public async Task LsTwoLines() { _server.Parse(new Line("CAP * LS * :a b")); await Assert.That(_server.AvailableCaps).IsEmpty(); _server.Parse(new Line("CAP * LS :c")); await Assert.That(_server.AvailableCaps).ContainsKey("a") .And.ContainsKey("b") .And.ContainsKey("c"); } [Test] public async Task LsValues() { _server.Parse(new Line("CAP * LS :a b= c=1")); await Assert.That(_server.AvailableCaps) .IsEquivalentTo(new Dictionary { { "a", "" }, { "b", "" }, { "c", "1" } }); } [Test] public async Task ACKOneLine() { _server.Parse(new Line("CAP * LS :a b")); _server.Parse(new Line("CAP * ACK :a b")); await Assert.That(_server.AgreedCaps).Contains("a").And.Contains("b"); } [Test] public async Task ACKTwoLines() { _server.Parse(new Line("CAP * LS :a b c")); _server.Parse(new Line("CAP * ACK * :a b")); _server.Parse(new Line("CAP * ACK :c")); await Assert.That(_server.AgreedCaps).IsEquivalentTo(["a", "b", "c"]); } [Test] public async Task ACKNotLs() { _server.Parse(new Line("CAP * LS a")); _server.Parse(new Line("CAP * ACK b")); await Assert.That(_server.AgreedCaps).IsEmpty(); } [Test] public async Task NewNoLs() { _server.Parse(new Line("CAP * NEW :a")); await Assert.That(_server.AvailableCaps).IsEquivalentTo(new Dictionary {{"a", ""}}); } [Test] public async Task NewOneLine() { _server.Parse(new Line("CAP * LS :a")); _server.Parse(new Line("CAP * NEW :b")); await Assert.That(_server.AvailableCaps) .IsEquivalentTo(new Dictionary { { "a", "" }, { "b", "" } }); } [Test] public async Task NewTwoLines() { _server.Parse(new Line("CAP * LS :a")); _server.Parse(new Line("CAP * NEW :b c")); await Assert.That(_server.AvailableCaps) .IsEquivalentTo(new Dictionary { { "a", "" }, { "b", "" }, { "c", "" } }); } [Test] public async Task DelNotAcked() { await Assert.That(() => _server.Parse(new Line("CAP * DEL a"))).ThrowsNothing(); } [Test] public async Task DELOneLS() { _server.Parse(new Line("CAP * LS :a")); _server.Parse(new Line("CAP * ACK :a")); _server.Parse(new Line("CAP * DEL :a")); await Assert.That(_server.AvailableCaps).IsEmpty(); await Assert.That(_server.AgreedCaps).IsEmpty(); } [Test] public async Task DelTwoLs() { _server.Parse(new Line("CAP * LS :a b")); _server.Parse(new Line("CAP * ACK :a b")); _server.Parse(new Line("CAP * DEL :a")); await Assert.That(_server.AvailableCaps).IsEquivalentTo(new Dictionary { { "b", "" } }); await Assert.That(_server.AgreedCaps).IsEquivalentTo(["b"]); } [Test] public async Task DelTwoDel() { _server.Parse(new Line("CAP * LS :a b")); _server.Parse(new Line("CAP * ACK :a b")); _server.Parse(new Line("CAP * DEL :a b")); await Assert.That(_server.AvailableCaps).IsEmpty(); await Assert.That(_server.AgreedCaps).IsEmpty(); } }