public async Task IsValidLanguageAliasAsync_IfSuccessfulReturnsTrueIfAliasesContainsLanguageAliasAndFalseIfItDoesNot(
            string dummyLanguageAlias,
            string[] dummyAliases,
            bool expectedResult)
        {
            // Arrange
            var dummyStream = new MemoryStream();
            Mock <IEmbeddedResourcesService> mockEmbeddedResourcesService = _mockRepository.Create <IEmbeddedResourcesService>();

            mockEmbeddedResourcesService.
            Setup(e => e.ReadAsStream(typeof(PrismService).GetTypeInfo().Assembly, PrismService.BUNDLE_NAME)).
            Returns(dummyStream);
            Mock <INodeJSService> mockNodeJSService = _mockRepository.Create <INodeJSService>();

            mockNodeJSService.
            Setup(n => n.InvokeFromStreamAsync <string[]>(
                      dummyStream,
                      PrismService.MODULE_CACHE_IDENTIFIER,
                      "getAliases",
                      null,
                      default(CancellationToken))).
            ReturnsAsync(dummyAliases);
            using (PrismService testSubject = CreatePrismService(mockNodeJSService.Object, mockEmbeddedResourcesService.Object))
            {
                // Act
                bool result = await testSubject.IsValidLanguageAliasAsync(dummyLanguageAlias).ConfigureAwait(false);

                // Assert
                Assert.Equal(expectedResult, result);
            }
            _mockRepository.VerifyAll();
        }
        public async Task HighlightAsync_ThrowsObjectDisposedExceptionIfInstanceHasBeenDisposed()
        {
            // Arrange
            PrismService testSubject = CreatePrismService();

            testSubject.Dispose();

            // Act and assert
            ObjectDisposedException result = await Assert.
                                             ThrowsAsync <ObjectDisposedException>(async() => await testSubject.HighlightAsync(null, null).ConfigureAwait(false)).
                                             ConfigureAwait(false);
        }
        public async Task IsValidLanguageAliasAsync_ReturnsFalseIfLanguageAliasIsNullOrWhitespace(string dummyLanguageAlias)
        {
            // Arrange
            using (PrismService testSubject = CreatePrismService())
            {
                // Act
                bool result = await testSubject.IsValidLanguageAliasAsync(dummyLanguageAlias).ConfigureAwait(false);

                // Assert
                Assert.False(result);
            }
        }
        public void Dispose_DoesNothingIfInstanceIsAlreadyDisposed()
        {
            // Arrange
            Mock <INodeJSService> mockNodeJSService = _mockRepository.Create <INodeJSService>();
            PrismService          testSubject       = CreatePrismService(mockNodeJSService.Object);

            // Act
            testSubject.Dispose();
            testSubject.Dispose();

            // Assert
            mockNodeJSService.Verify(n => n.Dispose(), Times.Once());
        }
        public async Task IsValidLanguageAliasAsync_ThrowsObjectDisposedExceptionIfInstanceHasBeenDisposed()
        {
            // Arrange
            using (PrismService testSubject = CreatePrismService())
            {
                testSubject.Dispose();

                // Act and assert
                ObjectDisposedException result = await Assert.
                                                 ThrowsAsync <ObjectDisposedException>(async() => await testSubject.IsValidLanguageAliasAsync(null, default(CancellationToken)).ConfigureAwait(false)).
                                                 ConfigureAwait(false);
            }
        }
        public void IsValidLanguageAliasAsync_FirstThreadLazilyRetrievesAliases()
        {
            // Arrange
            const string dummyLanguageAlias = "dummyLanguageAlias";
            var          dummyStream        = new MemoryStream();
            Mock <IEmbeddedResourcesService> mockEmbeddedResourcesService = _mockRepository.Create <IEmbeddedResourcesService>();

            mockEmbeddedResourcesService.
            Setup(e => e.ReadAsStream(typeof(PrismService).GetTypeInfo().Assembly, PrismService.BUNDLE_NAME)).
            Returns(dummyStream);
            Mock <INodeJSService> mockNodeJSService = _mockRepository.Create <INodeJSService>();

            mockNodeJSService.
            Setup(n => n.InvokeFromStreamAsync <string[]>(
                      dummyStream,
                      PrismService.MODULE_CACHE_IDENTIFIER,
                      "getAliases",
                      null,
                      default(CancellationToken))).
            ReturnsAsync(new string[] { dummyLanguageAlias });
            using (PrismService testSubject = CreatePrismService(mockNodeJSService.Object, mockEmbeddedResourcesService.Object))
            {
                // Act
                var       results    = new ConcurrentQueue <bool>();
                const int numThreads = 5;
                var       threads    = new List <Thread>();
                for (int i = 0; i < numThreads; i++)
                {
                    var thread = new Thread(() => results.Enqueue(testSubject.IsValidLanguageAliasAsync(dummyLanguageAlias).GetAwaiter().GetResult()));
                    threads.Add(thread);
                    thread.Start();
                }
                foreach (Thread thread in threads)
                {
                    thread.Join();
                }

                // Assert
                _mockRepository.VerifyAll();
                mockEmbeddedResourcesService.Verify(e => e.ReadAsStream(typeof(PrismService).GetTypeInfo().Assembly, PrismService.BUNDLE_NAME), Times.Once()); // Only called when aliases hasn't been instantiated
                Assert.Equal(numThreads, results.Count);
                foreach (bool result in results)
                {
                    Assert.True(result);
                }
            }
        }