public void ServerProxy_AddDebugWriter_WithArgs_ShouldInvokeCorrectly()
 {
     //------------Setup for test--------------------------
     var mockHubProxy = new Mock<IHubProxy>();
     mockHubProxy.Setup(proxy => proxy.Invoke("AddDebugWriter", It.IsAny<Guid>())).Returns(new Task(() => { }));
     var serverProxy = new TestServerProxy();
     serverProxy.SetEsbProxy(mockHubProxy.Object);
     //------------Execute Test---------------------------
     serverProxy.AddDebugWriter(Guid.NewGuid());
     //------------Assert Results-------------------------
     mockHubProxy.VerifyAll();
 }
 public void ServerProxy_ExecuteCommand_WithArgs_ShouldInvokeCorrectly()
 {
     //------------Setup for test--------------------------
     const string serverMsg = "server result";
     var mockHubProxy = new Mock<IHubProxyWrapper>();
     mockHubProxy.Setup(proxy => proxy.Invoke<string>("ExecuteCommand", It.IsAny<Envelope>(), It.IsAny<bool>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Returns(new Task<string>(() => serverMsg));
     var serverProxy = new TestServerProxy();
     serverProxy.SetEsbProxy(mockHubProxy.Object);
     //------------Execute Test---------------------------
     var resultOfExecution = serverProxy.ExecuteCommand(new StringBuilder("some payload"), Guid.NewGuid());
     //------------Assert Results-------------------------
     mockHubProxy.VerifyAll();
     Assert.AreEqual(serverMsg, resultOfExecution.ToString());
 }
Exemple #3
0
        public ManagementApiE2ETests()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            _namespaceUriString = Environment.GetEnvironmentVariable(NotificationHubNamespaceUriString.ToUpperInvariant()) ?? configuration[NotificationHubNamespaceUriString];
            _notificationHubConnectionString = Environment.GetEnvironmentVariable(NotificationHubConnectionString.ToUpperInvariant()) ?? configuration[NotificationHubConnectionString];
            _notificationHubName             = Environment.GetEnvironmentVariable(NotificationHubName.ToUpperInvariant()) ?? configuration[NotificationHubName];

            var storageAccount         = Environment.GetEnvironmentVariable(StorageAccount.ToUpperInvariant()) ?? configuration[StorageAccount];
            var storagePassword        = Environment.GetEnvironmentVariable(StoragePassword.ToUpperInvariant()) ?? configuration[StoragePassword];
            var storageEndpointAddress = Environment.GetEnvironmentVariable(StorageEndpointString.ToUpperInvariant()) ?? configuration[StorageEndpointString];
            var containerName          = Environment.GetEnvironmentVariable(ContainerName.ToUpperInvariant()) ?? configuration[ContainerName];


            _testServer = new TestServerProxy();
            if (_notificationHubConnectionString == "<insert value here before running tests>")
            {
                _notificationHubConnectionString = "Endpoint=sb://sample.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=xxxxxx";
                _namespaceManager = CreateNamespaceManager(RecordingMode.Playback, _notificationHubConnectionString);
            }
            else
            {
                _namespaceManager = CreateNamespaceManager(RecordingMode.Recording, _notificationHubConnectionString);
            }
            if (storageAccount != "<insert value here before running tests>")
            {
                CleanUp();
                _testServer.RecordingMode = RecordingMode.Recording;
                var storageEndpoint = new StorageUri(new Uri(storageEndpointAddress));
                var blobClient      = new CloudBlobClient(
                    storageEndpoint,
                    new StorageCredentials(storageAccount, storagePassword));

                var container = blobClient.GetContainerReference(containerName);

                _outputContainerSasUri = GetOutputDirectoryUrl(container);
                _inputFileSasUri       = GetInputFileUrl(container, InputFileName);
            }
            else
            {
                _testServer.RecordingMode = RecordingMode.Playback;
                _outputContainerSasUri    = new Uri("https://test.blob.core.windows.net/");
                _inputFileSasUri          = new Uri("https://test.blob.core.windows.net/");
            }
        }
 public void ServerProxy_ExecuteCommand_WithArgs_ShouldInvokeCorrectly()
 {
     //------------Setup for test--------------------------
     var serverMsg = "server result";
     var mockHubProxy = new Mock<IHubProxy>();
     var ExpectedResult = new Receipt {PartID = 0, ResultParts = 1};
     mockHubProxy.Setup(proxy => proxy.Invoke<Receipt>("ExecuteCommand", It.IsAny<Envelope>(), It.IsAny<bool>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Returns(new Task<Receipt>(() => ExpectedResult));
     mockHubProxy.Setup(proxy => proxy.Invoke<string>("FetchExecutePayloadFragment", It.IsAny<FutureReceipt>())).Returns(new Task<string>(() => serverMsg));
     var serverProxy = new TestServerProxy();
     serverProxy.SetEsbProxy(mockHubProxy.Object);
     //------------Execute Test---------------------------
     var resultOfExecution = serverProxy.ExecuteCommand(new StringBuilder("some payload"), Guid.NewGuid(), Guid.NewGuid());
     //------------Assert Results-------------------------
     mockHubProxy.VerifyAll();
     Assert.AreEqual(serverMsg, resultOfExecution.ToString());
 }
        public void ServerProxy_Wait_TaskThrowsHttpClientException_ExceptionHandledAndTaskIsFaultedAndIsConnectedIsTrue()
        {
            //------------Setup for test--------------------------
            const string ExMessage = "StatusCode: 403";
            var result = new StringBuilder();
            var task = new Task<string>(() =>
            {
                throw new HttpClientException(ExMessage);
            });


            var serverProxy = new TestServerProxy
            {
                IsConnected = true
            };

            //------------Execute Test---------------------------
            serverProxy.TestWait(task, result);

            //------------Assert Results-------------------------
            StringAssert.Contains(result.ToString(), ExMessage);
            Assert.IsTrue(task.IsFaulted);
            Assert.IsTrue(serverProxy.IsConnected);
        }
        public void ServerProxy_Wait_TaskThrowsReconnectingBeforeInvocationInvalidOperationException_ExceptionHandledAndTaskIsFaultedAndIsConnectedIsTrue()
        {
            //------------Setup for test--------------------------
            const string ExMessage = "Connection started reconnecting before invocation result was received";
            var result = new StringBuilder();
            var task = new Task<string>(() =>
            {
                throw new InvalidOperationException(ExMessage);
            });

            var serverProxy = new TestServerProxy
            {
                IsConnected = true
            };

            //------------Execute Test---------------------------
            serverProxy.TestWait(task, result);

            //------------Assert Results-------------------------
            StringAssert.Contains(result.ToString(), ExMessage);
            Assert.IsTrue(task.IsFaulted);
            Assert.IsTrue(serverProxy.IsConnected);
        }