public async void InvokeFromStreamAsync_WithTypeParameter_WithModuleFactory_IfModuleIsCachedInvokesFromCacheOtherwiseInvokesFromStream()
        {
            // Arrange
            const int             dummyResult            = 1;
            Func <Stream>         dummyModuleFactory     = () => new MemoryStream();
            const string          dummyCacheIdentifier   = "dummyCacheIdentifier";
            const string          dummyExportName        = "dummyExportName";
            var                   dummyArgs              = new object[0];
            var                   dummyCancellationToken = new CancellationToken();
            Mock <INodeJSService> mockNodeJSService      = _mockRepository.Create <INodeJSService>();

            mockNodeJSService.
            Setup(t => t.InvokeFromStreamAsync <int>(dummyModuleFactory, dummyCacheIdentifier, dummyExportName, dummyArgs, dummyCancellationToken)).
            ReturnsAsync(dummyResult);
            var dummyServices = new ServiceCollection();

            dummyServices.AddSingleton(typeof(INodeJSService), mockNodeJSService.Object);
            StaticNodeJSService.SetServices(dummyServices);

            // Act
            int result = await StaticNodeJSService.InvokeFromStreamAsync <int>(dummyModuleFactory, dummyCacheIdentifier, dummyExportName, dummyArgs, dummyCancellationToken).ConfigureAwait(false);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(dummyResult, result);
        }
        public async void InvokeFromStreamAsync_InvokesJavascript()
        {
            // Arrange
            const string dummyResultString = "success";

            DummyResult result;

            using (var memoryStream = new MemoryStream())
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    streamWriter.Write("module.exports = (callback, resultString) => callback(null, {result: resultString});");
                    streamWriter.Flush();
                    memoryStream.Position = 0;

                    // Act
                    result = await StaticNodeJSService.InvokeFromStreamAsync <DummyResult>(memoryStream, args : new[] { dummyResultString }).ConfigureAwait(false);
                }

            // Assert
            Assert.Equal(dummyResultString, result.Result);
        }
        public async void InvokeFromStreamAsync_WithoutTypeParameter_WithRawStreamModule_InvokesFromStream()
        {
            // Arrange
            var                   dummyModuleStream       = new MemoryStream();
            const string          dummyNewCacheIdentifier = "dummyNewCacheIdentifier";
            const string          dummyExportName         = "dummyExportName";
            var                   dummyArgs = new object[0];
            var                   dummyCancellationToken = new CancellationToken();
            Mock <INodeJSService> mockNodeJSService      = _mockRepository.Create <INodeJSService>();

            mockNodeJSService.Setup(t => t.InvokeFromStreamAsync(dummyModuleStream, dummyNewCacheIdentifier, dummyExportName, dummyArgs, dummyCancellationToken));
            var dummyServices = new ServiceCollection();

            dummyServices.AddSingleton(typeof(INodeJSService), mockNodeJSService.Object);
            StaticNodeJSService.SetServices(dummyServices);

            // Act
            await StaticNodeJSService.InvokeFromStreamAsync(dummyModuleStream, dummyNewCacheIdentifier, dummyExportName, dummyArgs, dummyCancellationToken).ConfigureAwait(false);

            // Assert
            _mockRepository.VerifyAll();
        }
Example #4
0
 public Task InvokeFromStreamAsync(Func <Stream> moduleFactory, string cacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
 {
     return(StaticNodeJSService.InvokeFromStreamAsync(moduleFactory, cacheIdentifier, exportName, args, cancellationToken));
 }
Example #5
0
 public Task InvokeFromStreamAsync(Stream moduleStream, string newCacheIdentifier = null, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
 {
     return(StaticNodeJSService.InvokeFromStreamAsync(moduleStream, newCacheIdentifier, exportName, args, cancellationToken));
 }