public void Should_ReturnValidPdfOptionsObject(PdfOptions pdfOptions) { // Arrange // TODO: Do sth with that properties. var omittedProperties = new List <string> { "Format", "MarginOptions" }; var sut = new PdfOptionsConverter(); // Act var res = sut.Convert(pdfOptions); // Assert var dstProperties = res.GetType() .GetProperties() .Where(x => !omittedProperties.Contains(x.Name)); foreach (var dstProperty in dstProperties) { var srcPropertyValue = pdfOptions.GetType() .GetProperty(dstProperty.Name) .GetValue(pdfOptions, null); dstProperty.GetValue(res, null).Should().Be(srcPropertyValue); } }
private string GetSwitchesBas(PdfOptions options) { var result = new StringBuilder(); var fields = options.GetType().GetProperties(); foreach (var fi in fields) { if (!(fi.GetCustomAttributes(typeof(OptionFlag), true).FirstOrDefault() is OptionFlag of)) { continue; } var value = fi.GetValue(options, null); if (value == null) { continue; } if (fi.PropertyType == typeof(Dictionary <string, string>)) { var dictionary = (Dictionary <string, string>)value; foreach (var d in dictionary) { result.AppendFormat(" {0} {1} {2}", of.Name, d.Key, d.Value); } } else if (fi.PropertyType == typeof(bool)) { if ((bool)value) { result.AppendFormat(CultureInfo.InvariantCulture, " {0}", of.Name); } } else { result.AppendFormat(CultureInfo.InvariantCulture, " {0} {1}", of.Name, value); } } return(result.ToString().Trim()); }