This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NSubstitute" version="4.2.1" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.14.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net461" />
</packages>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DASFactoryDb.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DASFactoryDb.Tests")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d2e1efed-273b-4611-9190-dd1b42b9ef21")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D2E1EFED-273B-4611-9190-DD1B42B9EF21}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DASFactoryDb.Tests</RootNamespace>
<AssemblyName>DASFactoryDb.Tests</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NSubstitute, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.4.2.1\lib\net46\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DbWrapperShould.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DASFactoryDb\DASFactoryDb.csproj">
<Project>{49c60032-9c8a-4ea5-9e26-2f1663555759}</Project>
<Name>DASFactoryDb</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>

View File

@@ -0,0 +1,204 @@
using NSubstitute;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DASFactoryDb.Tests
{
[TestFixture]
class DbWrapperShould
{
DbWrapper sut;
[SetUp]
public void SetUp()
{
//Arrange
sut = DbWrapper.Connection;
}
[TearDown]
public void TearDown()
{
sut.ResetLocalDASFactoryConnection();
}
[Test]
public void UserName_ShouldSetAndGet()
{
//Act
sut.Username = "Name";
var result = sut.Username;
//Assert
Assert.That(result, Is.EqualTo("Name"));
}
[Test]
public void Password_ShouldSetAndGet()
{
//Act
sut.Password = "Pass";
var result = sut.Password;
//Assert
Assert.That(result, Is.EqualTo("Pass"));
}
[Test]
public void DBName_ShouldSetAndGet()
{
//Act
sut.DBName = "DataPro";
var result = sut.DBName;
//Assert
Assert.That(result, Is.EqualTo("DataPro"));
}
[Test]
public void Server_ShouldSetAndGet()
{
//Act
sut.Server = "localdb\\DataProInstance";
var result = sut.Server;
//Assert
Assert.That(result, Is.EqualTo("localdb\\DataProInstance"));
}
[Test]
public void GetLocalDASFactoryConnectionString_NullServer_ShouldThrowException()
{
//Arrange
sut.Server = null;
//Act & Assert
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(
() => sut.GetLocalDASFactoryConnectionString()
, Throws.TypeOf<Exception>()
.With
.Property("Message")
.EqualTo("Empty Server"));
}
[Test]
public void GetLocalDASFactoryConnectionString_DefaultState()
{
//Arrange
sut.Server = "MyServer";
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(result, Is.EqualTo("Server=MyServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValue()
{
//Arrange
sut.Server = "TestServer";
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
// Assert.That(sut.UsingNTLMAuthentication , Is.EqualTo(true));
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValueAndFalseUsingNTLMAuthentication()
{
//Arrange
sut.Server = "TestServer";
DbWrapper._usingNTLMAuthentication = false;
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;User Id=;Password=;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValueAndFalseUsingNTLMAuthentication_SwitchToTrueUsingNTLMAuthentication()
{
//Arrange
sut.Server = "TestServer";
DbWrapper._usingNTLMAuthentication = false;
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;User Id=;Password=;"));
//Arrange
//Important to reset the connection otherwise the class needs to be redesgined to not be singleton
sut.ResetLocalDASFactoryConnection();
//Act
result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Ignore("Not testing DAL")]
[Test]
public void GetDASFactoryCommand_ShouldBeOpened()
{
//Arrange
string connectionString = "Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;";
System.Data.IDbCommand dbCommand = Substitute.For<System.Data.IDbCommand>();
System.Data.IDbConnection dbConnection = Substitute.For<System.Data.IDbConnection>();
dbConnection.ConnectionString = connectionString;
dbConnection.State.Returns(System.Data.ConnectionState.Open);
//Act
System.Data.IDbCommand result = null;
//Uncomment if decided to unit test the Data Access Layer
//result = DbWrapper.GetDASFactoryCommand(dbCommand, dbConnection);
Assert.That(result, Is.Not.Null);
var state = result.Connection.State;
//Assert
Assert.That(result.Connection.State, Is.EqualTo(System.Data.ConnectionState.Open));
Assert.That(result.Connection.ConnectionString, Is.Not.Empty.And.EqualTo(connectionString));
}
[Test]
public void GetDeviceId_ShouldThrowException_WhenNotConnected()
{
//Arrange
DbWrapper.Connected = false;
//Act & Assert
Assert.That(
() => DbWrapper.GetDeviceId("SOMESERIAL")
, Throws.TypeOf<Exception>()
.With
.Property("Message")
.EqualTo("Not connected"));
}
[Test]
public void Connection_ShouldBeSameReference()
{
Assert.That(DbWrapper.Connection, Is.SameAs(DbWrapper.Connection));
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D2E1EFED-273B-4611-9190-DD1B42B9EF21}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DASFactoryDb.Tests</RootNamespace>
<AssemblyName>DASFactoryDb.Tests</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NSubstitute, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.4.2.1\lib\net46\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DbWrapperShould.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DASFactoryDb\DASFactoryDb.csproj">
<Project>{49c60032-9c8a-4ea5-9e26-2f1663555759}</Project>
<Name>DASFactoryDb</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>

View File

@@ -0,0 +1,204 @@
using NSubstitute;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DASFactoryDb.Tests
{
[TestFixture]
class DbWrapperShould
{
DbWrapper sut;
[SetUp]
public void SetUp()
{
//Arrange
sut = DbWrapper.Connection;
}
[TearDown]
public void TearDown()
{
sut.ResetLocalDASFactoryConnection();
}
[Test]
public void UserName_ShouldSetAndGet()
{
//Act
sut.Username = "Name";
var result = sut.Username;
//Assert
Assert.That(result, Is.EqualTo("Name"));
}
[Test]
public void Password_ShouldSetAndGet()
{
//Act
sut.Password = "Pass";
var result = sut.Password;
//Assert
Assert.That(result, Is.EqualTo("Pass"));
}
[Test]
public void DBName_ShouldSetAndGet()
{
//Act
sut.DBName = "DataPro";
var result = sut.DBName;
//Assert
Assert.That(result, Is.EqualTo("DataPro"));
}
[Test]
public void Server_ShouldSetAndGet()
{
//Act
sut.Server = "localdb\\DataProInstance";
var result = sut.Server;
//Assert
Assert.That(result, Is.EqualTo("localdb\\DataProInstance"));
}
[Test]
public void GetLocalDASFactoryConnectionString_NullServer_ShouldThrowException()
{
//Arrange
sut.Server = null;
//Act & Assert
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(
() => sut.GetLocalDASFactoryConnectionString()
, Throws.TypeOf<Exception>()
.With
.Property("Message")
.EqualTo("Empty Server"));
}
[Test]
public void GetLocalDASFactoryConnectionString_DefaultState()
{
//Arrange
sut.Server = "MyServer";
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(result, Is.EqualTo("Server=MyServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValue()
{
//Arrange
sut.Server = "TestServer";
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
// Assert.That(sut.UsingNTLMAuthentication , Is.EqualTo(true));
Assert.That(DbWrapper._usingNTLMAuthentication, Is.EqualTo(true));
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValueAndFalseUsingNTLMAuthentication()
{
//Arrange
sut.Server = "TestServer";
DbWrapper._usingNTLMAuthentication = false;
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;User Id=;Password=;"));
}
[Test]
public void GetLocalDASFactoryConnectionString_ServerHasValueAndFalseUsingNTLMAuthentication_SwitchToTrueUsingNTLMAuthentication()
{
//Arrange
sut.Server = "TestServer";
DbWrapper._usingNTLMAuthentication = false;
//Act
var result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;User Id=;Password=;"));
//Arrange
//Important to reset the connection otherwise the class needs to be redesgined to not be singleton
sut.ResetLocalDASFactoryConnection();
//Act
result = sut.GetLocalDASFactoryConnectionString();
//Assert
Assert.That(result, Is.EqualTo("Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;"));
}
[Ignore("Not testing DAL")]
[Test]
public void GetDASFactoryCommand_ShouldBeOpened()
{
//Arrange
string connectionString = "Server=TestServer;Database=DASFactory;Trusted_Connection=TRUE;";
System.Data.IDbCommand dbCommand = Substitute.For<System.Data.IDbCommand>();
System.Data.IDbConnection dbConnection = Substitute.For<System.Data.IDbConnection>();
dbConnection.ConnectionString = connectionString;
dbConnection.State.Returns(System.Data.ConnectionState.Open);
//Act
System.Data.IDbCommand result = null;
//Uncomment if decided to unit test the Data Access Layer
//result = DbWrapper.GetDASFactoryCommand(dbCommand, dbConnection);
Assert.That(result, Is.Not.Null);
var state = result.Connection.State;
//Assert
Assert.That(result.Connection.State, Is.EqualTo(System.Data.ConnectionState.Open));
Assert.That(result.Connection.ConnectionString, Is.Not.Empty.And.EqualTo(connectionString));
}
[Test]
public void GetDeviceId_ShouldThrowException_WhenNotConnected()
{
//Arrange
DbWrapper.Connected = false;
//Act & Assert
Assert.That(
() => DbWrapper.GetDeviceId("SOMESERIAL")
, Throws.TypeOf<Exception>()
.With
.Property("Message")
.EqualTo("Not connected"));
}
[Test]
public void Connection_ShouldBeSameReference()
{
Assert.That(DbWrapper.Connection, Is.SameAs(DbWrapper.Connection));
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DASFactoryDb.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DASFactoryDb.Tests")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d2e1efed-273b-4611-9190-dd1b42b9ef21")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NSubstitute" version="4.2.1" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.14.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net461" />
</packages>