public void ShouldDetachOnlyOneConnectionFromGPIOByNumberConnection() { //init var gpioByNumberConnectorPeripheralMock = new MockGPIOByNumberConnectorPeripheral(3); var gpioReceiverMock = new MockReceiver(); var gpioReceiverMock2 = new MockReceiver(); var gpioReceiverMock3 = new MockReceiver(); gpioByNumberConnectorPeripheralMock.Connections[0].Connect(gpioReceiverMock, 1); gpioByNumberConnectorPeripheralMock.Connections[1].Connect(gpioReceiverMock2, 2); gpioByNumberConnectorPeripheralMock.Connections[2].Connect(gpioReceiverMock3, 3); machine.SystemBus.Register(gpioByNumberConnectorPeripheralMock, new BusRangeRegistration(0x00, 0x10)); machine.SystemBus.Register(gpioReceiverMock, new BusRangeRegistration(0x10, 0x10)); machine.SystemBus.Register(gpioReceiverMock2, new BusRangeRegistration(0x20, 0x10)); machine.SystemBus.Register(gpioReceiverMock3, new BusRangeRegistration(0x30, 0x10)); //act machine.SystemBus.Unregister(gpioReceiverMock); //assert var connections = gpioByNumberConnectorPeripheralMock.Connections; Assert.IsNull(connections[0].Endpoint); Assert.IsNotNull(connections[1].Endpoint); Assert.IsNotNull(connections[2].Endpoint); }
public void ShouldUnregisterChainedPeripheralsOnBDisconnect() { //A -> B -> C, B -> D and A -> C //B is disconnected //init var A = new MockGPIOByNumberConnectorPeripheral(2); var B = new MockGPIOByNumberConnectorPeripheral(2); var C = new MockReceiver(); var D = new MockReceiver(); machine.SystemBus.Register(A, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(B, new BusRangeRegistration(0x10, 0x10)); machine.SystemBus.Register(C, new BusRangeRegistration(0x20, 0x10)); machine.SystemBus.Register(D, new BusRangeRegistration(0x30, 0x10)); A.Connections[0].Connect(B, 1); B.Connections[0].Connect(C, 1); B.Connections[1].Connect(D, 1); A.Connections[1].Connect(C, 2); //act machine.SystemBus.Unregister(B); var AConnections = A.Connections; var BConnections = B.Connections; //assert Assert.IsNull(AConnections[0].Endpoint); Assert.IsNull(BConnections[0].Endpoint); Assert.IsNull(BConnections[1].Endpoint); Assert.IsNotNull(AConnections[1].Endpoint); Assert.IsTrue(BConnections.All(x => x.Value.Endpoint == null)); // TODO: o co tu chodzi? dlaczego dwa razy sprawdzamy BConnections czy są nullami? }
public void ShouldDisconnectEndpointOfUnregisteredPeripheral() { // init var A = new MockGPIOByNumberConnectorPeripheral(1); var B = new MockGPIOByNumberConnectorPeripheral(1); var C = new MockReceiver(); machine.SystemBus.Register(A, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(B, new BusRangeRegistration(0x10, 0x10)); machine.SystemBus.Register(C, new BusRangeRegistration(0x20, 0x10)); // act A.Connections[0].Connect(B, 1); A.Connections[0].Connect(C, 1); B.Connections[0].Connect(C, 1); Assert.True(A.Connections[0].Endpoints.Count == 2); Assert.True(B.Connections[0].Endpoints.Count == 1); // try to connect the same endpoint as before A.Connections[0].Connect(C, 1); Assert.True(A.Connections[0].Endpoints.Count(x => x.Receiver == C && x.Number == 1) == 1); machine.SystemBus.Unregister(C); Assert.True(A.Connections[0].Endpoints.Count == 1); Assert.True(A.Connections[0].Endpoints[0].Receiver == B); Assert.IsEmpty(B.Connections[0].Endpoints); }
public void ShouldUnregisterChainedPeripheralsOnBDisconnect() { //A -> B -> C, B -> D and A -> C //B is disconnected //init var A = new MockGPIOByNumberConnectorPeripheral(2); var B = new MockGPIOByNumberConnectorPeripheral(2); var C = new MockReceiver(); var D = new MockReceiver(); machine.SystemBus.Register(A, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(B, new BusRangeRegistration(0x10, 0x10)); machine.SystemBus.Register(C, new BusRangeRegistration(0x20, 0x10)); machine.SystemBus.Register(D, new BusRangeRegistration(0x30, 0x10)); A.Connections[0].Connect(B, 1); B.Connections[0].Connect(C, 1); B.Connections[1].Connect(D, 1); A.Connections[1].Connect(C, 2); //act machine.SystemBus.Unregister(B); var AConnections = A.Connections; var BConnections = B.Connections; //assert Assert.IsEmpty(AConnections[0].Endpoints); Assert.IsEmpty(BConnections[0].Endpoints); Assert.IsEmpty(BConnections[1].Endpoints); Assert.IsNotEmpty(AConnections[1].Endpoints); }
public void RaiseFormatMessageEventTestNonFormat() { var sms = new SMSProvider(); var mock_rec = new MockReceiver(); var NoneFormatFunc = sms.FormatingFunc[(int)SMSProvider.FormatedMode.NoneFormat]; string inmessage = "Hellow World!!!"; mock_rec.OnSmsReseivedFormatedMsg(inmessage, NoneFormatFunc); Assert.AreEqual(mock_rec.Message, "Hellow World!!!"); }
public void RaiseFormatMessageEventTestMessageDataTimeFormat() { var sms = new SMSProvider(); var mock_rec = new MockReceiver(); var MessageDataTimeFunc = sms.FormatingFunc[(int)SMSProvider.FormatedMode.MessageDataTime]; string inmessage = "Hellow World!!!"; mock_rec.OnSmsReseivedFormatedMsg(inmessage, MessageDataTimeFunc); Assert.AreEqual(mock_rec.Message, $"Hellow World!!! [{sms.DataTimeAttachment}]"); }
public void RaiseFormatMessageEventTestUppercaseFormat() { var sms = new SMSProvider(); var mock_rec = new MockReceiver(); var UpperCaseFunc = sms.FormatingFunc[(int)SMSProvider.FormatedMode.UpperCase]; string inmessage = "hellow world!!!"; mock_rec.OnSmsReseivedFormatedMsg(inmessage, UpperCaseFunc); Assert.AreEqual(mock_rec.Message, $"HELLOW WORLD!!!"); }
public void ShouldPropagateConnected() { var source = new GPIO(); var destination = new MockReceiver(); source.Connect(destination, 2); var endpoint = source.Endpoint; Assert.AreEqual(2, endpoint.Number); Assert.AreEqual(destination, endpoint.Receiver); }
public void RaiseSMSReceivedEventTest() { var sms = new SMSProvider(); var mock_rec = new MockReceiver(); sms.SMSReceived += new SMSProvider.SMSRecievedDelegate(mock_rec.OnSmsReseived); string outmessage = "Hellow World!"; sms.RaiseSMSReceivedEvent(outmessage); Assert.AreEqual(mock_rec.Message, "Hellow World!"); }
public void GetReceiver_Returns_Null_IfUnknownReceiver() { // Arrange MockReceiver multiReceiver = new MockReceiver("你好", "世界", "unknown"); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(MockReceiverName); // Assert Assert.Null(actual); }
public void GetReceiver_Returns_ReceiverWithMultipleNames(string name1, string name2, string name3) { // Arrange MockReceiver multiReceiver = new MockReceiver(name1, name2, name3); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(MockReceiverName); // Assert Assert.Same(multiReceiver, actual); }
public void GetReceiver_Returns_Null_IfUnknownReceiver() { // Arrange MockReceiver multiReceiver = new MockReceiver(); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver("unknown"); // Assert Assert.Null(actual); }
public void ShoulDisconnectGPIOSenderAttachedToGPIOReceiver() { //init var gpioReceiverMock = new MockReceiver(); var gpioSender = new MockIrqSender(); machine.SystemBus.Register(gpioReceiverMock, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(gpioSender, new BusRangeRegistration(0x10, 0x10)); gpioSender.Irq.Connect(gpioReceiverMock, 1); //act machine.SystemBus.Unregister(gpioReceiverMock); //assert Assert.IsFalse(gpioSender.Irq.IsConnected); }
public void ShouldConnectGPIOToReceiverAndReturnTheSameReceiver() { //init var gpioByNumberConnectorPeripheralMock = new MockGPIOByNumberConnectorPeripheral(3); var gpioReceiverMock = new MockReceiver(); machine.SystemBus.Register(gpioByNumberConnectorPeripheralMock, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(gpioReceiverMock, new BusRangeRegistration(0x10, 0x10)); gpioByNumberConnectorPeripheralMock.Connections[0].Connect(gpioReceiverMock, 1); //act var gpioConnections = gpioByNumberConnectorPeripheralMock.Connections; var receiver = gpioConnections[0].Endpoint.Receiver; Assert.True(gpioReceiverMock == receiver); }
public void ShouldGetAllGPIOConnections() { //init var gpioByNumberConnectorPeripheralMock = new MockGPIOByNumberConnectorPeripheral(1); var gpioReceiverMock = new MockReceiver(); gpioByNumberConnectorPeripheralMock.Connections[0].Connect(gpioReceiverMock, 1); machine.SystemBus.Register(gpioByNumberConnectorPeripheralMock, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(gpioReceiverMock, new BusRangeRegistration(0x10, 0x10)); //act var connections = gpioByNumberConnectorPeripheralMock.Connections; //assert Assert.AreEqual(1, connections.Count()); }
public void ShouldDetachConnectionFromGPIOByNumberConnection() { //init var gpioByNumberConnectorPeripheralMock = new MockGPIOByNumberConnectorPeripheral(1); var gpioReceiverMock = new MockReceiver(); gpioByNumberConnectorPeripheralMock.Connections[0].Connect(gpioReceiverMock, 1); machine.SystemBus.Register(gpioByNumberConnectorPeripheralMock, new BusRangeRegistration(0x0, 0x10)); machine.SystemBus.Register(gpioReceiverMock, new BusRangeRegistration(0x10, 0x10)); //act machine.SystemBus.Unregister(gpioReceiverMock); //assert var connections = gpioByNumberConnectorPeripheralMock.Connections; Assert.IsEmpty(connections[0].Endpoints); }
public MockReceiverTest(MockReceiverOptions options) : base(options) { _mockReceiver = new MockReceiver(); }
public void GetReceiver_Throws_IfDuplicateMultipleNameReceivers() { // Arrange MockReceiver multiReceiver = new MockReceiver(MockReceiverName, MockReceiverName); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => manager.GetReceiver(MockReceiverName)); // Assert Assert.Contains("Multiple types were found that match the WebHook receiver named 'MockReceiver'. This can happen if multiple receivers are defined with the same name but different casing which is not supported. The request for 'MockReceiver' has found the following matching receivers:", ex.Message); }