Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests into solution #22

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ variables:
buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0
- task: NuGetToolInstaller@1
inputs:
versionSpec: '4.x'
checkLatest: true

- task: NuGetCommand@2
inputs:
Expand Down
177 changes: 177 additions & 0 deletions src/SaneDevelopment.WPF.Controls.Tests/DependencyPropertyUtilTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// -----------------------------------------------------------------------
// <copyright file="DependencyPropertyUtilTests.cs" company="Sane Development">
//
// Sane Development WPF Controls Library Unit Tests.
//
// The BSD 3-Clause License.
//
// Copyright (c) Sane Development.
// All rights reserved.
//
// See LICENSE file for full license information.
//
// </copyright>
// -----------------------------------------------------------------------

namespace SaneDevelopment.WPF.Controls.Tests
{
using System;
using Xunit;

public class DependencyPropertyUtilTests
{
#region IsValidDoubleValue

[Fact]
public void IsValidDoubleValue_WhenNull_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidDoubleValue(null);

Assert.False(res);
}

[Fact]
public void IsValidDoubleValue_WhenNaN_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidDoubleValue(double.NaN);

Assert.False(res);
}

[Fact]
public void IsValidDoubleValue_WhenNegativeInfinity_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidDoubleValue(double.NegativeInfinity);

Assert.False(res);
}

[Fact]
public void IsValidDoubleValue_WhenPositiveInfinity_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidDoubleValue(double.PositiveInfinity);

Assert.False(res);
}

[Theory]
[InlineData(double.MinValue)]
[InlineData(double.MaxValue)]
[InlineData(double.Epsilon)]
[InlineData(0)]
public void IsValidDoubleValue_WhenDouble_ReturnsTrue(double valueToValidate)
{
var res = DependencyPropertyUtil.IsValidDoubleValue(valueToValidate);

Assert.True(res);
}

#endregion IsValidDoubleValue

#region IsValidDateTimeValue

[Fact]
public void IsValidDateTimeValue_WhenNull_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidDateTimeValue(null);

Assert.False(res);
}

[Fact]
public void IsValidDateTimeValue_WhenIsDateTime_ReturnsTrue()
{
var valueToValidate = DateTime.MinValue;

var res = DependencyPropertyUtil.IsValidDateTimeValue(valueToValidate);

Assert.True(res);
}

[Theory]
[InlineData(0d)]
[InlineData(true)]
[InlineData(false)]
[InlineData(0)]
[InlineData("")]
[InlineData('\0')]
public void IsValidDateTimeValue_WhenIsNotDateTime_ReturnsFalse(object valueToValidate)
{
var res = DependencyPropertyUtil.IsValidDateTimeValue(valueToValidate);

Assert.False(res);
}

#endregion IsValidDateTimeValue

#region IsValidBoolValue

[Fact]
public void IsValidBoolValue_WhenNull_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidBoolValue(null);

Assert.False(res);
}

[Fact]
public void IsValidBoolValue_WhenIsBool_ReturnsTrue()
{
var valueToValidate = true;

var res = DependencyPropertyUtil.IsValidBoolValue(valueToValidate);

Assert.True(res);
}

[Theory]
[InlineData(0d)]
[InlineData(0)]
[InlineData("")]
[InlineData('\0')]
public void IsValidBoolValue_WhenIsNotBool_ReturnsFalse(object valueToValidate)
{
var res = DependencyPropertyUtil.IsValidBoolValue(valueToValidate);

Assert.False(res);
}

#endregion IsValidBoolValue

#region IsValidTimeSpanValue

[Fact]
public void IsValidTimeSpanValue_WhenNull_ReturnsFalse()
{
var res = DependencyPropertyUtil.IsValidTimeSpanValue(null);

Assert.False(res);
}

[Fact]
public void IsValidTimeSpanValue_WhenIsTimeSpan_ReturnsTrue()
{
var valueToValidate = TimeSpan.MinValue;

var res = DependencyPropertyUtil.IsValidTimeSpanValue(valueToValidate);

Assert.True(res);
}

[Theory]
[InlineData(0d)]
[InlineData(true)]
[InlineData(false)]
[InlineData(0)]
[InlineData("")]
[InlineData('\0')]
public void IsValidTimeSpanValue_WhenIsNotTimeSpan_ReturnsFalse(object valueToValidate)
{
var res = DependencyPropertyUtil.IsValidTimeSpanValue(valueToValidate);

Assert.False(res);
}

#endregion IsValidTimeSpanValue
}
}
39 changes: 39 additions & 0 deletions src/SaneDevelopment.WPF.Controls.Tests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -----------------------------------------------------------------------
// <copyright file="GlobalSuppressions.cs" company="Sane Development">
//
// Sane Development WPF Controls Library Unit Tests.
//
// The BSD 3-Clause License.
//
// Copyright (c) Sane Development.
// All rights reserved.
//
// See LICENSE file for full license information.
//
// </copyright>
// -----------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
"StyleCop.CSharp.ReadabilityRules",
"SA1124:Do not use regions",
Justification = "We use regions to group several tests united by similar testing subject.")]

[assembly: SuppressMessage(
"StyleCop.CSharp.DocumentationRules",
"SA1600:Elements should be documented",
Justification = "Not need in unit tests project")]
[assembly: SuppressMessage(
"StyleCop.CSharp.SpecialRules",
"SA0001:XML comment analysis is disabled due to project configuration",
Justification = "Not need in unit tests project")]

[assembly: SuppressMessage(
"Naming",
"CA1707:Identifiers should not contain underscores",
Justification = "Not need in unit tests project")]
[assembly: SuppressMessage(
"Design",
"CA1014:Mark assemblies with CLSCompliant",
Justification = "Not need in unit tests project")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>

<IsPackable>false</IsPackable>
<CodeAnalysisRuleSet>..\SaneDevelopment.WPF.Controls.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Remove="stylecop.json" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SaneDevelopment.WPF.Controls\SaneDevelopment.WPF.Controls.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions src/SaneDevelopment.WPF.Controls.Tests/stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "Sane Development",
"copyrightText": "{projectName}.\n\n{licenseName}.\n\nCopyright (c) {companyName}.\nAll rights reserved.\n\nSee {licenseFile} file for full license information.",
"headerDecoration": "-----------------------------------------------------------------------",
"variables": {
"licenseName": "The BSD 3-Clause License",
"licenseFile": "LICENSE",
"projectName": "Sane Development WPF Controls Library Unit Tests"
}
}
}
}
6 changes: 6 additions & 0 deletions src/SaneDevelopment.WPF.Controls.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SaneDevelopment.WPF.Controls.ruleset = SaneDevelopment.WPF.Controls.ruleset
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaneDevelopment.WPF.Controls.Tests", "SaneDevelopment.WPF.Controls.Tests\SaneDevelopment.WPF.Controls.Tests.csproj", "{8EC10F08-9FE3-496D-94A4-9465B371FE88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{FAC6E5E8-3F26-47B9-8936-09528A72FE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAC6E5E8-3F26-47B9-8936-09528A72FE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAC6E5E8-3F26-47B9-8936-09528A72FE81}.Release|Any CPU.Build.0 = Release|Any CPU
{8EC10F08-9FE3-496D-94A4-9465B371FE88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EC10F08-9FE3-496D-94A4-9465B371FE88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EC10F08-9FE3-496D-94A4-9465B371FE88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EC10F08-9FE3-496D-94A4-9465B371FE88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down