Skip to content

Commit

Permalink
Start System.Printing test project (#10167)
Browse files Browse the repository at this point in the history
Add test project for System.Printing along with a few starter tests.
  • Loading branch information
JeremyKuhne authored Dec 16, 2024
1 parent de08d6f commit 4204efe
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Microsoft.Dotnet.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Windows.Primitives-r
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PresentationFramework.Fluent.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationFramework.Fluent.Tests\PresentationFramework.Fluent.Tests.csproj", "{56833D74-2D0B-5516-C1D6-B93D4FFF7612}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Printing.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Printing.Tests\System.Printing.Tests.csproj", "{762F6671-44CA-672D-B9C5-CFB69999F152}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -1653,6 +1655,18 @@ Global
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x64.Build.0 = Release|x64
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x86.ActiveCfg = Release|x86
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x86.Build.0 = Release|x86
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|arm64.ActiveCfg = Debug|arm64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|arm64.Build.0 = Debug|arm64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x64.ActiveCfg = Debug|x64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x64.Build.0 = Debug|x64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x86.ActiveCfg = Debug|x86
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x86.Build.0 = Debug|x86
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|arm64.ActiveCfg = Release|arm64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|arm64.Build.0 = Release|arm64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x64.ActiveCfg = Release|x64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x64.Build.0 = Release|x64
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x86.ActiveCfg = Release|x86
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1780,6 +1794,7 @@ Global
{5306FA93-178C-4535-ADEE-86B1DE1B68CB} = {2EE4A2DA-70B3-4767-9D18-618DA0FE3105}
{0EFFC7C4-B486-4852-8CED-EDEB46E02C42} = {D0AED517-9972-41CB-8751-983E4EB8F511}
{56833D74-2D0B-5516-C1D6-B93D4FFF7612} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
{762F6671-44CA-672D-B9C5-CFB69999F152} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4340004-DAC0-497D-B69D-CFA7CD93F567}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


#include "win32inc.hpp"

Expand All @@ -10,6 +8,7 @@ using namespace System::Runtime::CompilerServices;

//change to use PublicKey
[assembly:InternalsVisibleTo("ReachFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")];
[assembly:InternalsVisibleTo("System.Printing.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")];


// When objects that do not derive from System.Exception are thrown,
Expand Down
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
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>
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();
}
}

0 comments on commit 4204efe

Please sign in to comment.