コード例 #1
0
        public async Task EventShouldCallCorrectFunction()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);


            dynamic helloWorldDataObject = GetDynamicDataObject(HelloWorldData);

            DefaultHassClientMock.AddCustomEvent("CUSTOM_EVENT", helloWorldDataObject);

            var isCalled = false;
            var message  = "";

            // ACT
            DefaultDaemonApp.ListenEvent("CUSTOM_EVENT", (ev, data) =>
            {
                isCalled = true;
                message  = data.Test;
                return(Task.CompletedTask);
            });

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            // ASSERT
            Assert.True(isCalled);
            Assert.Equal(HelloWorldData, message);
        }
コード例 #2
0
        public async Task OtherEventShouldNotCallCorrectFunction()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            dynamic dataObject = GetDynamicDataObject();

            DefaultHassClientMock.AddCustomEvent("CUSTOM_EVENT", dataObject);

            var isCalled = false;

            // ACT
            DefaultDaemonApp.ListenEvent("OTHER_EVENT", (ev, data) =>
            {
                isCalled = true;
                return(Task.CompletedTask);
            });

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            // ASSERT
            Assert.False(isCalled);
        }