MultiThreadingTest.cs 1.52 KB
Newer Older
1
2
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.Exceptions;
3
4
5
6
7
8
9
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Svg.UnitTests
{

10
11
    [TestClass]
    public class MultiThreadingTest : SvgTestHelper
12
13
14
    {
		protected override string TestResource { get { return GetFullResourceString("Issue_Threading.TestFile.svg"); } }
		protected override int ExpectedSize { get { return 100; } }
15
16
17

        private void LoadFile()
        {
18
            LoadSvg(GetXMLDocFromResource());
19
20
21
22
        }

        
        [TestMethod]
23
        public void LoadSVGThreading_SingleThread_YieldsNoError()
24
25
26
        {
            LoadFile();
        }
27
28


29
        [TestMethod]
30
        public void LoadSVGThreading_MultiThread_YieldsNoErrorWhileInBounds()
31
32
33
34
35
36
37
        {
            Parallel.For(0, 10, (x) =>
            {
                LoadFile();
            });
            Trace.WriteLine("Done");
        }
38

39

40
        [TestMethod]
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        public void LoadSVGThreading_MultiThread_GivesMemoryExceptionOnTooManyParallelTest()
        {
			try
			{
				Parallel.For(0, 100, (x) =>
				{
					LoadFile();
				});
			}
			catch (AggregateException ex)
			{
				//We expect an SVG Memory Exception to be thrown, thats okay, otherwise fail
				if (!(ex.InnerException is SvgMemoryException))
				{
					throw ex.InnerException;
				}
			}
			Assert.Inconclusive("This test was expected to throw and SVGMemoryException, however this is higly dependent on the file and machine under test. This is not a fail reason.");
59
60
61
        }
    }
}