Moq.Language.ICallback.Callback(System.Action)

Here are the examples of the csharp api Moq.Language.ICallback.Callback(System.Action) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

19 Source : WebHookReceiverTests.cs
with Apache License 2.0
from aspnet

[Fact]
        public async Task ExecuteWebHookAsync_InitializesContext()
        {
            // Arrange
            WebHookHandlerContext actual = null;
            var handlerMock = new Mock<IWebHookHandler>();
            handlerMock.Setup<Task>(h => h.ExecuteAsync(WebHookReceiverMock.ReceiverName, It.IsAny<WebHookHandlerContext>()))
                .Callback<string, WebHookHandlerContext>((rec, con) => actual = con)
                .Returns(Task.FromResult(true))
                .Verifiable();

            var handlers = new KeyValuePair<Type, object>[]
            {
                new KeyValuePair<Type, object>(typeof(IWebHookHandler), handlerMock.Object),
            };
            Initialize(TestSecret, handlers);
            var data = new object();
            IEnumerable<string> actions = new[] { "action" };

            // Act
            await _receiverMock.ExecuteWebHookAsync(TestId, _context, _request, actions, data);

            // replacedert
            handlerMock.Verify();
            replacedert.Equal(TestId, actual.Id);
            replacedert.Equal(_request, actual.Request);
            replacedert.Equal(_context, actual.RequestContext);
            replacedert.Equal(data, actual.Data);
            replacedert.Equal(actions, actual.Actions);
        }

19 Source : PmlTestRunnerTest.cs
with MIT License
from PoByBolek

[TestCase(13)]
        [TestCase(123)]
        [TestCase(128937489)]
        public void Run_ShouldreplacedignAndReturnTestResultWithElapsedTimeWhenTestFails(int duration)
        {
            // Arrange
            int seconds = 0;
            var proxy = new Mock<ObjectProxy>();
            proxy.Setup(mock => mock.Invoke(It.IsAny<string>(), It.IsAny<object[]>())).Returns(StackTrace);
            var clock = new Mock<Clock>();
            clock.SetupGet(mock => mock.CurrentInstant)
                .Returns(() => Instant.FromSeconds(seconds))
                .Callback(() => seconds = duration);
            var runner = new PmlTestRunner(proxy.Object, Mock.Of<MethodInvoker>(), clock.Object);
            // Act
            var result = runner.Run(Test);
            // replacedert
            replacedert.AreEqual(TimeSpan.FromSeconds(duration), result.Duration);
            replacedert.AreSame(result, Test.Result);
        }

19 Source : PmlTestRunnerTest.cs
with MIT License
from PoByBolek

[TestCase(20)]
        [TestCase(12)]
        [TestCase(0)]
        [TestCase(-5)]
        [TestCase(3600)]
        [TestCase(86401)]
        public void Run_ShouldreplacedignAndReturnTestResultWithElapsedTime(int duration)
        {
            // Arrange
            int seconds = 0;
            var clock = new Mock<Clock>();
            clock.SetupGet(mock => mock.CurrentInstant)
                .Returns(() => Instant.FromSeconds(seconds))
                .Callback(() => seconds = duration);
            var runner = new PmlTestRunner(Mock.Of<ObjectProxy>(), Mock.Of<MethodInvoker>(), clock.Object);
            // Act
            var result = runner.Run(Test);
            // replacedert
            replacedert.AreEqual(TimeSpan.FromSeconds(duration), result.Duration);
            replacedert.AreSame(result, Test.Result);
        }

19 Source : ClientHostDisconnectionOperationTests.cs
with Mozilla Public License 2.0
from SafeExamBrowser

[TestMethod]
		public void MustWaitForDisconnectionIfConnectionIsActive()
		{
			var after = default(DateTime);
			var before = default(DateTime);
			var timeout_ms = 200;

			sut = new ClientHostDisconnectionOperation(context, logger.Object, timeout_ms);

			clientHost.SetupGet(h => h.IsConnected).Returns(true).Callback(() => Task.Delay(10).ContinueWith((_) =>
			{
				clientHost.Raise(h => h.RuntimeDisconnected += null);
			}));

			before = DateTime.Now;
			sut.Revert();
			after = DateTime.Now;

			clientHost.VerifyGet(h => h.IsConnected);
			clientHost.VerifyAdd(h => h.RuntimeDisconnected += It.IsAny<CommunicationEventHandler>());
			clientHost.VerifyRemove(h => h.RuntimeDisconnected -= It.IsAny<CommunicationEventHandler>());
			clientHost.VerifyNoOtherCalls();

			replacedert.IsTrue(after - before < new TimeSpan(0, 0, 0, 0, timeout_ms));
		}