Skip to content

Commit 4204efe

Browse files
authored
Start System.Printing test project (#10167)
Add test project for System.Printing along with a few starter tests.
1 parent de08d6f commit 4204efe

File tree

5 files changed

+167
-2
lines changed

5 files changed

+167
-2
lines changed

Microsoft.Dotnet.Wpf.sln

+15
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Windows.Primitives-r
381381
EndProject
382382
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}"
383383
EndProject
384+
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}"
385+
EndProject
384386
Global
385387
GlobalSection(SolutionConfigurationPlatforms) = preSolution
386388
Debug|arm64 = Debug|arm64
@@ -1653,6 +1655,18 @@ Global
16531655
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x64.Build.0 = Release|x64
16541656
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x86.ActiveCfg = Release|x86
16551657
{56833D74-2D0B-5516-C1D6-B93D4FFF7612}.Release|x86.Build.0 = Release|x86
1658+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|arm64.ActiveCfg = Debug|arm64
1659+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|arm64.Build.0 = Debug|arm64
1660+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x64.ActiveCfg = Debug|x64
1661+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x64.Build.0 = Debug|x64
1662+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x86.ActiveCfg = Debug|x86
1663+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Debug|x86.Build.0 = Debug|x86
1664+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|arm64.ActiveCfg = Release|arm64
1665+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|arm64.Build.0 = Release|arm64
1666+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x64.ActiveCfg = Release|x64
1667+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x64.Build.0 = Release|x64
1668+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x86.ActiveCfg = Release|x86
1669+
{762F6671-44CA-672D-B9C5-CFB69999F152}.Release|x86.Build.0 = Release|x86
16561670
EndGlobalSection
16571671
GlobalSection(SolutionProperties) = preSolution
16581672
HideSolutionNode = FALSE
@@ -1780,6 +1794,7 @@ Global
17801794
{5306FA93-178C-4535-ADEE-86B1DE1B68CB} = {2EE4A2DA-70B3-4767-9D18-618DA0FE3105}
17811795
{0EFFC7C4-B486-4852-8CED-EDEB46E02C42} = {D0AED517-9972-41CB-8751-983E4EB8F511}
17821796
{56833D74-2D0B-5516-C1D6-B93D4FFF7612} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
1797+
{762F6671-44CA-672D-B9C5-CFB69999F152} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
17831798
EndGlobalSection
17841799
GlobalSection(ExtensibilityGlobals) = postSolution
17851800
SolutionGuid = {B4340004-DAC0-497D-B69D-CFA7CD93F567}

src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintSystemAssemblyInfo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3-
// See the LICENSE file in the project root for more information.
4-
53

64
#include "win32inc.hpp"
75

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

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

1413

1514
// When objects that do not derive from System.Exception are thrown,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
global using Xunit;
5+
#pragma warning disable IDE0005 // Using directive is unnecessary. New project, this will be used.
6+
global using FluentAssertions;
7+
#pragma warning restore IDE0005
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4+
<Nullable>enable</Nullable>
5+
<Platforms>x64;x86;arm64</Platforms>
6+
<RootNamespace />
7+
<TargetFramework Condition="!$(TargetFramework.Contains('windows'))">$(TargetFramework)-windows</TargetFramework>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9+
<StrongNameKeyId>Open</StrongNameKeyId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
14+
<PackageReference Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" />
15+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
16+
<PackageReference Include="System.Private.Windows.Core.TestUtilities" Version="$(SystemPrivateWindowsCoreTestUtilitiesVersion)" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<MicrosoftPrivateWinFormsReference Include="System.Private.Windows.Core" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="$(WpfSourceDir)WindowsBase\WindowsBase.csproj" />
25+
<ProjectReference Include="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" />
26+
<ProjectReference Include="$(WpfSourceDir)System.Printing\System.Printing.vcxproj" />
27+
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" />
28+
<ProjectReference Include="$(WpfSourceDir)ReachFramework\ReachFramework.csproj" />
29+
<ProjectReference Include="$(WpfSourceDir)System.Windows.Primitives\System.Windows.Primitives.csproj" />
30+
</ItemGroup>
31+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
6+
namespace System.Printing.IndexedProperties;
7+
8+
public class PrintStringPropertyTests
9+
{
10+
[Fact]
11+
public void Constructor_Name()
12+
{
13+
using PrintStringProperty property = new("TestProperty");
14+
property.Value.Should().BeNull();
15+
property.Name.Should().Be("TestProperty");
16+
bool disposed = property.TestAccessor().Dynamic.IsDisposed;
17+
disposed.Should().BeFalse();
18+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
19+
initialized.Should().BeFalse();
20+
}
21+
22+
[Fact]
23+
public void Constructor_Name_Value()
24+
{
25+
using PrintStringProperty property = new("TestProperty", "TestValue");
26+
property.Value.Should().Be("TestValue");
27+
property.Name.Should().Be("TestProperty");
28+
bool disposed = property.TestAccessor().Dynamic.IsDisposed;
29+
disposed.Should().BeFalse();
30+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
31+
initialized.Should().BeFalse();
32+
}
33+
34+
[Fact]
35+
public void Constructor_Name_Value_Changed()
36+
{
37+
List<string?> changes = [];
38+
39+
using PrintStringProperty property = new(
40+
"TestProperty",
41+
"TestValue",
42+
(PrintSystemDelegates.StringValueChanged)((string? value) => changes.Add(value)));
43+
44+
property.Value.Should().Be("TestValue");
45+
property.Name.Should().Be("TestProperty");
46+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
47+
initialized.Should().BeFalse();
48+
49+
changes.Should().BeEquivalentTo(["TestValue"]);
50+
51+
property.Value = new object();
52+
changes.Should().BeEquivalentTo(["TestValue"]);
53+
54+
property.Value = "SecondValue";
55+
changes.Should().BeEquivalentTo(["TestValue", "SecondValue"]);
56+
57+
property.Value = null;
58+
changes.Should().BeEquivalentTo(["TestValue", "SecondValue", null]);
59+
}
60+
61+
[Fact]
62+
public void Dispose()
63+
{
64+
PrintStringProperty property = new("TestProperty", "TestValue");
65+
property.Dispose();
66+
67+
// Name and Value are set to null
68+
property.Value.Should().BeNull();
69+
property.Name.Should().BeNull();
70+
bool disposed = property.TestAccessor().Dynamic.IsDisposed;
71+
disposed.Should().BeTrue();
72+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
73+
initialized.Should().BeFalse();
74+
}
75+
76+
[Fact]
77+
public void Value_Set()
78+
{
79+
using PrintStringProperty property = new("TestProperty");
80+
81+
// Set to a string
82+
property.Value = "TestValue";
83+
property.Value.Should().Be("TestValue");
84+
property.Name.Should().Be("TestProperty");
85+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
86+
initialized.Should().BeFalse();
87+
88+
// Set to non-string does nothing
89+
property.Value = new object();
90+
property.Value.Should().Be("TestValue");
91+
initialized = property.TestAccessor().Dynamic.IsInitialized;
92+
initialized.Should().BeFalse();
93+
94+
// Set to null
95+
property.Value = null;
96+
property.Value.Should().BeNull();
97+
initialized = property.TestAccessor().Dynamic.IsInitialized;
98+
initialized.Should().BeFalse();
99+
}
100+
101+
[Fact]
102+
public void Create_Name()
103+
{
104+
using var property = PrintStringProperty.Create("TestProperty");
105+
106+
property.Value.Should().BeNull();
107+
property.Name.Should().Be("TestProperty");
108+
bool disposed = property.TestAccessor().Dynamic.IsDisposed;
109+
disposed.Should().BeFalse();
110+
bool initialized = property.TestAccessor().Dynamic.IsInitialized;
111+
initialized.Should().BeFalse();
112+
}
113+
}

0 commit comments

Comments
 (0)