public void IsNotNullOrWhiteSpace_ShouldThrowArgumentNullException_WhenArgumentIsNull(string argumentValue, string argumentName, string message)
        {
            var argumentNullException = Assert.Throws <ArgumentNullException>(() =>
                                                                              AssertArgument.NotNullOrWhiteSpace(argumentValue, argumentName, message));

            argumentNullException.ParamName.Should().Be(argumentName);
        }
示例#2
0
        /// <summary>
        /// Validates that a string is a valid url
        /// </summary>
        /// <param name="value">The string being validated</param>
        /// <returns></returns>
        public static bool IsValidUrl(this string value)
        {
            AssertArgument.NotNull(value, nameof(value));

            return(Uri.TryCreate(value, UriKind.Absolute, out var uriResult) &&
                   (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps));
        }
        public void IsNotNullOrEmpty_ShouldThrowArgumentNullException()
        {
            var argumentNullException = Assert.Throws <ArgumentNullException>(() =>
                                                                              AssertArgument.NotNullOrEmpty(null, "ArgumentName", "Failed"));

            argumentNullException.ParamName.Should().Be("ArgumentName");
        }
        public void IsPositive_Int_WhenPositive_DoesNothing()
        {
            //Arrange
            int argument = 1;

            //Act
            AssertArgument.IsPositive(nameof(argument), argument);
        }
        public void IsPositive_Float_WhenPositive_DoesNothing()
        {
            //Arrange
            float argument = 1f;

            //Act
            AssertArgument.IsPositive(nameof(argument), argument);
        }
        public void IsNotNullOrEmpty_String_WhenListHasEntries_DoesNothing()
        {
            //Arrange
            string argument = "Non-empty string";

            //Act
            AssertArgument.IsNotNullOrEmpty(nameof(argument), argument);
        }
        public void IsNotNull_Object_WhenObjectIsNotNull_DoesNothing()
        {
            //Arrange
            object argument = new object();

            //Act
            AssertArgument.IsNotNull(nameof(argument), argument);
        }
        public void IsNotNullOrEmpty_ShouldThrowArgumentException()
        {
            var argumentNullException = Assert.Throws <ArgumentException>(() =>
                                                                          AssertArgument.NotNullOrEmpty(new List <string>(), "ArgumentName", "Failed1"));

            argumentNullException.ParamName.Should().Be("ArgumentName");
            argumentNullException.Message.Should().StartWith("Failed1");
        }
示例#9
0
        /// <summary>
        /// Converts unit time to <see cref="DateTime"/>
        /// </summary>
        /// <param name="unixTimeStamp"></param>
        /// <returns>The unix time converted to <see cref="DateTime"/></returns>
        public static DateTime ConvertUnixTimeToDateTime(long unixTimeStamp)
        {
            AssertArgument.NotNull(unixTimeStamp, nameof(unixTimeStamp));

            var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            var result   = dateTime.AddSeconds(unixTimeStamp);

            return(result);
        }
        public FileConverter(IFileProcessor fileProcessor,
                             List <Resolution> suppliedResolutions)
        {
            AssertArgument.IsNotNull(nameof(fileProcessor), fileProcessor);
            AssertArgument.IsNotNullOrEmpty(nameof(suppliedResolutions), suppliedResolutions);

            this.fileProcessor       = fileProcessor;
            this.suppliedResolutions = suppliedResolutions;
        }
        public SVGToPNGConverter(ISVGWrapper svgDocumentWrapper, IBitmapWrapper bitmapWrapper, IFileSystemProvider fileSystemProvider)
        {
            AssertArgument.IsNotNull(nameof(svgDocumentWrapper), svgDocumentWrapper);
            AssertArgument.IsNotNull(nameof(bitmapWrapper), bitmapWrapper);
            AssertArgument.IsNotNull(nameof(fileSystemProvider), fileSystemProvider);

            this.svgDocumentWrapper = svgDocumentWrapper;
            this.bitmapWrapper      = bitmapWrapper;
            this.fileSystemProvider = fileSystemProvider;
        }
        public void IsNotNullOrEmpty_List_WhenListHasEntries_DoesNothing()
        {
            //Arrange
            var argument = new List <object> {
                new object()
            };

            //Act
            AssertArgument.IsNotNullOrEmpty(nameof(argument), argument);
        }
        public void ConvertFiles(List <string> filesToConvert, List <Resolution> selectedResolutions, string saveLocation)
        {
            AssertArgument.IsNotNullOrEmpty(nameof(filesToConvert), filesToConvert);
            AssertArgument.IsNotNullOrEmpty(nameof(selectedResolutions), selectedResolutions);
            AssertArgument.IsNotNullOrEmpty(nameof(saveLocation), saveLocation);

            List <ImageSize> sizes = selectedResolutions.Select(x => x.ConvertToImageSize()).ToList();

            fileProcessor.ConvertSVGToPNG(filesToConvert, sizes, saveLocation).ToList();
        }
示例#14
0
        public Resolution(float widthInches, float heightInches, int dpi)
        {
            AssertArgument.IsPositive(nameof(widthInches), widthInches);
            AssertArgument.IsPositive(nameof(heightInches), heightInches);
            AssertArgument.IsPositive(nameof(dpi), dpi);

            Width  = widthInches;
            Height = heightInches;
            DPI    = dpi;
        }
示例#15
0
        public ImageSize(int pixelWidth, int pixelHeight, int dpi)
        {
            AssertArgument.IsPositive(nameof(pixelWidth), pixelWidth);
            AssertArgument.IsPositive(nameof(pixelHeight), pixelHeight);
            AssertArgument.IsPositive(nameof(dpi), dpi);

            PixelWidth  = pixelWidth;
            PixelHeight = pixelHeight;
            DPI         = dpi;
            Width       = ToInches(PixelWidth, DPI);
            Height      = ToInches(pixelHeight, dpi);
        }
示例#16
0
        public ImageSize(float width, float height, int dpi)
        {
            AssertArgument.IsPositive(nameof(width), width);
            AssertArgument.IsPositive(nameof(height), height);
            AssertArgument.IsPositive(nameof(dpi), dpi);

            Width       = width;
            Height      = height;
            DPI         = dpi;
            PixelHeight = ToPixels(height, dpi);
            PixelWidth  = ToPixels(width, dpi);
        }
示例#17
0
        public FileProcessor([Named(ConverterType.SVGToPNG)] IImageConverter svgToPNGConverter,
                             [Named(ConverterType.AIToSVG)] IImageConverter aiToSVGConverter)
        {
            AssertArgument.IsNotNull(nameof(svgToPNGConverter), svgToPNGConverter);
            AssertArgument.IsNotNull(nameof(aiToSVGConverter), aiToSVGConverter);

            this.aiToSVGConverter  = aiToSVGConverter;
            this.svgToPNGConverter = svgToPNGConverter;

            SkipSizeIterator = new List <ImageSize> {
                new ImageSize(1, 1)
            };
        }
        public void IsNotNullOrEmpty_List_WhenListIsNull_ThrowsException()
        {
            //Arrange
            List <object> argument     = null;
            string        argumentName = "0AA69E84-F022-4B6A-AE13-4B69719E4C89";

            try
            {
                //Act
                AssertArgument.IsNotNullOrEmpty(argumentName, argument);
            }
            catch (Exception ex)
            {
                //Assert
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
                Assert.IsTrue(ex.Message.Contains(argumentName));
                return;
            }

            FailOnNoException();
        }
        public void IsNotNullOrEmpty_List_WhenListIsEmpty_ThrowsException()
        {
            //Arrange
            var    argument        = new List <object>();
            string expectedMessage = GetArgumentIsEmptyExceptionMessage(nameof(argument));

            try
            {
                //Act
                AssertArgument.IsNotNullOrEmpty(nameof(argument), argument);
            }
            catch (Exception ex)
            {
                //Assert
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.AreEqual(expectedMessage, ex.Message);
                return;
            }

            FailOnNoException();
        }
        public void IsPositive_Int_WhenZero_ThrowsException()
        {
            //Arrange
            int    argument        = 0;
            string argumentName    = "0AA69E84-F022-4B6A-AE13-4B69719E4C89";
            string expectedMessage = GetArgumentMustBePositiveExceptionMessage(argumentName);

            try
            {
                //Act
                AssertArgument.IsPositive(argumentName, argument);
            }
            catch (Exception ex)
            {
                //Assert
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.AreEqual(expectedMessage, ex.Message);
                return;
            }

            FailOnNoException();
        }
示例#21
0
        public AIToSVGConverter(IIllustratorProvider illustratorProvider)
        {
            AssertArgument.IsNotNull(nameof(illustratorProvider), illustratorProvider);

            this.illustratorProvider = illustratorProvider;
        }
示例#22
0
 public void IsNotNullOrEmpty_ShouldNotThrowException_WithValidArgument()
 {
     AssertArgument.NotNullOrEmpty(new List <string> {
         "Hello"
     }, "ExampleName", "Message example");
 }
示例#23
0
 public void IsNotNullOrWhiteSpace_ShouldNotThrowException_WithValidArgument()
 {
     AssertArgument.NotNullOrWhiteSpace("Hello", "Name", "message");
 }
示例#24
0
 public void IsNotNull_ShouldNotThrowException_WithNotNullArgument()
 {
     AssertArgument.NotNull(new DateTime(), "testName");
 }
示例#25
0
        public void IsNotNull_ShouldThrowArgumentNullException_WithNullArgument()
        {
            var argumentException = Assert.Throws <ArgumentNullException>(() => AssertArgument.NotNull(null, "testName"));

            argumentException.ParamName.Should().Be("testName");
        }
示例#26
0
        /// <inheritdoc/>
        public Task <Url> GetUrl(string shortUrl)
        {
            AssertArgument.NotNull(shortUrl, nameof(shortUrl));

            return(this.urlRepository.GetByShortUrl(shortUrl));
        }