Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
ignoring duplicate tests in deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
GoEddie committed Mar 15, 2017
1 parent 5f577f9 commit eda62cf
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 12 deletions.
7 changes: 6 additions & 1 deletion AgileSQLClub.tSQLtTestController/TestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ public class FileScanner
{
private readonly TSqlParser _parser;

public FileScanner()
{
_parser = new TSql130Parser(true);
}

public FileScanner(TSqlParser parser)
{
_parser = parser;
}

public ScanResults ScanCode(string code, ScanResults results, string path)
public virtual ScanResults ScanCode(string code, ScanResults results, string path)
{
var batches = code.Split(new[] {"\r\nGO\r\n", "\nGO\n"}, StringSplitOptions.None);
var offset = 0;
Expand Down
42 changes: 42 additions & 0 deletions Test/UnitTests/TestCacheTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgileSQLClub.tSQLtTestController;
using Moq;
using NUnit.Framework;
using tSQLtTestAdapter;

namespace UnitTests
{
[TestFixture]
public class TestCacheTests
{
[Test]
public void DiscardsDuplicates()
{
var mockScanner = new Mock<FileScanner>();

mockScanner.Setup(p => p.ScanCode(It.IsAny<string>(), It.IsAny<ScanResults>(), It.IsAny<string>())).Returns((
string a, ScanResults result, string b) =>
{
result.FoundClasses.Add(new SqlSchema("Schema", "PathA"));
result.FoundClasses.Add(new SqlSchema("Schema", "PathB"));
result.FoundClasses.Add(new SqlSchema("Schema", "PathB"));

result.FoundPotentialTests.Add(new SqlProcedure(new SqlObjectName() {Object = "test", Schema = "Schema"}, "Patha", 0, 100, 1));
result.FoundPotentialTests.Add(new SqlProcedure(new SqlObjectName() { Object = "test", Schema = "Schema" }, "Pathb", 0, 100, 1));
return result;
});

var mockFileReader = new Mock<IFileReader>();
mockFileReader.Setup(p => p.ReadAll(It.IsAny<string>())).Returns("Blah");
mockFileReader.Setup(p => p.GetLastWriteTimeUtc(It.IsAny<string>())).Returns(DateTime.MaxValue);

var testCache = new TestCache(mockScanner.Object, mockFileReader.Object);
testCache.AddPath("path");
Assert.AreEqual(1, testCache.GetTests().Count);
}
}
}
13 changes: 13 additions & 0 deletions Test/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\..\packages\Castle.Core.4.0.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Data.Tools.Schema.Sql, Version=13.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.SqlServer.DacFx.x64.130.3411.1\lib\net40\Microsoft.Data.Tools.Schema.Sql.dll</HintPath>
<Private>True</Private>
Expand All @@ -54,6 +58,10 @@
<HintPath>..\..\packages\Microsoft.SqlServer.DacFx.x64.130.3411.1\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.7.1.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\packages\Moq.4.7.1\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.2.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\packages\NUnit.3.2.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand All @@ -69,6 +77,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="FileScannerTests.cs" />
<Compile Include="TestCacheTests.cs" />
<Compile Include="tSQLtTestFinderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -80,6 +89,10 @@
<Project>{35E9ACF7-2A97-4160-AB4E-42F4C4EA16CD}</Project>
<Name>AgileSQLClub.tSQLtTestController</Name>
</ProjectReference>
<ProjectReference Include="..\..\XmlTestAdapter\tSQLtTestAdapter.csproj">
<Project>{BC4B3BED-9241-4DD6-8070-A9B66DFC08C1}</Project>
<Name>tSQLtTestAdapter</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 2 additions & 0 deletions Test/UnitTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.0.0" targetFramework="net452" />
<package id="Microsoft.SqlServer.DacFx.x64" version="130.3411.1" targetFramework="net452" />
<package id="Moq" version="4.7.1" targetFramework="net452" />
<package id="NUnit" version="3.2.1" targetFramework="net452" />
</packages>
2 changes: 1 addition & 1 deletion XMLTestAdapterVSIX/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="AgileSQLClub.tSQLtTestAdapter" Version="0.63" Language="en-US" Publisher="EdElliott" />
<Identity Id="AgileSQLClub.tSQLtTestAdapter" Version="0.67" Language="en-US" Publisher="EdElliott" />
<DisplayName>tSQLt Test Adapter</DisplayName>
<Description xml:space="preserve">Unit Test Adapter for tSQLt Tests</Description>
<MoreInfo>https://the.agilsql.club/projects/tSQLt-Test-Adapter</MoreInfo>
Expand Down
10 changes: 10 additions & 0 deletions XmlTestAdapter/IFileReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace tSQLtTestAdapter
{
public interface IFileReader
{
DateTime GetLastWriteTimeUtc(string path);
string ReadAll(string path);
}
}
4 changes: 2 additions & 2 deletions XmlTestAdapter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.2")]
[assembly: AssemblyFileVersion("0.0.0.2")]
[assembly: AssemblyVersion("0.0.0.3")]
[assembly: AssemblyFileVersion("0.0.0.3")]
54 changes: 46 additions & 8 deletions XmlTestAdapter/TestCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@ public class TestCache
private readonly Dictionary<string, DateTime> _dateCache = new Dictionary<string, DateTime>();
private bool _haveChanges = true;
private ScanResults _results = new ScanResults();
private readonly FileScanner _scanner = new FileScanner(new TSql130Parser(false));
private readonly FileScanner _scanner;
private readonly List<TestClass> _tests = new List<TestClass>();
private readonly IFileReader _fileReader;
public TestCache()
{
_scanner = new FileScanner(new TSql130Parser(false));
_fileReader = new FileReader();
}

public TestCache(FileScanner probablyAMock, IFileReader anotherMock)
{
_scanner = probablyAMock;
_fileReader = anotherMock;
}


public void AddPath(string path)
{
var date = File.GetLastWriteTimeUtc(path);
var date = _fileReader.GetLastWriteTimeUtc(path);
if (!_dateCache.ContainsKey(path) || date <= _dateCache[path])
{
_results = _scanner.ScanCode(File.ReadAllText(path), _results, path);
_results = _scanner.ScanCode(_fileReader.ReadAll(path), _results, path);
_haveChanges = true;
}
}
Expand All @@ -32,14 +44,21 @@ public List<TestClass> GetTests()
{
return _tests;
}

var classes = new List<TestClass>();

var foundClasses =
var foundClasses = new List<SqlSchema>();

foreach (var clazz in
_results.FoundClasses.Where(
p =>
_results.FoundPotentialTests.Any(
e => string.Equals(p.Name, e.Name.Schema, StringComparison.OrdinalIgnoreCase)));
e => string.Equals(p.Name, e.Name.Schema, StringComparison.OrdinalIgnoreCase))))
{
if (foundClasses.All(p => p.Name != clazz.Name))
{
foundClasses.Add(clazz);
}

}

var foundTests =
_results.FoundPotentialTests.Where(
Expand All @@ -54,7 +73,7 @@ public List<TestClass> GetTests()
var testClass = new TestClass();
testClass.Name = cls.Name;
testClass.Path = cls.Path;
//testClass.Tests =

foreach (var test in foundTests.Where(p => string.Equals(p.Name.Schema, cls.Name, StringComparison.OrdinalIgnoreCase)))
{
testClass.Tests.Add(new Test {Name = test.Name.Object, Path = test.Path, Line = test.StartLine});
Expand All @@ -70,4 +89,23 @@ public List<TestClass> GetTests()
return _tests;
}
}

public class FileReader : IFileReader
{
public FileReader()
{

}


public virtual string ReadAll(string path)
{
return File.ReadAllText(path);
}

public virtual DateTime GetLastWriteTimeUtc(string path)
{
return File.GetLastWriteTimeUtc(path);
}
}
}
1 change: 1 addition & 0 deletions XmlTestAdapter/tSQLtTestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Helpers\TestFileChangedEventArgs.cs" />
<Compile Include="Helpers\TestFilesUpdateWatcher.cs" />
<Compile Include="Helpers\VsSolutionHelper.cs" />
<Compile Include="IFileReader.cs" />
<Compile Include="TestCache.cs" />
<Compile Include="tSQLtTestContainer.cs" />
<Compile Include="tSQLtTestContainerDiscoverer.cs" />
Expand Down

0 comments on commit eda62cf

Please sign in to comment.