public void CreateConverterShouldInvokeCreateGlobalSettings()
        {
            // Arrange
            var globalSettingsPtr = new IntPtr(_fixture.Create <int>());
            var converterPtr      = new IntPtr(_fixture.Create <int>());

            _module.Setup(m =>
                          m.CreateGlobalSettings())
            .Returns(globalSettingsPtr);
            _module.Setup(m =>
                          m.CreateConverter(It.IsAny <IntPtr>()))
            .Returns(converterPtr);
            _module.Setup(
                m =>
                m.SetGlobalSetting(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string?>()));
            var document = new HtmlToImageDocument();

            // Act
            var result = _sut.CreateConverter(document);

            // Assert
            using (new AssertionScope())
            {
                _module.Verify(m => m.CreateGlobalSettings(), Times.Once);
                _module.Verify(
                    m =>
                    m.SetGlobalSetting(
                        It.IsAny <IntPtr>(),
                        It.IsAny <string>(),
                        It.IsAny <string?>()),
                    Times.Never);
                result.converterPtr.Should().Be(converterPtr);
                result.globalSettingsPtr.Should().Be(globalSettingsPtr);
            }
        }
Beispiel #2
0
        public async Task ConvertAsyncShouldReturnStreamWhenConverted()
        {
            // Arrange
            _engineMock.Setup(
                e =>
                e.AddConvertWorkItem(It.IsAny <ConvertWorkItemBase>(), It.IsAny <CancellationToken>()))
            .Callback <ConvertWorkItemBase, CancellationToken>(
                (
                    i,
                    _) =>
            {
                i.TaskCompletionSource.SetResult(true);
            });
            using var memoryStream = new MemoryStream();

            var document = new HtmlToImageDocument();

            // Act
            var result = await _sut.ConvertAsync(document, _ => memoryStream, CancellationToken.None);

            // Assert
            using (new AssertionScope())
            {
                _engineMock.Verify(
                    e =>
                    e.AddConvertWorkItem(It.IsAny <ConvertWorkItemBase>(), It.IsAny <CancellationToken>()),
                    Times.Once);
                result.Should().BeTrue();
            }
        }
Beispiel #3
0
        public void ShouldHaveNonNullImageSettingsAfterInitialization()
        {
            // Arrange
            var sut = new HtmlToImageDocument();

            // Assert
            sut.ImageSettings.Should().NotBeNull();
        }
Beispiel #4
0
        public HtmlToImageDocumentInstance(ObjectInstance prototype, HtmlToImageDocument htmlToImageDocument)
            : this(prototype)
        {
            if (htmlToImageDocument == null)
            {
                throw new ArgumentNullException("htmlToImageDocument");
            }

            m_htmlToImageDocument = htmlToImageDocument;
        }
        public void ConvertShouldThrowExceptionWhenNullCreateStreamFuncPassed()
        {
            // Arrange
            var document = new HtmlToImageDocument();

#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
            Action action = () => _sut.Convert(document, null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.

            // Act & Assert
            action.Should().Throw <ArgumentException>();
        }
        public void ConvertImplShouldThrowExceptionWhenModuleInitializeNotEqualOne()
        {
            // Arrange
            var document = new HtmlToImageDocument();

            _module.Setup(m => m.Initialize(It.IsAny <int>()))
            .Returns(0);

            Action action = () => _sut.Convert(document, _ => Stream.Null);

            // Act & Assert
            action.Should().Throw <ArgumentException>();
        }
        public void ConvertShouldReturnStreamWhenConverted()
        {
            // Arrange
            using var memoryStream = new MemoryStream();
            var globalSettingsPtr = new IntPtr(_fixture.Create <int>());
            var converterPtr      = new IntPtr(_fixture.Create <int>());

            _module.Setup(m => m.Initialize(It.IsAny <int>()))
            .Returns(1);
            _module.Setup(m =>
                          m.CreateGlobalSettings())
            .Returns(globalSettingsPtr);
            _module.Setup(m =>
                          m.CreateConverter(It.IsAny <IntPtr>()))
            .Returns(converterPtr);
            _module.Setup(
                m =>
                m.SetGlobalSetting(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string?>()));
            _module.Setup(m => m.Convert(It.IsAny <IntPtr>()))
            .Returns(true);
            _module.Setup(m => m.GetOutput(It.IsAny <IntPtr>(), It.IsAny <Func <int, Stream> >()));
            _module.Setup(m => m.DestroyGlobalSetting(It.IsAny <IntPtr>()));
            _module.Setup(m => m.DestroyConverter(It.IsAny <IntPtr>()));
            ////_module.Setup(m => m.Terminate());
            var document = new HtmlToImageDocument();
            var quality  = _fixture.Create <string>();

            document.ImageSettings.Quality = quality;

            // Act
            // ReSharper disable once AccessToDisposedClosure
            var result = _sut.Convert(document, _ => memoryStream);

            // Assert
            using (new AssertionScope())
            {
                _module.Verify(m => m.CreateGlobalSettings(), Times.Once);
                _module.Verify(
                    m =>
                    m.SetGlobalSetting(
                        It.Is <IntPtr>(v => v == globalSettingsPtr),
                        It.Is <string>(v => v == "quality"),
                        It.Is <string?>(v => v == quality)),
                    Times.Once);
                _module.Verify(m => m.GetOutput(It.IsAny <IntPtr>(), It.IsAny <Func <int, Stream> >()), Times.Once);
                _module.Verify(m => m.DestroyGlobalSetting(It.IsAny <IntPtr>()), Times.Once);
                _module.Verify(m => m.DestroyConverter(It.IsAny <IntPtr>()), Times.Once);
                ////_module.Verify(m => m.Terminate(), Times.Once);
                result.Should().BeTrue();
            }
        }
Beispiel #8
0
        public FileResult ImageTest()
        {
            var doc = new HtmlToImageDocument()
            {
                In           = "www.google.com",
                Format       = "jpg",
                ScreenWidth  = 500,
                ScreenHeight = 500
            };

            var result = imageConverter.Convert(doc);

            return(File(result, "image/jpeg"));
        }
        public void ConvertImplShouldThrowExceptionWhenNullImageSettingsPassed()
        {
            // Arrange
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
            var document = new HtmlToImageDocument
            {
                ImageSettings = null,
            };
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
            Action action = () => _sut.Convert(document, _ => Stream.Null);

            // Act & Assert
            action.Should().Throw <ArgumentException>();
        }
        public void ConvertShouldReturnNullStreamWhenNotConverted()
        {
            // Arrange
            var globalSettingsPtr = new IntPtr(_fixture.Create <int>());
            var converterPtr      = new IntPtr(_fixture.Create <int>());

            _module.Setup(m => m.Initialize(It.IsAny <int>()))
            .Returns(1);
            _module.Setup(m =>
                          m.CreateGlobalSettings())
            .Returns(globalSettingsPtr);
            _module.Setup(m =>
                          m.CreateConverter(It.IsAny <IntPtr>()))
            .Returns(converterPtr);
            _module.Setup(
                m =>
                m.SetGlobalSetting(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string?>()));
            _module.Setup(m => m.Convert(It.IsAny <IntPtr>()))
            .Returns(false);
            _module.Setup(m => m.GetOutput(It.IsAny <IntPtr>(), It.IsAny <Func <int, Stream> >()));
            _module.Setup(m => m.DestroyGlobalSetting(It.IsAny <IntPtr>()));
            _module.Setup(m => m.DestroyConverter(It.IsAny <IntPtr>()));
            ////_module.Setup(m => m.Terminate());
            var document = new HtmlToImageDocument();
            var quality  = _fixture.Create <string>();

            document.ImageSettings.Quality = quality;

            // Act
            var result = _sut.Convert(document, _ => Stream.Null);

            // Assert
            using (new AssertionScope())
            {
                _module.Verify(m => m.CreateGlobalSettings(), Times.Once);
                _module.Verify(
                    m =>
                    m.SetGlobalSetting(
                        It.Is <IntPtr>(v => v == globalSettingsPtr),
                        It.Is <string>(v => v == "quality"),
                        It.Is <string?>(v => v == quality)),
                    Times.Once);
                _module.Verify(m => m.GetOutput(It.IsAny <IntPtr>(), It.IsAny <Func <int, Stream> >()), Times.Never);
                _module.Verify(m => m.DestroyGlobalSetting(It.IsAny <IntPtr>()), Times.Once);
                _module.Verify(m => m.DestroyConverter(It.IsAny <IntPtr>()), Times.Once);
                ////_module.Verify(m => m.Terminate(), Times.Once);
                result.Should().BeFalse();
            }
        }
        public FileResult ImageTest()
        {
            var doc = new HtmlToImageDocument() 
            { 
                In = "www.google.com", 
                Format = "jpg", 
                ScreenWidth = 500, 
                ScreenHeight = 500
            };

            var result = imageConverter.Convert(doc);

            return File(result, "image/jpeg");
        }