public void GetVersionNumber_NoDeadlock()
        {
            // Using an asynchronous HttpClient request within an MVC Web API action may cause
            // a deadlock when we wait for the result synchronously.

            var context = new Mock<SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var provider = new DefaultVersionProvider();

                provider.GetVersion(ClusterHelper.GetBucket("beer-sample"));

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
Beispiel #2
0
        public void GetVersionNumber_NoDeadlock()
        {
            // Using an asynchronous HttpClient request within an MVC Web API action may cause
            // a deadlock when we wait for the result synchronously.

            var context = new Mock <SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var provider = new DefaultVersionProvider();

                provider.GetVersion(ClusterHelper.GetBucket("beer-sample"));

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
        public void GetVersionNumber_ReturnsVersion()
        {
            // Arrange

            var provider = new DefaultVersionProvider();

            // Act

            var version = provider.GetVersion(ClusterHelper.GetBucket("beer-sample"));

            // Assert

            Assert.NotNull(version);
        }
Beispiel #4
0
        public void GetVersionNumber_ReturnsVersion()
        {
            // Arrange

            var provider = new DefaultVersionProvider();

            // Act

            var version = provider.GetVersion(ClusterHelper.GetBucket("beer-sample"));

            // Assert

            Assert.NotNull(version);
        }
        public void GetVersion_Fails_Returns4()
        {
            // Arrange

            var bucket = new Mock <IBucket>();

            bucket
            .SetupGet(m => m.Cluster)
            .Returns(new Mock <ICluster>().Object);
            bucket
            .Setup(m => m.GetClusterVersionAsync())
            .Returns(Task.FromResult <ClusterVersion?>(null));

            var provider = new DefaultVersionProvider();

            // Act

            var result = provider.GetVersion(bucket.Object);

            // Assert

            Assert.AreEqual(Version40, result);
        }