Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using JetBrains.dotMemoryUnit;
- using JetBrains.dotMemoryUnit.Kernel;
- using NUnit.Framework;
- namespace DotMemoryUnitTests
- {
- public class CustomTestCaseAttribute : TestCaseAttribute
- {
- }
- public class DotMemoryUnit1 : IDisposable
- {
- public static IDisposable CollectAllocations { get { return new DotMemoryUnit1(true); } }
- public static IDisposable DoNotCollectAllocations { get { return new DotMemoryUnit1(false); } }
- private DotMemoryUnit1(bool collectAllocations)
- {
- dotMemoryApi.CollectAllocations = collectAllocations;
- DotMemoryUnitController.TestStart();
- }
- public void Dispose()
- {
- DotMemoryUnitController.TestEnd();
- dotMemoryApi.CollectAllocations = false;
- }
- }
- public class DotMemoryUnit2 : IDisposable
- {
- public static IDisposable CollectAllocations { get { return new DotMemoryUnit2(true); } }
- public static IDisposable DoNotCollectAllocations { get { return new DotMemoryUnit2(false); } }
- private DotMemoryUnit2(bool collectAllocations)
- {
- Console.WriteLine("11111");
- dotMemoryApi.CollectAllocations = collectAllocations;
- DotMemoryUnitController.TestStart();
- Console.WriteLine("22222");
- }
- public void Dispose()
- {
- Console.WriteLine("33333");
- DotMemoryUnitController.TestEnd();
- dotMemoryApi.CollectAllocations = false;
- Console.WriteLine("44444");
- }
- }
- public class TestProgram
- {
- [CustomTestCaseAttribute]
- [AssertTraffic(AllocatedSizeInBytes = 100)]
- public void UsingDotMemoryUnit1()
- {
- using (DotMemoryUnit1.CollectAllocations)
- {
- var memoryCheckPoint1 = dotMemory.Check();
- Count();
- var memoryCheckPoint2 = dotMemory.Check();
- }
- }
- [CustomTestCaseAttribute]
- [AssertTraffic(AllocatedSizeInBytes = 100)]
- public void UsingDotMemoryUnit2()
- {
- using (DotMemoryUnit2.CollectAllocations)
- {
- var memoryCheckPoint1 = dotMemory.Check();
- Count();
- var memoryCheckPoint2 = dotMemory.Check();
- }
- }
- private void Count()
- {
- string[] numbers = { "One", "Two", "Three", "Four", "Five"};
- Console.WriteLine("Let's count: " + String.Join(",", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment