当前位置: 首页>>代码示例>>C#>>正文


C# Mock.Raise方法代码示例

本文整理汇总了C#中Mock.Raise方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.Raise方法的具体用法?C# Mock.Raise怎么用?C# Mock.Raise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.Raise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FilterAddIDTest

        public void FilterAddIDTest()
        {
            LogItem message = new LogItem(category, level, msg, ids, GetException());
             var qThread = new Mock<IQueued<LogItem>>(MockBehavior.Strict);
             var writer = new Mock<ILogWriter>(MockBehavior.Strict);

             writer
            .Setup(s => s.Write(It.IsAny<LogItem>()));
             writer
            .Setup(s => s.GetTimeout())
            .Returns(timeout);
             qThread
            .Setup(s => s.SetTimeout(It.IsAny<int>()));

             LogCollector target = new LogCollector(qThread.Object, writer.Object);
             target.FilterAddID(1);
             qThread.Raise(s => s.OnReceive += null, message);

             writer
               .Verify(s => s.Write(It.IsAny<LogItem>()), Times.Never());

             target.FilterAddID(3);
             target.FilterAddID(1);
             qThread.Raise(s => s.OnReceive += null, message);

             writer
            .Verify(s => s.Write(It.Is<LogItem>(a => a.Equals(message))), Times.Once());
        }
开发者ID:repinvv,项目名称:SharpLogger,代码行数:28,代码来源:LogCollectorTest.cs

示例2: Arrange

        protected void Arrange()
        {
            var random = new Random();

            _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500));
            _expected = new byte[random.Next(30, 50)];
            _encoding = Encoding.UTF8;
            random.NextBytes(_expected);

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);

            var sequence = new MockSequence();

            _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
            _channelSessionMock.InSequence(sequence).Setup(p => p.Open());
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        // generate response for SftpInitRequest
                        var versionInfoResponse = SftpVersionResponseBuilder.Create(3)
                                                                            .Build();
                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, versionInfoResponse));
                    });
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC");

                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, sftpNameResponse));
                    }
                );
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        var sftpDataResponse = CreateSftpDataResponse(2, _expected);

                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, sftpDataResponse.Take(0, 20)));
                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, sftpDataResponse.Take(20, sftpDataResponse.Length - 20)));
                    }
                );

            _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding);
            _sftpSession.Connect();
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:57,代码来源:SftpSessionTest_Connected_RequestRead.cs

示例3: Arrange

        protected void Arrange()
        {
            var random = new Random();

            _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500));
            _encoding = Encoding.UTF8;

            _bAvail = (ulong) random.Next(0, int.MaxValue);

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);

            var sequence = new MockSequence();

            _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
            _channelSessionMock.InSequence(sequence).Setup(p => p.Open());
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        // generate response for SftpInitRequest
                        var versionInfoResponse = SftpVersionResponseBuilder.Create(3)
                                                                            .AddExtension("[email protected]", "")
                                                                            .Build();
                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, versionInfoResponse));
                    });
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC");

                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, sftpNameResponse));
                    }
                );
            _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true);
            _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny<byte[]>())).Callback(
                () =>
                    {
                        var statVfsReplyBuilder = StatVfsReplyBuilder.Create(2);
                        statVfsReplyBuilder.WithBAvail(_bAvail);
                        var statVfsReply = statVfsReplyBuilder.Build();

                        _channelSessionMock.Raise(
                            c => c.DataReceived += null,
                            new ChannelDataEventArgs(0, statVfsReply));
                    }
                );

            _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding);
            _sftpSession.Connect();
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:57,代码来源:SftpSessionTest_Connected_RequestStatVfs.cs

示例4: TestAmountIndexRaisesWhenPlaying

 public void TestAmountIndexRaisesWhenPlaying()
 {
     var mockTimer = new Mock<ITimer>();
     Piano piano = GetNewPiano(mockTimer.Object);
     piano.StartPlaying();
     mockTimer.Raise(mock => mock.Elapsed += null, new EventArgs());
     mockTimer.Raise(mock => mock.Elapsed += null, new EventArgs());
     foreach(PianoKey pianoKey in piano.AllKeys)
     {
         Assert.AreEqual(2, pianoKey.CurrentIndex);
     }
 }
开发者ID:LimmaPaulus,项目名称:Capo,代码行数:12,代码来源:PianoTests.cs

示例5: Arrange

        private void Arrange()
        {
            var random = new Random();
            _localChannelNumber = (uint)random.Next(0, int.MaxValue);
            _localWindowSize = (uint)random.Next(0, int.MaxValue);
            _localPacketSize = (uint)random.Next(0, int.MaxValue);
            _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
            _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
            _remotePacketSize = (uint)random.Next(0, int.MaxValue);
            _closeTimer = new Stopwatch();
            _channelClosedRegister = new List<ChannelEventArgs>();
            _channelExceptionRegister = new List<ExceptionEventArgs>();

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);

            var sequence = new MockSequence();
            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
                .Callback<WaitHandle>(w =>
                    {
                        new Thread(() =>
                            {
                                Thread.Sleep(100);
                                // raise ChannelCloseReceived event to set waithandle for receiving
                                // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
                                // sending the SSH_MSG_CHANNEL_CLOSE message to the server
                                _sessionMock.Raise(s => s.ChannelCloseReceived += null,
                                    new MessageEventArgs<ChannelCloseMessage>(
                                        new ChannelCloseMessage(_localChannelNumber)));
                            }).Start();
                        _closeTimer.Start();
                        try
                        {
                            w.WaitOne();
                        }
                        finally
                        {
                            _closeTimer.Stop();
                        }
                    });

            _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
            _channel.SetIsOpen(true);

            _sessionMock.Raise(
                s => s.ChannelEofReceived += null,
                new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:52,代码来源:ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs

示例6: Arrange

        protected void Arrange()
        {
            var random = new Random();
            _closingRegister = new List<EventArgs>();
            _exceptionRegister = new List<ExceptionEventArgs>();
            _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
            _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
            ForwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port);

            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);

            _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE"));
            _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS"));
            _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN"));
            _sessionMock.Setup(
                p =>
                    p.SendMessage(
                        It.Is<GlobalRequestMessage>(
                            g =>
                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                g.AddressToBind == ForwardedPort.BoundHost &&
                                g.PortToBind == ForwardedPort.BoundPort)))
                .Callback(
                    () =>
                        _sessionMock.Raise(s => s.RequestSuccessReceived += null,
                            new MessageEventArgs<RequestSuccessMessage>(new RequestSuccessMessage())));
            _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny<WaitHandle>()));
            _sessionMock.Setup(
                p =>
                    p.SendMessage(
                        It.Is<GlobalRequestMessage>(
                            g =>
                                g.RequestName == GlobalRequestName.CancelTcpIpForward &&
                                g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort)))
                .Callback(
                    () =>
                        _sessionMock.Raise(s => s.RequestSuccessReceived += null,
                            new MessageEventArgs<RequestSuccessMessage>(new RequestSuccessMessage())));
            _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(false));

            ForwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
            ForwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
            ForwardedPort.Session = _sessionMock.Object;
            ForwardedPort.Start();
            ForwardedPort.Stop();
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:50,代码来源:ForwardedPortRemoteTest_Dispose_PortStopped.cs

示例7: ResetControllerGetsCalledOnTheViewWhenTheViewRaisesControllerChangedWithNeitherProgrammer

        public void ResetControllerGetsCalledOnTheViewWhenTheViewRaisesControllerChangedWithNeitherProgrammer()
        {
            var programmer1 = new Programmer("Joe");
            var programmer2 = new Programmer("Bob");

            var mockView = new Mock<PairTrackerView>();

            mockView.Setup(v => v.ResetController());

            var presenter = new PairTrackerPresenterBuilder().WithView(mockView.Object).Build();
            mockView.Raise(v => v.StartButton_Clicked += null, new StartButtonClickedEventArgs(programmer1, programmer2));
            mockView.Raise(v => v.Controller_Changed += null, new ControllerChangedEventArgs(Programmer.Neither));

            mockView.VerifyAll();
        }
开发者ID:alexkates,项目名称:Pair-Tracker,代码行数:15,代码来源:PairTrackerPresenterTests.cs

示例8: UnlockNameEntryGetsCalledOnTheViewWhenTheViewRaisesStopButton_Clicked

        public void UnlockNameEntryGetsCalledOnTheViewWhenTheViewRaisesStopButton_Clicked()
        {
            var programmer1 = new Programmer("Joe");
            var programmer2 = new Programmer("Bob");

            var mockView = new Mock<PairTrackerView>();

            mockView.Setup(v => v.UnlockNameEntry());

            var presenter = new PairTrackerPresenterBuilder().WithView(mockView.Object).Build();
            mockView.Raise(v => v.StartButton_Clicked += null, new StartButtonClickedEventArgs(programmer1, programmer2));
            mockView.Raise(v => v.StopButton_Clicked += null, new EventArgs());

            mockView.VerifyAll();
        }
开发者ID:alexkates,项目名称:Pair-Tracker,代码行数:15,代码来源:PairTrackerPresenterTests.cs

示例9: ConstructingControllerStartsTimelines

        public void ConstructingControllerStartsTimelines()
        {
            var checkTimelines = new Mock<ITimer>();
            var updateTimelines = new Mock<ITimer>();
            var queue = new Queue<ITimer>();
            queue.Enqueue(checkTimelines.Object);
            queue.Enqueue(updateTimelines.Object);
            SysTimer.Override = queue.Dequeue;

            var timelines = new Mock<ITimelines>();
            var controller = new TimelineController(timelines.Object);
            controller.StartTimelines();
            checkTimelines.Raise(c => c.Elapsed += null, EventArgs.Empty);
            updateTimelines.Raise(u => u.Elapsed += null, EventArgs.Empty);

            checkTimelines.VerifySet(c => c.Interval = 100);
            checkTimelines.VerifySet(c => c.Interval = 60000);
            checkTimelines.Verify(c => c.Start());
            timelines.Verify(t => t.HomeTimeline());
            timelines.Verify(t => t.MentionsTimeline());

            updateTimelines.VerifySet(u => u.Interval = 30000);
            updateTimelines.Verify(u => u.Start());
            timelines.Verify(t => t.UpdateTimeStamps());
            Assert.That(controller, Is.Not.Null);
        }
开发者ID:arvydas,项目名称:tweetz-desktop,代码行数:26,代码来源:TestTimelineController.cs

示例10: MealForOtherDayNotRemovedFromChildrenWhenRemovedFromRepository

        public void MealForOtherDayNotRemovedFromChildrenWhenRemovedFromRepository()
        {
            var dataRepositoryMock = new Mock<IDataRepository>();
             var data = new MockData();
             var allMeals = data.Meals();

             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date
                                           select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals ) ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals )
                                           select meal).ToList() ) );

             var mealNodeViewModel = new MealNodeViewModel( dataRepositoryMock.Object, null );
             Assert.AreEqual( 3, mealNodeViewModel.Children.Count );

             var removedMeal = allMeals.Find( m => m.DateAndTimeOfMeal.Date == DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals ) && m.TypeOfMeal.Name == "Dinner" );
             Assert.IsNotNull( removedMeal );
             allMeals.Remove( removedMeal );
             dataRepositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( removedMeal ) );
             Assert.AreEqual( 3, mealNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealNodeViewModel.Children)
             {
            var meal = allMeals.Find( m => m.ID == (Guid)node.Parameter );
            Assert.IsNotNull( meal );
            Assert.AreEqual( meal.Name, node.Name );
             }
        }
开发者ID:nagyist,项目名称:HealthTracker-1,代码行数:31,代码来源:MealNodeViewModelTest.cs

示例11: Arrange

        private void Arrange()
        {
            var random = new Random();
            _localChannelNumber = (uint)random.Next(0, int.MaxValue);
            _localWindowSize = (uint)random.Next(0, int.MaxValue);
            _localPacketSize = (uint)random.Next(0, int.MaxValue);
            _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
            _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
            _remotePacketSize = (uint)random.Next(0, int.MaxValue);
            _channelClosedRegister = new List<ChannelEventArgs>();
            _channelExceptionRegister = new List<ExceptionEventArgs>();
            _initialSessionSemaphoreCount = random.Next(10, 20);
            _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount);

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);

            _sequence = new MockSequence();
            _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1);
            _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
            _sessionMock.InSequence(_sequence)
                .Setup(
                    p =>
                        p.SendMessage(
                            It.Is<ChannelOpenMessage>(
                                m =>
                                    m.LocalChannelNumber == _localChannelNumber &&
                                    m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
                                    m.Info is SessionChannelOpenInfo)));
            _sessionMock.InSequence(_sequence)
                .Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
                .Callback<WaitHandle>(
                    w =>
                    {
                        _sessionMock.Raise(
                            s => s.ChannelOpenConfirmationReceived += null,
                            new MessageEventArgs<ChannelOpenConfirmationMessage>(
                                new ChannelOpenConfirmationMessage(
                                    _localChannelNumber,
                                    _remoteWindowSize,
                                    _remotePacketSize,
                                    _remoteChannelNumber)));
                        w.WaitOne();
                    });
            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.InSequence(_sequence)
                .Setup(
                    p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                .Returns(false);

            _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.Open();

            _sessionMock.Raise(
                p => p.ChannelCloseReceived += null,
                new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:60,代码来源:ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs

示例12: ValidHelloMessage

        public void ValidHelloMessage ()
        {
            var responseStream = new MemoryStream ();
            var stream = new TestStream (new MemoryStream (helloMessage), responseStream);

            // Create mock byte server and client
            var mockByteServer = new Mock<IServer<byte,byte>> ();
            var byteServer = mockByteServer.Object;
            var byteClient = new TestClient (stream);

            var server = new RPCServer (byteServer);
            server.OnClientRequestingConnection += (sender, e) => e.Request.Allow ();
            server.Start ();

            // Fire a client connection event
            var eventArgs = new ClientRequestingConnectionEventArgs<byte,byte> (byteClient);
            mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs);

            Assert.IsTrue (eventArgs.Request.ShouldAllow);
            Assert.IsFalse (eventArgs.Request.ShouldDeny);

            server.Update ();
            Assert.AreEqual (1, server.Clients.Count ());
            Assert.AreEqual ("Jebediah Kerman!!!", server.Clients.First ().Name);

            byte[] bytes = responseStream.ToArray ();
            byte[] responseBytes = byteClient.Guid.ToByteArray ();
            Assert.IsTrue (responseBytes.SequenceEqual (bytes));
        }
开发者ID:paperclip,项目名称:krpc,代码行数:29,代码来源:RPCServerTest.cs

示例13: OnStartProgress

        public void OnStartProgress()
        {
            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var collector = new Mock<ICollectProgressReports>();
            var model = new ProgressModel(context.Object, collector.Object);

            var propertyChangedWasRaised = 0;
            var properties = new List<string>();
            model.PropertyChanged += (s, e) =>
            {
                propertyChangedWasRaised++;
                properties.Add(e.PropertyName);
            };

            collector.Raise(c => c.OnStartProgress += null, EventArgs.Empty);

            Assert.AreEqual(0.0, model.Progress);
            Assert.AreEqual(3, propertyChangedWasRaised);
            Assert.That(
                properties,
                Is.EquivalentTo(
                    new List<string>
                    {
                        "Progress",
                        "Description",
                        "HasErrors"
                    }));
        }
开发者ID:pvandervelde,项目名称:Apollo,代码行数:33,代码来源:ProgressModelTest.cs

示例14: CanExecuteChangesToFalseAndAnEventIsFiredWhenOneOfThePromtpsBecomesNotReady

        public void CanExecuteChangesToFalseAndAnEventIsFiredWhenOneOfThePromtpsBecomesNotReady()
        {
            var numberOfEvents = 0;

            var catalogItem = A.CatalogItemInfo().WithPath("Report 1").Build();

            var prompt1 = Mock.Of<IPrompt>(p => p.ReadyForReportExecution == true);
            var prompt2 = Mock.Of<IPrompt>(p => p.ReadyForReportExecution == true);
            var prompt3 = new Mock<IPrompt>();
            prompt3.SetupGet(p => p.ReadyForReportExecution).Returns(false);

            _fakePromptsViewModelService.SetupGetPrompts(catalogItem.Path);

            _promptsViewModel.ShowPromptsFor(catalogItem);

            _fakePromptsViewModelService.ExecuteCallback(A.ObservableCollection(prompt1, prompt2, prompt3.Object));

            Assert.IsFalse(_promptsViewModel.ExecuteReport.CanExecute(null));

            _promptsViewModel.ExecuteReport.CanExecuteChanged += (s, e) => { numberOfEvents++; };

            prompt3.SetupGet(p => p.ReadyForReportExecution).Returns(true);
            prompt3.Raise(p => p.PropertyChanged += null, new PropertyChangedEventArgs("ReadyForReportExecution"));

            Assert.AreEqual(numberOfEvents, 1);
            Assert.IsTrue(_promptsViewModel.ExecuteReport.CanExecute(null));
        }
开发者ID:e82eric,项目名称:Prompts,代码行数:27,代码来源:PromptsViewModelTest.cs

示例15: Arrange

        private void Arrange()
        {
            var random = new Random();
            _localChannelNumber = (uint)random.Next(0, int.MaxValue);
            _localWindowSize = (uint)random.Next(0, int.MaxValue);
            _localPacketSize = (uint)random.Next(0, int.MaxValue);
            _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
            _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
            _remotePacketSize = (uint)random.Next(0, int.MaxValue);
            _channelClosedRegister = new List<ChannelEventArgs>();
            _channelExceptionRegister = new List<ExceptionEventArgs>();

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);

            _sessionMock.Setup(p => p.IsConnected).Returns(true);
            _sessionMock.Setup(
                p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                .Returns(true);

            _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
            _channel.SetIsOpen(true);

            _sessionMock.Raise(p => p.ChannelEofReceived += null,
                new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:28,代码来源:ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs


注:本文中的Mock.Raise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。