diff --git a/ClosedXML.Report/Excel/SubtotalGroup.cs b/ClosedXML.Report/Excel/SubtotalGroup.cs index c810162..75eca77 100644 --- a/ClosedXML.Report/Excel/SubtotalGroup.cs +++ b/ClosedXML.Report/Excel/SubtotalGroup.cs @@ -1,4 +1,3 @@ -using System; using ClosedXML.Excel; namespace ClosedXML.Report.Excel diff --git a/ClosedXML.Report/Excel/SubtotalSummaryFunc.cs b/ClosedXML.Report/Excel/SubtotalSummaryFunc.cs index 8d1bd51..a4fc542 100644 --- a/ClosedXML.Report/Excel/SubtotalSummaryFunc.cs +++ b/ClosedXML.Report/Excel/SubtotalSummaryFunc.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq.Expressions; using ClosedXML.Report.Utils; namespace ClosedXML.Report.Excel diff --git a/ClosedXML.Report/FormulaEvaluator.cs b/ClosedXML.Report/FormulaEvaluator.cs index 1515fc3..f830bf2 100644 --- a/ClosedXML.Report/FormulaEvaluator.cs +++ b/ClosedXML.Report/FormulaEvaluator.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Linq.Dynamic.Core.Exceptions; using System.Linq.Expressions; using System.Reflection; using System.Text.RegularExpressions; diff --git a/ClosedXML.Report/Options/AutoFilterTag.cs b/ClosedXML.Report/Options/AutoFilterTag.cs index 5182966..e76e532 100644 --- a/ClosedXML.Report/Options/AutoFilterTag.cs +++ b/ClosedXML.Report/Options/AutoFilterTag.cs @@ -1,6 +1,4 @@ -using ClosedXML.Report.Excel; - -namespace ClosedXML.Report.Options +namespace ClosedXML.Report.Options { public class AutoFilterTag : OptionTag { diff --git a/ClosedXML.Report/Options/HiddenTag.cs b/ClosedXML.Report/Options/HiddenTag.cs index 65c19f1..b975028 100644 --- a/ClosedXML.Report/Options/HiddenTag.cs +++ b/ClosedXML.Report/Options/HiddenTag.cs @@ -1,5 +1,4 @@ -using ClosedXML.Excel; -using MoreLinq; +using MoreLinq; namespace ClosedXML.Report.Options { diff --git a/ClosedXML.Report/Options/ImageTag.cs b/ClosedXML.Report/Options/ImageTag.cs index 48168d9..795e5df 100644 --- a/ClosedXML.Report/Options/ImageTag.cs +++ b/ClosedXML.Report/Options/ImageTag.cs @@ -31,7 +31,8 @@ public override void Execute(ProcessingContext context) case Stream stream: picture = xlCell.Worksheet.AddPicture(stream); break; case string path: picture = xlCell.Worksheet.AddPicture(path); break; default: throw new TemplateParseException("Unsupported image type.", xlCell.AsRange()); - }; + } + picture.MoveTo(xlCell); if (!string.IsNullOrEmpty(ImageName)) picture.Name = ImageName; if (Scale > 0) picture.Scale(Scale); diff --git a/ClosedXML.Report/Options/OptionTag.cs b/ClosedXML.Report/Options/OptionTag.cs index fd204dd..0678f28 100644 --- a/ClosedXML.Report/Options/OptionTag.cs +++ b/ClosedXML.Report/Options/OptionTag.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using ClosedXML.Excel; -using ClosedXML.Report.Excel; namespace ClosedXML.Report.Options { diff --git a/ClosedXML.Report/Options/ValidationTag.cs b/ClosedXML.Report/Options/ValidationTag.cs index 6aa3e5f..8186906 100644 --- a/ClosedXML.Report/Options/ValidationTag.cs +++ b/ClosedXML.Report/Options/ValidationTag.cs @@ -25,10 +25,6 @@ InputMessage String ================================================ */ -using ClosedXML.Excel; -using ClosedXML.Report.Excel; -using ClosedXML.Report.Utils; - namespace ClosedXML.Report.Options { public class ValidationTag: OptionTag diff --git a/ClosedXML.Report/TemplateParseException.cs b/ClosedXML.Report/TemplateParseException.cs index 3a3b2eb..a87cbd9 100644 --- a/ClosedXML.Report/TemplateParseException.cs +++ b/ClosedXML.Report/TemplateParseException.cs @@ -13,7 +13,7 @@ public TemplateParseException(string message, IXLRange range) : base(message) Range = range; } - public TemplateParseException(string message, TemplateErrors errors) + public TemplateParseException(string message, TemplateErrors errors) : base(message) { InnerErrors = errors; } diff --git a/ClosedXML.Report/Utils/EnumExtensions.cs b/ClosedXML.Report/Utils/EnumExtensions.cs index 6ad7876..aaadaf2 100644 --- a/ClosedXML.Report/Utils/EnumExtensions.cs +++ b/ClosedXML.Report/Utils/EnumExtensions.cs @@ -88,12 +88,12 @@ private static ulong ToUInt64(object value) case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: - return (ulong)Convert.ToInt64(value, (IFormatProvider)CultureInfo.InvariantCulture); + return (ulong)Convert.ToInt64(value, CultureInfo.InvariantCulture); case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: - return Convert.ToUInt64(value, (IFormatProvider)CultureInfo.InvariantCulture); + return Convert.ToUInt64(value, CultureInfo.InvariantCulture); default: throw new InvalidOperationException("Invalid operation: Unknown enum type"); } diff --git a/ClosedXML.Report/Utils/TypeExtensions.cs b/ClosedXML.Report/Utils/TypeExtensions.cs index 126d5f6..73e044d 100644 --- a/ClosedXML.Report/Utils/TypeExtensions.cs +++ b/ClosedXML.Report/Utils/TypeExtensions.cs @@ -99,7 +99,7 @@ public static Type ToType(this TypeCode code) return typeof(double); case TypeCode.Empty: - return null; + break; case TypeCode.Int16: return typeof(short); @@ -180,22 +180,16 @@ public static PropertyInfo GetPropertyInfo( Expression> propertyLambda) { if (!(propertyLambda.Body is MemberExpression member)) - throw new ArgumentException(string.Format( - "Expression '{0}' refers to a method, not a property.", - propertyLambda.ToString())); + throw new ArgumentException($"Expression '{propertyLambda}' refers to a method, not a property."); PropertyInfo propInfo = member.Member as PropertyInfo; if (propInfo == null) - throw new ArgumentException(string.Format( - "Expression '{0}' refers to a field, not a property.", - propertyLambda.ToString())); + throw new ArgumentException($"Expression '{propertyLambda}' refers to a field, not a property."); if (type != propInfo.ReflectedType && !type.IsSubclassOf(propInfo.ReflectedType)) - throw new ArgumentException(string.Format( - "Expresion '{0}' refers to a property that is not from type {1}.", - propertyLambda.ToString(), - type)); + throw new ArgumentException( + $"Expression '{propertyLambda}' refers to a property that is not from type {type}."); return propInfo; } diff --git a/ClosedXML.Report/Utils/XLDynamicExpressionParser.cs b/ClosedXML.Report/Utils/XLDynamicExpressionParser.cs index 8754fdc..03961e4 100644 --- a/ClosedXML.Report/Utils/XLDynamicExpressionParser.cs +++ b/ClosedXML.Report/Utils/XLDynamicExpressionParser.cs @@ -3,7 +3,6 @@ using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core.CustomTypeProviders; using System.Linq.Expressions; -using System.Text; namespace ClosedXML.Report.Utils { diff --git a/tests/ClosedXML.Report.Tests/AutoFilterTagTests.cs b/tests/ClosedXML.Report.Tests/AutoFilterTagTests.cs index 6d4ea39..cc8003b 100644 --- a/tests/ClosedXML.Report.Tests/AutoFilterTagTests.cs +++ b/tests/ClosedXML.Report.Tests/AutoFilterTagTests.cs @@ -1,5 +1,4 @@ -using ClosedXML.Excel; -using ClosedXML.Report.Options; +using ClosedXML.Report.Options; using FluentAssertions; using Xunit; diff --git a/tests/ClosedXML.Report.Tests/FormulaEvaluatorTests.cs b/tests/ClosedXML.Report.Tests/FormulaEvaluatorTests.cs index e8a2926..25d777f 100644 --- a/tests/ClosedXML.Report.Tests/FormulaEvaluatorTests.cs +++ b/tests/ClosedXML.Report.Tests/FormulaEvaluatorTests.cs @@ -87,7 +87,7 @@ public void EvalExpressionVariableWithAt() [Fact] public void ExpressionParseTestNullPropagation() { - var customers = new Customer[] + var customers = new[] { new Customer {Id = 1, Name = "Customer1", Manager = new Customer { Id = 3, Name = "Manager1"}}, new Customer {Id = 2, Name = "Customer2", Manager = null} diff --git a/tests/ClosedXML.Report.Tests/ReportOptionsTests.cs b/tests/ClosedXML.Report.Tests/ReportOptionsTests.cs index 127672c..55f2be9 100644 --- a/tests/ClosedXML.Report.Tests/ReportOptionsTests.cs +++ b/tests/ClosedXML.Report.Tests/ReportOptionsTests.cs @@ -16,7 +16,7 @@ public class ReportOptionsTests : XlsxTemplateTestsBase public void Hidden_option_should_hide_sheet() { XlTemplateTest("5_options.xlsx", - tpl => { }, + _ => { }, wb => { wb.Worksheets.Count.Should().Be(3); @@ -28,7 +28,7 @@ public void Hidden_option_should_hide_sheet() public void OnlyValues_option_should_remove_formulas_on_sheet() { XlTemplateTest("5_options.xlsx", - tpl => { }, + _ => { }, wb => { var worksheet = wb.Worksheet(1); @@ -44,7 +44,7 @@ public void OnlyValues_option_should_remove_formulas_on_sheet() public void ColsFit_option_should_FitWidth() { XlTemplateTest("5_options.xlsx", - tpl => { }, + _ => { }, wb => { var worksheet = wb.Worksheet(1); @@ -80,8 +80,8 @@ public void DeleteOptionsWithParameter() { using (var db = new DbDemos()) { - var cust = db.customers.LoadWith(x => x.Orders.First().Items).OrderBy(c => c.CustNo).First(x => x.CustNo == 1356); - tpl.AddVariable(cust); + var customer = db.customers.LoadWith(x => x.Orders.First().Items).OrderBy(c => c.CustNo).First(x => x.CustNo == 1356); + tpl.AddVariable(customer); } tpl.AddVariable("disableCColumnDeletion", "true"); tpl.AddVariable("disableEColumnDeletion", "false"); diff --git a/tests/ClosedXML.Report.Tests/SubrangesTests.cs b/tests/ClosedXML.Report.Tests/SubrangesTests.cs index 04e2166..5a9800e 100644 --- a/tests/ClosedXML.Report.Tests/SubrangesTests.cs +++ b/tests/ClosedXML.Report.Tests/SubrangesTests.cs @@ -132,7 +132,7 @@ private IEnumerable GenerateVisitors() { return new List { - new { Name = "Alice", Attendance = new List { } }, + new { Name = "Alice", Attendance = new List() }, new { Name = "Bob", Attendance = new List { new { Month = "February", Visits = 2 }, new { Month = "March", Visits = 3 }, @@ -143,7 +143,7 @@ private IEnumerable GenerateVisitors() new { Month = "July", Visits = 8 }, new { Month = "October", Visits = 6 }, } }, - new { Name = "Daniel", Attendance = new List { } }, + new { Name = "Daniel", Attendance = new List() }, }; } diff --git a/tests/ClosedXML.Report.Tests/SubtotalSummaryFuncTests.cs b/tests/ClosedXML.Report.Tests/SubtotalSummaryFuncTests.cs index edd42b1..76e3c0e 100644 --- a/tests/ClosedXML.Report.Tests/SubtotalSummaryFuncTests.cs +++ b/tests/ClosedXML.Report.Tests/SubtotalSummaryFuncTests.cs @@ -11,19 +11,16 @@ namespace ClosedXML.Report.Tests { public class SubtotalSummaryFuncTests : XlsxTemplateTestsBase { - private IXLRange _rng; - private XLWorkbook _workbook; - public SubtotalSummaryFuncTests(ITestOutputHelper output) : base(output) { var fileName = Path.Combine(TestConstants.TemplatesFolder, "9_plaindata.xlsx"); - _workbook = new XLWorkbook(fileName); - _rng = _workbook.Range("range1"); - _rng.InsertColumnsAfter(1, true); - var clmn = _rng.LastColumn().ColumnNumber() - _rng.FirstColumn().ColumnNumber() + 1; - for (int i = 1; i <= _rng.RowCount(); i++) + var workbook = new XLWorkbook(fileName); + var rng = workbook.Range("range1"); + rng.InsertColumnsAfter(1, true); + var clmn = rng.LastColumn().ColumnNumber() - rng.FirstColumn().ColumnNumber() + 1; + for (int i = 1; i <= rng.RowCount(); i++) { - _rng.Row(i).Cell(clmn).Value = i - 1; + rng.Row(i).Cell(clmn).Value = i - 1; } } @@ -31,8 +28,8 @@ public SubtotalSummaryFuncTests(ITestOutputHelper output) : base(output) public void SumIntTest() { var sum = new SubtotalSummaryFunc("sum", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => e.Compile(); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => e.Compile(); sum.DataSource = new DataSource(new object[] { new Test(1), new Test(2), new Test(3) }); sum.Calculate(sum.DataSource).Should().Be(6); @@ -42,8 +39,8 @@ public void SumIntTest() public void SumDoubleTest() { var sum = new SubtotalSummaryFunc("sum", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => e.Compile(); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => e.Compile(); sum.DataSource = new DataSource(new object[] { new Test(1.5), new Test(2d), new Test(3.5) }); sum.Calculate(sum.DataSource).Should().Be(7d); @@ -53,9 +50,10 @@ public void SumDoubleTest() public void SumTimeSpanTest() { var sum = new SubtotalSummaryFunc("sum", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); - sum.DataSource = new DataSource(new object[] { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) }); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); + sum.DataSource = new DataSource(new object[] + { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) }); sum.Calculate(sum.DataSource).Should().Be(TimeSpan.FromHours(6)); } @@ -64,8 +62,8 @@ public void SumTimeSpanTest() public void AverageIntTest() { var sum = new SubtotalSummaryFunc("average", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); sum.DataSource = new DataSource(new object[] { new Test(1), new Test(2), new Test(3) }); sum.Calculate(sum.DataSource).Should().Be(2); @@ -75,8 +73,8 @@ public void AverageIntTest() public void AverageDoubleTest() { var sum = new SubtotalSummaryFunc("average", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); sum.DataSource = new DataSource(new object[] { new Test(1.5), new Test(2d), new Test(3.5), new Test(4.5) }); sum.Calculate(sum.DataSource).Should().Be(2.875); @@ -86,9 +84,10 @@ public void AverageDoubleTest() public void AverageTimeSpanTest() { var sum = new SubtotalSummaryFunc("average", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); - sum.DataSource = new DataSource(new object[] { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) }); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); + sum.DataSource = new DataSource(new object[] + { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) }); sum.Calculate(sum.DataSource).Should().Be(TimeSpan.FromHours(2)); } @@ -97,8 +96,8 @@ public void AverageTimeSpanTest() public void MinIntTest() { var sum = new SubtotalSummaryFunc("min", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); sum.DataSource = new DataSource(new object[] { new Test(2), new Test(1), new Test(3) }); sum.Calculate(sum.DataSource).Should().Be(1); @@ -108,8 +107,8 @@ public void MinIntTest() public void MinDoubleTest() { var sum = new SubtotalSummaryFunc("min", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); sum.DataSource = new DataSource(new object[] { new Test(2d), new Test(0.5), new Test(3.5) }); sum.Calculate(sum.DataSource).Should().Be(0.5); @@ -119,9 +118,13 @@ public void MinDoubleTest() public void MinDateTimeTest() { var sum = new SubtotalSummaryFunc("min", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); - sum.DataSource = new DataSource(new object[] { new Test(new DateTime(2017, 01, 01)), new Test(new DateTime(2016, 01, 01)), new Test(new DateTime(2018, 01, 01)) }); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); + sum.DataSource = new DataSource(new object[] + { + new Test(new DateTime(2017, 01, 01)), new Test(new DateTime(2016, 01, 01)), + new Test(new DateTime(2018, 01, 01)) + }); sum.Calculate(sum.DataSource).Should().Be(new DateTime(2016, 01, 01)); } @@ -130,21 +133,24 @@ public void MinDateTimeTest() public void StDevDoubleTest() { var sum = new SubtotalSummaryFunc("stdev", 1); - Expression> e = o => o.val; - sum.GetCalculateDelegate = type => (e.Compile()); - sum.DataSource = new DataSource(new object[] { new Test(10d), new Test(20d), new Test(30d), new Test(40d), new Test(50d), new Test(60d), new Test(70d) }); + Expression> e = o => o.Val; + sum.GetCalculateDelegate = _ => (e.Compile()); + sum.DataSource = new DataSource(new object[] + { + new Test(10d), new Test(20d), new Test(30d), new Test(40d), new Test(50d), new Test(60d), new Test(70d) + }); ((double)sum.Calculate(sum.DataSource)).Should().BeInRange(21.6, 21.61); } private class Test { - public dynamic val; + public readonly dynamic Val; public Test(dynamic val) { - this.val = val; + Val = val; } } } -} +} \ No newline at end of file diff --git a/tests/ClosedXML.Report.Tests/TempSheetBufferTests.cs b/tests/ClosedXML.Report.Tests/TempSheetBufferTests.cs index 36026cc..785d437 100644 --- a/tests/ClosedXML.Report.Tests/TempSheetBufferTests.cs +++ b/tests/ClosedXML.Report.Tests/TempSheetBufferTests.cs @@ -12,70 +12,64 @@ public class TempSheetBufferTests [Fact] public void NamedRangesAreRemovedWithTempSheet() { - using (var wb = new XLWorkbook()) - { - var ws = wb.AddWorksheet("Sheet1"); + using var wb = new XLWorkbook(); + wb.AddWorksheet("Sheet1"); - var tempSheetBuffer = new TempSheetBuffer(wb); - wb.DefinedNames.Add("Temp range", tempSheetBuffer.GetRange( - tempSheetBuffer.GetCell(1, 1).Address, - tempSheetBuffer.GetCell(4, 4).Address)); + var tempSheetBuffer = new TempSheetBuffer(wb); + wb.DefinedNames.Add("Temp range", tempSheetBuffer.GetRange( + tempSheetBuffer.GetCell(1, 1).Address, + tempSheetBuffer.GetCell(4, 4).Address)); - wb.DefinedNames.Count().Should().Be(1, "global named range is supposed to be added"); - tempSheetBuffer.Dispose(); - wb.DefinedNames.Count().Should().Be(0, "named range should be deleted with the temp buffer"); - } + wb.DefinedNames.Count().Should().Be(1, "global named range is supposed to be added"); + tempSheetBuffer.Dispose(); + wb.DefinedNames.Count().Should().Be(0, "named range should be deleted with the temp buffer"); } [Fact] public void CanRenderRangeForEmptySet() { // If bound range has no items and the option row is empty, remove the whole area, including the option row. - using (var wb = new XLWorkbook()) - { - var ws = wb.AddWorksheet("Sheet1"); - ws.Range("A2:B3").AddToNamed("List"); - ws.Cell("B2").Value = "{{item}}"; - ws.Cell("B4").Value = "Cell below"; + using var wb = new XLWorkbook(); + var ws = wb.AddWorksheet("Sheet1"); + ws.Range("A2:B3").AddToNamed("List"); + ws.Cell("B2").Value = "{{item}}"; + ws.Cell("B4").Value = "Cell below"; - var template = new XLTemplate(wb); - template.AddVariable("List", new List()); - template.Generate(); + var template = new XLTemplate(wb); + template.AddVariable("List", new List()); + template.Generate(); - ws.Cell("B2").GetString().Should().Be("Cell below"); - ws.Cell("B3").GetString().Should().Be(""); - } + ws.Cell("B2").GetString().Should().Be("Cell below"); + ws.Cell("B3").GetString().Should().Be(""); } [Fact] public void InnerRange() { - using (var wb = new XLWorkbook()) - { - // Arrange. - const string rangeName = "List"; - const string innerRangeName = "CustomTotals"; - const string totalsName = "Totals"; - var list = new List { "Value1", "Value2" }; - var ws = wb.AddWorksheet("Sheet1"); - ws.Cell("B1").Value = "Header"; - ws.Range("A2:C3").AddToNamed(rangeName); - ws.Cell("B2").Value = "{{index+1}}"; - ws.Cell("C2").Value = "{{item}}"; - ws.Cell("B3").Value = totalsName; - ws.Range("C3:C3").AddToNamed(innerRangeName); + using var wb = new XLWorkbook(); + // Arrange. + const string rangeName = "List"; + const string innerRangeName = "CustomTotals"; + const string totalsName = "Totals"; + var list = new List { "Value1", "Value2" }; + var ws = wb.AddWorksheet("Sheet1"); + ws.Cell("B1").Value = "Header"; + ws.Range("A2:C3").AddToNamed(rangeName); + ws.Cell("B2").Value = "{{index+1}}"; + ws.Cell("C2").Value = "{{item}}"; + ws.Cell("B3").Value = totalsName; + ws.Range("C3:C3").AddToNamed(innerRangeName); - // Act. - var template = new XLTemplate(wb); - template.AddVariable(rangeName, list); - template.AddVariable(innerRangeName, list.Count); - template.Generate(); + // Act. + var template = new XLTemplate(wb); + template.AddVariable(rangeName, list); + template.AddVariable(innerRangeName, list.Count); + template.Generate(); - // Assert. - ws.Cell("B4").GetString().Should().Be(totalsName); - ws.Range(rangeName).RowCount().Should().Be(3); - ws.Range(rangeName).ColumnCount().Should().Be(3); - } + // Assert. + ws.Cell("B4").GetString().Should().Be(totalsName); + ws.Range(rangeName).RowCount().Should().Be(3); + ws.Range(rangeName).ColumnCount().Should().Be(3); } } } diff --git a/tests/ClosedXML.Report.Tests/TestModels/User.cs b/tests/ClosedXML.Report.Tests/TestModels/User.cs index 0822a03..ab13efb 100644 --- a/tests/ClosedXML.Report.Tests/TestModels/User.cs +++ b/tests/ClosedXML.Report.Tests/TestModels/User.cs @@ -3,7 +3,6 @@ using System.Linq; using Bogus; using Bogus.DataSets; -using Bogus.Extensions; namespace ClosedXML.Report.Tests.TestModels { diff --git a/tests/ClosedXML.Report.Tests/Utils/PackageHelper.cs b/tests/ClosedXML.Report.Tests/Utils/PackageHelper.cs index 38afb18..58a3740 100644 --- a/tests/ClosedXML.Report.Tests/Utils/PackageHelper.cs +++ b/tests/ClosedXML.Report.Tests/Utils/PackageHelper.cs @@ -270,7 +270,6 @@ public static bool TryReadPart(Package package, Uri uri, Action deserial /// /// /// - /// /// /// public static bool Compare(Package left, Package right, bool compareToFirstDifference, bool stripColumnWidths, out string message) diff --git a/tests/ClosedXML.Report.Tests/Utils/ResourceFileExtractor.cs b/tests/ClosedXML.Report.Tests/Utils/ResourceFileExtractor.cs index 0e8af92..1dc3572 100644 --- a/tests/ClosedXML.Report.Tests/Utils/ResourceFileExtractor.cs +++ b/tests/ClosedXML.Report.Tests/Utils/ResourceFileExtractor.cs @@ -13,8 +13,7 @@ public sealed class ResourceFileExtractor { #region Static #region Private fields - private static readonly Dictionary ms_defaultExtractors = - new Dictionary(); + private static readonly Dictionary DefaultExtractors = new(); #endregion #region Public properties /// Instance of resource extractor for executing assembly @@ -22,34 +21,31 @@ public static ResourceFileExtractor Instance { get { - ResourceFileExtractor _return; - Assembly _assembly = Assembly.GetCallingAssembly(); - string _key = _assembly.GetName().FullName; - if (!ms_defaultExtractors.TryGetValue(_key, out _return)) + Assembly assembly = Assembly.GetCallingAssembly(); + string key = assembly.GetName().FullName; + if (!DefaultExtractors.TryGetValue(key, out var resourceFileExtractor)) { - lock (ms_defaultExtractors) + lock (DefaultExtractors) { - if (!ms_defaultExtractors.TryGetValue(_key, out _return)) + if (!DefaultExtractors.TryGetValue(key, out resourceFileExtractor)) { - _return = new ResourceFileExtractor(_assembly, true, null); - ms_defaultExtractors.Add(_key, _return); + resourceFileExtractor = new ResourceFileExtractor(assembly, true, null); + DefaultExtractors.Add(key, resourceFileExtractor); } } } - return _return; + return resourceFileExtractor; } } #endregion - #region Public methods - #endregion #endregion #region Private fields - private readonly Assembly m_assembly; - private readonly ResourceFileExtractor m_baseExtractor; - private readonly string m_assemblyName; + private readonly Assembly _assembly; + private readonly ResourceFileExtractor _baseExtractor; + private readonly string _assemblyName; - private bool m_isStatic; - private string m_resourceFilePath; + private bool _isStatic; + private string _resourceFilePath; #endregion #region Constructors /// @@ -60,7 +56,7 @@ public static ResourceFileExtractor Instance public ResourceFileExtractor(string resourceFilePath, ResourceFileExtractor baseExtractor) : this(Assembly.GetCallingAssembly(), baseExtractor) { - m_resourceFilePath = resourceFilePath; + _resourceFilePath = resourceFilePath; } /// /// Create instance @@ -86,7 +82,7 @@ public ResourceFileExtractor(string resourcePath) public ResourceFileExtractor(Assembly assembly, string resourcePath) : this(assembly ?? Assembly.GetCallingAssembly()) { - m_resourceFilePath = resourcePath; + _resourceFilePath = resourcePath; } /// /// Instance constructor @@ -127,11 +123,11 @@ private ResourceFileExtractor(Assembly assembly, bool isStatic, ResourceFileExtr throw new ArgumentNullException("assembly"); } #endregion - m_assembly = assembly; - m_baseExtractor = baseExtractor; - m_assemblyName = Assembly.GetName().Name; + _assembly = assembly; + _baseExtractor = baseExtractor; + _assemblyName = Assembly.GetName().Name; IsStatic = isStatic; - m_resourceFilePath = ".Resources."; + _resourceFilePath = ".Resources."; } #endregion #region Public properties @@ -139,13 +135,13 @@ private ResourceFileExtractor(Assembly assembly, bool isStatic, ResourceFileExtr public Assembly Assembly { [DebuggerStepThrough] - get { return m_assembly; } + get { return _assembly; } } /// Work assembly name public string AssemblyName { [DebuggerStepThrough] - get { return m_assemblyName; } + get { return _assemblyName; } } /// /// Path to read resource files. Example: .Resources.Upgrades. @@ -153,25 +149,25 @@ public string AssemblyName public string ResourceFilePath { [DebuggerStepThrough] - get { return m_resourceFilePath; } + get { return _resourceFilePath; } [DebuggerStepThrough] - set { m_resourceFilePath = value; } + set { _resourceFilePath = value; } } public bool IsStatic { [DebuggerStepThrough] - get { return m_isStatic; } + get { return _isStatic; } [DebuggerStepThrough] - set { m_isStatic = value; } + set { _isStatic = value; } } public IEnumerable GetFileNames() { - string _path = AssemblyName + m_resourceFilePath; - foreach (string _resourceName in Assembly.GetManifestResourceNames()) + string path = AssemblyName + _resourceFilePath; + foreach (string resourceName in Assembly.GetManifestResourceNames()) { - if (_resourceName.StartsWith(_path)) + if (resourceName.StartsWith(path)) { - yield return _resourceName.Replace(_path, string.Empty); + yield return resourceName.Replace(path, string.Empty); } } } @@ -179,18 +175,18 @@ public IEnumerable GetFileNames() #region Public methods public string ReadFileFromRes(string fileName) { - Stream _stream = ReadFileFromResToStream(fileName); - string _result; - StreamReader sr = new StreamReader(_stream); + Stream stream = ReadFileFromResToStream(fileName); + string result; + StreamReader sr = new StreamReader(stream); try { - _result = sr.ReadToEnd(); + result = sr.ReadToEnd(); } finally { sr.Close(); } - return _result; + return result; } public string ReadFileFromResFormat(string fileName, params object[] formatArgs) @@ -206,8 +202,8 @@ public string ReadFileFromResFormat(string fileName, params object[] formatArgs) /// public string ReadSpecificFileFromRes(string specificPath, string fileName) { - ResourceFileExtractor _ext = new ResourceFileExtractor(Assembly, specificPath); - return _ext.ReadFileFromRes(fileName); + ResourceFileExtractor ext = new ResourceFileExtractor(Assembly, specificPath); + return ext.ReadFileFromRes(fileName); } /// /// Read file in current assembly by specific file name @@ -217,21 +213,21 @@ public string ReadSpecificFileFromRes(string specificPath, string fileName) /// ApplicationException. public Stream ReadFileFromResToStream(string fileName) { - string _nameResFile = AssemblyName + m_resourceFilePath + fileName; - Stream _stream = Assembly.GetManifestResourceStream(_nameResFile); + string nameResFile = AssemblyName + _resourceFilePath + fileName; + Stream stream = Assembly.GetManifestResourceStream(nameResFile); #region Not found - if (ReferenceEquals(_stream, null)) + if (ReferenceEquals(stream, null)) { #region Get from base extractor - if (!ReferenceEquals(m_baseExtractor, null)) + if (!ReferenceEquals(_baseExtractor, null)) { - return m_baseExtractor.ReadFileFromResToStream(fileName); + return _baseExtractor.ReadFileFromResToStream(fileName); } #endregion - throw new ApplicationException("Can't find resource file " + _nameResFile); + throw new ApplicationException("Can't find resource file " + nameResFile); } #endregion - return _stream; + return stream; } #endregion } diff --git a/tests/ClosedXML.Report.Tests/Utils/StreamHelper.cs b/tests/ClosedXML.Report.Tests/Utils/StreamHelper.cs index 64be192..f9766fc 100644 --- a/tests/ClosedXML.Report.Tests/Utils/StreamHelper.cs +++ b/tests/ClosedXML.Report.Tests/Utils/StreamHelper.cs @@ -176,17 +176,17 @@ private static void LogDiff(string stringOne, string stringOther) } } - private static Regex columnRegex = new Regex("", RegexOptions.Compiled); - private static Regex widthRegex = new Regex("width=\"\\d+(\\.\\d+)?\"\\s+", RegexOptions.Compiled); + private static readonly Regex ColumnRegex = new("", RegexOptions.Compiled); + private static readonly Regex WidthRegex = new("width=\"\\d+(\\.\\d+)?\"\\s+", RegexOptions.Compiled); private static String RemoveColumnWidths(String s) { var replacements = new Dictionary(); - foreach (var m in columnRegex.Matches(s).OfType()) + foreach (var m in ColumnRegex.Matches(s).OfType()) { var original = m.Groups[0].Value; - var replacement = widthRegex.Replace(original, ""); + var replacement = WidthRegex.Replace(original, ""); replacements.Add(original, replacement); } @@ -197,11 +197,11 @@ private static String RemoveColumnWidths(String s) return s; } - private static Regex guidRegex = new Regex(@"{[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}}", RegexOptions.Compiled | RegexOptions.Multiline); + private static readonly Regex GuidRegex = new(@"{[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}}", RegexOptions.Compiled | RegexOptions.Multiline); - private static String RemoveGuids(String s) + private static string RemoveGuids(string s) { - return guidRegex.Replace(s, delegate (Match m) + return GuidRegex.Replace(s, delegate { return string.Empty; }); diff --git a/tests/ClosedXML.Report.Tests/XlExtensionsTests.cs b/tests/ClosedXML.Report.Tests/XlExtensionsTests.cs index 97e8590..8ab1e4c 100644 --- a/tests/ClosedXML.Report.Tests/XlExtensionsTests.cs +++ b/tests/ClosedXML.Report.Tests/XlExtensionsTests.cs @@ -1,7 +1,6 @@ using System.IO; using ClosedXML.Excel; using ClosedXML.Report.Excel; -using ClosedXML.Report.Utils; using FluentAssertions; using Xunit; using Xunit.Abstractions; diff --git a/tests/ClosedXML.Report.Tests/XlTemplateTests.cs b/tests/ClosedXML.Report.Tests/XlTemplateTests.cs index 26eb3c8..3841890 100644 --- a/tests/ClosedXML.Report.Tests/XlTemplateTests.cs +++ b/tests/ClosedXML.Report.Tests/XlTemplateTests.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq; using Bogus; -using ClosedXML.Report.Excel; using Xunit; using Xunit.Abstractions; diff --git a/tests/ClosedXML.Report.Tests/XlsxTemplateTestsBase.cs b/tests/ClosedXML.Report.Tests/XlsxTemplateTestsBase.cs index 04660b5..ad7884f 100644 --- a/tests/ClosedXML.Report.Tests/XlsxTemplateTestsBase.cs +++ b/tests/ClosedXML.Report.Tests/XlsxTemplateTestsBase.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading; using ClosedXML.Excel; -using ClosedXML.Report.Excel; using FluentAssertions; using Xunit.Abstractions;