Пример #1
0
        public void ACustomEventNullValueCallThrowsNullReferenceException()
        {
            // ARRANGE
            var hcMock     = HassClientMock.DefaultMock;
            var daemonHost = new NetDaemonHost(hcMock.Object, new Mock <IDataRepository>().Object);
            var app        = new FluentTestApp();

            app.StartUpAsync(daemonHost);

            var cancelSource = hcMock.GetSourceWithTimeout();

            Assert.Throws <NullReferenceException>(() => app
                                                   .Event("CUSTOM_EVENT")
                                                   .Call(null).Execute());
        }
Пример #2
0
        public async Task ACustomEventShouldDoCorrectCall()
        {
            // ARRANGE
            var hcMock = HassClientMock.DefaultMock;

            await using var daemonHost = new NetDaemonHost(hcMock.Object, new Mock <IDataRepository>().Object);

            var app = new FluentTestApp();

            app.Id = "id";

            daemonHost.InternalRunningAppInstances[app.Id] = app;
            await app.StartUpAsync(daemonHost);

            dynamic dynObject = new ExpandoObject();

            dynObject.Test = "Hello World!";

            hcMock.AddCustomEvent("CUSTOM_EVENT", dynObject);

            var    cancelSource = hcMock.GetSourceWithTimeout();
            var    isCalled     = false;
            string?message      = "";

            app
            .Event("CUSTOM_EVENT")
            .Call((ev, data) =>
            {
                isCalled = true;
                message  = data?.Test;
                return(Task.CompletedTask);
            }).Execute();

            try
            {
                await daemonHost.Run("host", 8123, false, "token", cancelSource.Token).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                // Expected behaviour
            }

            Assert.True(isCalled);
            Assert.Equal("Hello World!", message);
        }
Пример #3
0
        public async Task ACustomEventNullValueCallThrowsNullReferenceException()
        {
            // ARRANGE
            var hcMock = HassClientMock.DefaultMock;

            await using var daemonHost = new NetDaemonHost(hcMock.Object, new Mock <IDataRepository>().Object);

            var app = new FluentTestApp();

            app.Id = "id";

            daemonHost.InternalRunningAppInstances[app.Id] = app;
            await app.StartUpAsync(daemonHost);

            var cancelSource = hcMock.GetSourceWithTimeout();

            Assert.Throws <NullReferenceException>(() => app
                                                   .Event("CUSTOM_EVENT")
                                                   .Call(null).Execute());
        }
Пример #4
0
        public async Task ACustomEventShouldUsingSelectorUsingDataNotExisstFuncNotCall()
        {
            // ARRANGE
            var hcMock     = HassClientMock.DefaultMock;
            var daemonHost = new NetDaemonHost(hcMock.Object, new Mock <IDataRepository>().Object);
            var app        = new FluentTestApp();
            await app.StartUpAsync(daemonHost);

            dynamic dynObject = new ExpandoObject();

            dynObject.Test = "Hello World!";

            hcMock.AddCustomEvent("CUSTOM_EVENT", dynObject);

            var    cancelSource = hcMock.GetSourceWithTimeout();
            var    isCalled     = false;
            string?message      = "";

            app
            .Events(n => n.EventId == "CUSTOM_EVENT" && n?.Data?.NotExist == "Hello Test!")
            .Call((ev, data) =>
            {
                isCalled = true;
                message  = data?.Test;
                return(Task.CompletedTask);
            }).Execute();

            try
            {
                await daemonHost.Run("host", 8123, false, "token", cancelSource.Token).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                // Expected behaviour
            }

            Assert.False(isCalled);
        }