Beispiel #1
0
        public void RpcClient_Can_Handle_SignMessageResponse(SignedResponse signedResponse)
        {
            var testScheduler = new TestScheduler();

            var signMessageResponse = new SignMessageResponse
            {
                OriginalMessage = signedResponse.OriginalMessage,
                PublicKey       = signedResponse.PublicKey,
                Signature       = signedResponse.Signature,
            };

            var correlationId = CorrelationId.GenerateCorrelationId();

            var protocolMessage =
                signMessageResponse.ToProtocolMessage(PeerIdHelper.GetPeerId("sender"), correlationId);

            var messageStream = MessageStreamHelper.CreateStreamWithMessage(_fakeContext, testScheduler,
                                                                            protocolMessage
                                                                            );

            _handler = new SignMessageResponseObserver(_output, _logger);
            _handler.StartObserving(messageStream);

            testScheduler.Start();

            _output.Received(1).WriteLine(Arg.Any <string>());
        }
        public void from_VACANT_DOOR_CLOSED_NO_PHONE_CONNECTED_to_VACANT_DOOR_OPEN_NO_PHONE_CONNECTED()
        {
            //act
            _doorSensor.DoorOpened += Raise.EventWith(EventArgs.Empty);

            //assert
            _logger.Received(1).LogThis("Door opened");
            _userOutput.Received().Notify_ConnectPhone();
        }
Beispiel #3
0
        public void DisplayPlayingField_CallsUserOutput_WhenCalled()
        {
            // Arrange
            MineFieldManager sut = CreateSut();

            sut.CreateMineField(1,
                                2,
                                3);

            // Act
            sut.DisplayPlayingField();

            // Assert
            m_UserOutput.Received().DisplayPlayingField();
        }
Beispiel #4
0
        public void ReadSecurePassword_Should_Prompt_Context_And_Get_Password_From_Console()
        {
            var prompt      = "hello give me a password";
            var keysPressed = new[]
            {
                new ConsoleKeyInfo('?', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('?', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('@', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('s', ConsoleKey.S, false, false, false),
                new ConsoleKeyInfo('s', ConsoleKey.S, false, false, false),
                new ConsoleKeyInfo('?', ConsoleKey.Enter, false, false, false)
            };

            _userInput.ReadKey().Returns(keysPressed.First(), keysPressed.Skip(1).ToArray());

            using (var pass = _consolePasswordReader.ReadSecurePassword(prompt))
            {
                _userOutput.Received(1).WriteLine(prompt);
                pass.Length.Should().Be(4);
                pass.IsReadOnly().Should().BeTrue();
            }
        }
Beispiel #5
0
        public async Task StopAsync_Should_Log_If_Not_Running_Sync()
        {
            _deltaHeightWatcher = Substitute.For <IDeltaHeightWatcher>();
            _deltaHeightWatcher.GetHighestDeltaIndexAsync().Returns(new DeltaIndex {
                Cid = ByteString.Empty, Height = 10000
            });

            var sync = new Synchroniser(new SyncState(), _peerSyncManager, _deltaCache, _deltaHeightWatcher, _deltaHashProvider, _deltaDfsReader,
                                        _deltaIndexService, _mapperProvider, _userOutput, Substitute.For <ILogger>());

            await sync.StopAsync(CancellationToken.None);

            _userOutput.Received(1).WriteLine("Sync is not currently running.");

            sync.State.IsRunning.Should().BeFalse();
        }
        public void VACANT_DOOR_CLOSED_NO_PHONE_CONNECTED_testing_illegal_state_changes()
        {
            //act
            _doorSensor.DoorClosed           += Raise.EventWith(EventArgs.Empty);
            _rfidReader.RfidDetected         += Raise.EventWith(new RfidDetectedEventArgs(5));
            _chargeControl.PhoneConnected    += Raise.EventWith(EventArgs.Empty);
            _chargeControl.PhoneDisconnected += Raise.EventWith(EventArgs.Empty);

            //assert
            //correct behavior
            _logger.Received(1).LogThis("Door is closed");
            _userOutput.Received(1).Notify_OpenDoorConnectPhone();

            //incorrect behaviour
            _logger.Received(0).LogThis("Door opened");
            _logger.Received(0).LogThis("Door has been locked");
            _logger.Received(0).LogThis("Door has been unlocked");
            _logger.Received(0).LogThis("Wrong RFID, door remains locked");
            _logger.Received(0).LogThis("Phone connected");
            _logger.Received(0).LogThis("Phone has been disconnected");
            _logger.Received(0).LogThis("Door closed, awaiting RFID tag");
            _logger.Received(0).LogThis("Phone has been disconnected");


            _userOutput.Received(0).Notify_DoorOpened();
            _userOutput.Received(0).Notify_ConnectPhone();
            _userOutput.Received(0).Notify_PhoneConnectedCloseDoor();
            _userOutput.Received(0).Notify_ScanRFID_ToLock();
            _userOutput.Received(0).Notify_CheckingRFID();
            _userOutput.Received(0).Notify_DoorLocked_ScanRfidToUnlock();
            _userOutput.Received(0).Notify_YouMayOpenDoorAndDisconnect();
        }