public void WhenParameterIsNull_Update_ShouldThrowError()
        {
            //Arrange
            var mockMessageRepository = GetMessageProvider();
            //Act
            var sut = new MessagesProvider(mockMessageRepository.Object);

            //Assert
            Assert.Throws <ArgumentNullException>(() => sut.Update(null));
        }
Beispiel #2
0
        private static void Main(String[] args)
        {
            var messagesGenerator = new MessagesGenerator();
            var messagesProvider  = new MessagesProvider(messagesGenerator);
            var random            = new Random();

            //Just an example of how to use API, pretty bad example
            using (var client = new SunricherTcpClient("192.168.12.194", ApiConstants.DefaultTcpPort))
            {
                client.MessageSent += (s, e) =>
                {
                    String messageStr = String.Join("-",
                                                    e.Message.Select(b => Convert.ToString(b, 16).PadLeft(2, '0')));

                    Console.WriteLine($"Message sent: {messageStr}");
                };

                var cts  = new CancellationTokenSource();
                var ct   = cts.Token;
                var task = Task.Run(() =>
                {
                    try
                    {
                        client.SendMessageAsync(messagesProvider.PowerOn(), ct).Wait(ct);
                        while (true)
                        {
                            if (ct.IsCancellationRequested)
                            {
                                break;
                            }

                            client.SendMessageAsync(messagesProvider.SetRed((Byte)random.Next(0, 100)), ct).Wait();
                            client.SendMessageAsync(messagesProvider.SetGreen((Byte)random.Next(0, 100)), ct).Wait();
                            client.SendMessageAsync(messagesProvider.SetBlue((Byte)random.Next(0, 100)), ct).Wait();
                            client.SendMessageAsync(messagesProvider.SetWhite((Byte)random.Next(0, 100)), ct).Wait();
                            client.SendMessageAsync(messagesProvider.SetBrightness((Byte)random.Next(0, 255)), ct).Wait();
                            Thread.Sleep(1000);
                        }
                    }
                    catch (Exception)
                    {
                        cts.Cancel();
                        throw;
                    }
                }, ct);

                Console.ReadKey();
                cts.Cancel();
                task.Wait(TimeSpan.FromSeconds(10));
            }
        }
        public void GetAll_ShouldReturnData()
        {
            //Arrange
            var mockMessageRepository = new Mock <IRepository <Entities.Message> >();
            var msg = new Entities.Message {
                Id = 1, Text = "Hello world!"
            };

            mockMessageRepository.Setup(m => m.GetAll()).Returns(new List <Entities.Message> {
                msg
            });
            //Act
            var sut    = new MessagesProvider(mockMessageRepository.Object);
            var result = sut.GetAll();

            //Assert
            Assert.True(result.Any());
        }
        public override void ClearUIForStartInput()
        {
            base.ClearUIForStartInput();
            if (IsMainWindowReadyForUserInteraction())
            {
                try
                {
                    RootAutomationElement.SetFocus();
                    Keyboard.Type(Key.F2);
                }
                catch (Exception e)
                {
                    MessagesProvider.Log($"Cannot clear UI for start input: Element name {RootAutomationElement.Current.Name}, Exception: {e}");
                }
            }

            foreach (var tab in Tabs)
            {
                tab.GetTabItems()?.First()?.Select();
            }
        }