Compare commits
7 Commits
d6a78c42c7
...
58f5c5ba4a
Author | SHA1 | Date | |
---|---|---|---|
|
58f5c5ba4a | ||
|
de73af8b7d | ||
|
d4ef078b9d | ||
|
fbb36fb00d | ||
|
06b397cebf | ||
|
1d64c8839d | ||
|
71a0745c70 |
@ -133,9 +133,9 @@ public class ExcelWriter : IWriter, IDisposable
|
|||||||
if (row != null)
|
if (row != null)
|
||||||
{
|
{
|
||||||
Range nameCell = worksheetCells[row, _nameCell.Column];
|
Range nameCell = worksheetCells[row, _nameCell.Column];
|
||||||
if (!Regex.IsMatch(nameCell.Value2, @"(арт. \d{11})"))
|
if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}"))
|
||||||
{
|
{
|
||||||
nameCell.AddValue($"-> замена (арт. {positionAmount.Key.ProductSku})");
|
nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (int column in columns)
|
foreach (int column in columns)
|
||||||
@ -155,9 +155,9 @@ public class ExcelWriter : IWriter, IDisposable
|
|||||||
if (row != null)
|
if (row != null)
|
||||||
{
|
{
|
||||||
Range nameCell = worksheetCells[row, _nameCell.Column];
|
Range nameCell = worksheetCells[row, _nameCell.Column];
|
||||||
if (!Regex.IsMatch(nameCell.Value2, @"(арт. \d{11})"))
|
if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}"))
|
||||||
{
|
{
|
||||||
nameCell.AddValue($" -> замена (арт. {positionAmount.Key.ProductSku})");
|
nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (int column in columns)
|
foreach (int column in columns)
|
||||||
@ -198,7 +198,7 @@ public class ExcelWriter : IWriter, IDisposable
|
|||||||
current.ClearContents();
|
current.ClearContents();
|
||||||
|
|
||||||
worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty;
|
worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty;
|
||||||
worksheetCells[row, nameColumn].Value2 = $"{product.Name} -> не найден (арт. {product.ProductSku})";
|
worksheetCells[row, nameColumn].Value2 = $"{product.Name} (не найден арт. {product.ProductSku})";
|
||||||
worksheetCells[row, skuColumn].Value2 = "???";
|
worksheetCells[row, skuColumn].Value2 = "???";
|
||||||
if (_oldSkuCell != null)
|
if (_oldSkuCell != null)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ public class CanReadProducts : IDisposable
|
|||||||
Assert.Equal(3, products.Count());
|
Assert.Equal(3, products.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"TestWorkbooks\TestSpecification.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecification.xlsx")]
|
||||||
public void CanReadWorkbook()
|
public void CanReadWorkbook()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Worksheets[1];
|
Worksheet worksheet = Util.Workbook.Worksheets[1];
|
||||||
|
@ -17,7 +17,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
_reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IReader>();
|
_reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IReader>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"TestWorkbooks\TestSpecification.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecification.xlsx")]
|
||||||
public void CanWriteSingle()
|
public void CanWriteSingle()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
@ -34,6 +34,76 @@ public class CanWriteProducts : IDisposable
|
|||||||
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
|
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationMultipleProductLines.xlsx")]
|
||||||
|
public void CanWriteMultipleProductLines()
|
||||||
|
{
|
||||||
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
||||||
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
|
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_writer.WriteProducts(products);
|
||||||
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
|
Assert.Equal("TestSpecificationMultipleProductLines", products.First().Item1);
|
||||||
|
Assert.Equal("TargetSpecificationMultipleProductLines", targetProducts.First().Item1);
|
||||||
|
Assert.Equal(2, targetProducts.First().Item2.Count());
|
||||||
|
Assert.True(Enumerable.SequenceEqual(products.First().Item2, targetProducts.First().Item2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationNotFound.xlsx")]
|
||||||
|
public void CanWriteNotFound()
|
||||||
|
{
|
||||||
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx"));
|
||||||
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
|
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_writer.WriteProducts(products);
|
||||||
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
|
||||||
|
Assert.Equal("???", targetSheet.Range["B4"].Value2);
|
||||||
|
Assert.Contains("Молот Тора", targetSheet.Range["C4"].Value2);
|
||||||
|
Assert.Contains("15555551555", targetSheet.Range["C4"].Value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationReplaced.xlsx")]
|
||||||
|
public void CanWriteReplaced()
|
||||||
|
{
|
||||||
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx"));
|
||||||
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
|
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_writer.WriteProducts(products);
|
||||||
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
|
Assert.Equal("TestSpecificationReplaced", products.First().Item1);
|
||||||
|
Assert.Equal("TargetSpecificationReplaced", targetProducts.First().Item1);
|
||||||
|
Assert.Single(targetProducts.First().Item2);
|
||||||
|
var product = targetProducts.First().Item2.First().Key;
|
||||||
|
Assert.Contains("Молот Тора", product.Name);
|
||||||
|
Assert.Contains("15555551555", product.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationNewVariant.xlsx")]
|
||||||
|
public void CanWriteNewVariant()
|
||||||
|
{
|
||||||
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx"));
|
||||||
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
|
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_writer.WriteProducts(products);
|
||||||
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
|
Assert.Equal("TestSpecificationNewVariant", products.First().Item1);
|
||||||
|
Assert.Equal("TargetSpecificationNewVariant", targetProducts.First().Item1);
|
||||||
|
Assert.Single(targetProducts.First().Item2);
|
||||||
|
var product = targetProducts.First().Item2.First().Key;
|
||||||
|
Assert.Contains("Молот Тора", product.Name);
|
||||||
|
Assert.Contains("15555551555", product.Name);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_addIn.AutoClose();
|
_addIn.AutoClose();
|
||||||
|
@ -17,19 +17,4 @@
|
|||||||
<ProjectReference Include="..\RhSolutions.AddIn\RhSolutions.AddIn.csproj" />
|
<ProjectReference Include="..\RhSolutions.AddIn\RhSolutions.AddIn.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="TestWorkbooks\EmptyTestTable.xlsx">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="TestWorkbooks\EmptyWorkbook.xlsx">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="TestWorkbooks\ExcelTableTest.xlsx">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="TestWorkbooks\TestSpecification.xlsx">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
RhSolutions.Tests/TestWorkbooks/TargetSpecificationNotFound.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TargetSpecificationNotFound.xlsx
Normal file
Binary file not shown.
BIN
RhSolutions.Tests/TestWorkbooks/TargetSpecificationReplaced.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TargetSpecificationReplaced.xlsx
Normal file
Binary file not shown.
Binary file not shown.
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationNewVariant.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationNewVariant.xlsx
Normal file
Binary file not shown.
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationNotFound.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationNotFound.xlsx
Normal file
Binary file not shown.
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationReplaced.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationReplaced.xlsx
Normal file
Binary file not shown.
@ -15,14 +15,14 @@ public class WorkbookValidationTests : IDisposable
|
|||||||
Util.Application.Workbooks.Add();
|
Util.Application.Workbooks.Add();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"TestWorkbooks\EmptyTestTable.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyTestTable.xlsx")]
|
||||||
public void WorksheetIsCorrect()
|
public void WorksheetIsCorrect()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Sheets[1];
|
Worksheet worksheet = Util.Workbook.Sheets[1];
|
||||||
Assert.True(worksheet.IsValidSource());
|
Assert.True(worksheet.IsValidSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"TestWorkbooks\EmptyWorkbook.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyWorkbook.xlsx")]
|
||||||
public void EmptyWorkbookIsNotCorrect()
|
public void EmptyWorkbookIsNotCorrect()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Sheets[1];
|
Worksheet worksheet = Util.Workbook.Sheets[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user