-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start System.Printing test project (#10167)
Add test project for System.Printing along with a few starter tests.
- Loading branch information
1 parent
de08d6f
commit 4204efe
Showing
5 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Printing.Tests/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
global using Xunit; | ||
#pragma warning disable IDE0005 // Using directive is unnecessary. New project, this will be used. | ||
global using FluentAssertions; | ||
#pragma warning restore IDE0005 |
31 changes: 31 additions & 0 deletions
31
src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Printing.Tests/System.Printing.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Nullable>enable</Nullable> | ||
<Platforms>x64;x86;arm64</Platforms> | ||
<RootNamespace /> | ||
<TargetFramework Condition="!$(TargetFramework.Contains('windows'))">$(TargetFramework)-windows</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<StrongNameKeyId>Open</StrongNameKeyId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" /> | ||
<PackageReference Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" /> | ||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" /> | ||
<PackageReference Include="System.Private.Windows.Core.TestUtilities" Version="$(SystemPrivateWindowsCoreTestUtilitiesVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<MicrosoftPrivateWinFormsReference Include="System.Private.Windows.Core" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(WpfSourceDir)WindowsBase\WindowsBase.csproj" /> | ||
<ProjectReference Include="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" /> | ||
<ProjectReference Include="$(WpfSourceDir)System.Printing\System.Printing.vcxproj" /> | ||
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" /> | ||
<ProjectReference Include="$(WpfSourceDir)ReachFramework\ReachFramework.csproj" /> | ||
<ProjectReference Include="$(WpfSourceDir)System.Windows.Primitives\System.Windows.Primitives.csproj" /> | ||
</ItemGroup> | ||
</Project> |
113 changes: 113 additions & 0 deletions
113
...Tests/System.Printing.Tests/System/Printing/IndexedProperties/PrintStringPropertyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace System.Printing.IndexedProperties; | ||
|
||
public class PrintStringPropertyTests | ||
{ | ||
[Fact] | ||
public void Constructor_Name() | ||
{ | ||
using PrintStringProperty property = new("TestProperty"); | ||
property.Value.Should().BeNull(); | ||
property.Name.Should().Be("TestProperty"); | ||
bool disposed = property.TestAccessor().Dynamic.IsDisposed; | ||
disposed.Should().BeFalse(); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_Name_Value() | ||
{ | ||
using PrintStringProperty property = new("TestProperty", "TestValue"); | ||
property.Value.Should().Be("TestValue"); | ||
property.Name.Should().Be("TestProperty"); | ||
bool disposed = property.TestAccessor().Dynamic.IsDisposed; | ||
disposed.Should().BeFalse(); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_Name_Value_Changed() | ||
{ | ||
List<string?> changes = []; | ||
|
||
using PrintStringProperty property = new( | ||
"TestProperty", | ||
"TestValue", | ||
(PrintSystemDelegates.StringValueChanged)((string? value) => changes.Add(value))); | ||
|
||
property.Value.Should().Be("TestValue"); | ||
property.Name.Should().Be("TestProperty"); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
|
||
changes.Should().BeEquivalentTo(["TestValue"]); | ||
|
||
property.Value = new object(); | ||
changes.Should().BeEquivalentTo(["TestValue"]); | ||
|
||
property.Value = "SecondValue"; | ||
changes.Should().BeEquivalentTo(["TestValue", "SecondValue"]); | ||
|
||
property.Value = null; | ||
changes.Should().BeEquivalentTo(["TestValue", "SecondValue", null]); | ||
} | ||
|
||
[Fact] | ||
public void Dispose() | ||
{ | ||
PrintStringProperty property = new("TestProperty", "TestValue"); | ||
property.Dispose(); | ||
|
||
// Name and Value are set to null | ||
property.Value.Should().BeNull(); | ||
property.Name.Should().BeNull(); | ||
bool disposed = property.TestAccessor().Dynamic.IsDisposed; | ||
disposed.Should().BeTrue(); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Value_Set() | ||
{ | ||
using PrintStringProperty property = new("TestProperty"); | ||
|
||
// Set to a string | ||
property.Value = "TestValue"; | ||
property.Value.Should().Be("TestValue"); | ||
property.Name.Should().Be("TestProperty"); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
|
||
// Set to non-string does nothing | ||
property.Value = new object(); | ||
property.Value.Should().Be("TestValue"); | ||
initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
|
||
// Set to null | ||
property.Value = null; | ||
property.Value.Should().BeNull(); | ||
initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Create_Name() | ||
{ | ||
using var property = PrintStringProperty.Create("TestProperty"); | ||
|
||
property.Value.Should().BeNull(); | ||
property.Name.Should().Be("TestProperty"); | ||
bool disposed = property.TestAccessor().Dynamic.IsDisposed; | ||
disposed.Should().BeFalse(); | ||
bool initialized = property.TestAccessor().Dynamic.IsInitialized; | ||
initialized.Should().BeFalse(); | ||
} | ||
} |