Skip to content

Commit cd92b97

Browse files
committed
Add dotMemoryUnit demo project
1 parent 0f1c6e5 commit cd92b97

File tree

7 files changed

+263
-0
lines changed

7 files changed

+263
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ local.properties
2929
.buildpath
3030

3131

32+
#################
33+
## Rider
34+
#################
35+
.idea/
36+
37+
3238
#################
3339
## Visual Studio
3440
#################
@@ -40,6 +46,7 @@ local.properties
4046
*.suo
4147
*.user
4248
*.sln.docstates
49+
.vs/
4350

4451
# Build results
4552

DotMemoryUnit/TestsWithDMU.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2003
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsWithDMU", "TestsWithDMU\TestsWithDMU.csproj", "{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {937DF61C-FA75-4DC3-8D80-85C93B74F669}
24+
EndGlobalSection
25+
EndGlobal

DotMemoryUnit/TestsWithDMU/Clock.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Timers;
3+
4+
namespace ExampleTestsWithDMU
5+
{
6+
class Clock
7+
: IDisposable
8+
{
9+
public void OnTick(object state, ElapsedEventArgs args)
10+
{
11+
Console.WriteLine(DateTime.UtcNow);
12+
}
13+
14+
public void Dispose()
15+
{
16+
}
17+
}
18+
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Threading;
3+
using JetBrains.dotMemoryUnit;
4+
using Xunit;
5+
using Xunit.Abstractions;
6+
using Timer = System.Timers.Timer;
7+
8+
namespace ExampleTestsWithDMU
9+
{
10+
public class ClockFacts
11+
{
12+
public ClockFacts(ITestOutputHelper outputHelper)
13+
{
14+
DotMemoryUnitTestOutput.SetOutputMethod(
15+
message => outputHelper.WriteLine(message));
16+
}
17+
18+
[Fact]
19+
public void ClockDisposesCorrectly()
20+
{
21+
var isolator = new Action(() =>
22+
{
23+
// Arrange
24+
Timer timer;
25+
using (Clock clock = new Clock())
26+
{
27+
// Act
28+
timer = new Timer(1000);
29+
timer.Elapsed += clock.OnTick;
30+
timer.Start();
31+
32+
Thread.Sleep(5 * 1000); // Run clock for 5 seconds
33+
}
34+
});
35+
36+
isolator();
37+
38+
// Run explicit GC
39+
GC.Collect();
40+
41+
// Assert
42+
dotMemory.Check(memory =>
43+
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Clock>()).ObjectsCount));
44+
}
45+
46+
[Fact]
47+
public void ClockDisposesCorrectlyFixed()
48+
{
49+
var isolator = new Action(() =>
50+
{
51+
// Arrange
52+
using (Clock clock = new Clock())
53+
using (Timer timer = new Timer(1000))
54+
{
55+
// Act
56+
timer.Elapsed += clock.OnTick;
57+
timer.Start();
58+
59+
Thread.Sleep(5 * 1000); // Run clock for 5 seconds
60+
61+
timer.Stop();
62+
timer.Elapsed -= clock.OnTick;
63+
}
64+
});
65+
66+
isolator();
67+
68+
// Run explicit GC
69+
GC.Collect();
70+
71+
// Assert
72+
dotMemory.Check(memory =>
73+
{
74+
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Clock>()).ObjectsCount);
75+
});
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ExampleTestsWithDMU")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ExampleTestsWithDMU")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c831e3fc-acc5-49e8-b4e5-a712247fe4c6")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="..\packages\xunit.runner.console.2.4.0\build\xunit.runner.console.props" Condition="Exists('..\packages\xunit.runner.console.2.4.0\build\xunit.runner.console.props')" />
5+
<Import Project="..\packages\xunit.core.2.4.0\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.0\build\xunit.core.props')" />
6+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectGuid>{C831E3FC-ACC5-49E8-B4E5-A712247FE4C6}</ProjectGuid>
11+
<OutputType>Library</OutputType>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<RootNamespace>TestsWithDMU</RootNamespace>
14+
<AssemblyName>TestsWithDMU</AssemblyName>
15+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
16+
<FileAlignment>512</FileAlignment>
17+
<Deterministic>true</Deterministic>
18+
<NuGetPackageImportStamp>
19+
</NuGetPackageImportStamp>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<DebugType>pdbonly</DebugType>
32+
<Optimize>true</Optimize>
33+
<OutputPath>bin\Release\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="dotMemory.Unit, Version=111.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
40+
<HintPath>..\packages\JetBrains.dotMemoryUnit.3.0.20171219.105559\lib\net35\dotMemory.Unit.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.Core" />
44+
<Reference Include="System.Xml.Linq" />
45+
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="Microsoft.CSharp" />
47+
<Reference Include="System.Data" />
48+
<Reference Include="System.Net.Http" />
49+
<Reference Include="System.Xml" />
50+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
51+
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
52+
<Private>True</Private>
53+
</Reference>
54+
<Reference Include="xunit.assert, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
55+
<HintPath>..\packages\xunit.assert.2.4.0\lib\netstandard2.0\xunit.assert.dll</HintPath>
56+
</Reference>
57+
<Reference Include="xunit.core, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
58+
<HintPath>..\packages\xunit.extensibility.core.2.4.0\lib\net452\xunit.core.dll</HintPath>
59+
</Reference>
60+
<Reference Include="xunit.execution.desktop, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
61+
<HintPath>..\packages\xunit.extensibility.execution.2.4.0\lib\net452\xunit.execution.desktop.dll</HintPath>
62+
</Reference>
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Compile Include="Clock.cs" />
66+
<Compile Include="ClockFacts.cs" />
67+
<Compile Include="Properties\AssemblyInfo.cs" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<None Include="packages.config" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
77+
<PropertyGroup>
78+
<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>
79+
</PropertyGroup>
80+
<Error Condition="!Exists('..\packages\xunit.core.2.4.0\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.0\build\xunit.core.props'))" />
81+
<Error Condition="!Exists('..\packages\xunit.core.2.4.0\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.0\build\xunit.core.targets'))" />
82+
<Error Condition="!Exists('..\packages\xunit.runner.console.2.4.0\build\xunit.runner.console.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.console.2.4.0\build\xunit.runner.console.props'))" />
83+
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props'))" />
84+
</Target>
85+
<Import Project="..\packages\xunit.core.2.4.0\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.0\build\xunit.core.targets')" />
86+
</Project>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="JetBrains.dotMemoryUnit" version="3.0.20171219.105559" targetFramework="net461" />
4+
<package id="xunit" version="2.4.0" targetFramework="net461" />
5+
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
6+
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
7+
<package id="xunit.assert" version="2.4.0" targetFramework="net461" />
8+
<package id="xunit.core" version="2.4.0" targetFramework="net461" />
9+
<package id="xunit.extensibility.core" version="2.4.0" targetFramework="net461" />
10+
<package id="xunit.extensibility.execution" version="2.4.0" targetFramework="net461" />
11+
<package id="xunit.runner.console" version="2.4.0" targetFramework="net461" developmentDependency="true" />
12+
<package id="xunit.runner.visualstudio" version="2.4.0" targetFramework="net461" developmentDependency="true" />
13+
</packages>

0 commit comments

Comments
 (0)