using Elwig.Helpers.Weighing;

namespace Tests.WeighingTests {
    [TestFixture]
    public class ScaleTestBadenL320 {

        private EventMockScale Mock;
        private AveryEventScale Scale;

        [OneTimeSetUp]
        public void SetupScale() {
            Mock = new EventMockScale(12345, ScaleHandlers.Handle_L320);
            Scale = new("1", "L320", "tcp://127.0.0.1:12345");
        }

        [OneTimeTearDown]
        public void TeardownScale() {
            Mock.Dispose();
            Scale.Dispose();
        }

        [SetUp]
        public void ResetScale() {
            Mock.IdentNr = 0;
            Mock.Weight = 0;
            Mock.Error = null;
        }

        [Test]
        public async Task Test_01_Normal() {
            WeighingResult? res = null;
            Scale.WeighingEvent += (sender, evt) => {
                res = evt.Result;
            };

            await Mock.Weigh(2345);
            await Task.Delay(100);
            Assert.That(res, Is.Not.Null);
            Assert.That(res, Is.EqualTo(new WeighingResult {
                NetWeight = 2345,
                WeighingId = "1", FullWeighingId = $"2020-09-28/1",
                Date = new DateOnly(2020, 9, 28), Time = new TimeOnly(9, 8),
            }));

            await Mock.Weigh(4215);
            await Task.Delay(100);
            Assert.That(res, Is.Not.Null);
            Assert.That(res, Is.EqualTo(new WeighingResult {
                NetWeight = 4215,
                WeighingId = "2", FullWeighingId = $"2020-09-28/2",
                Date = new DateOnly(2020, 9, 28),
                Time = new TimeOnly(9, 8),
            }));
        }
    }
}