Skip to content

Commit 1ec0a60

Browse files
committed
Put back code removed with 75c1cf9 conflicts resolution
1 parent c8b3f6e commit 1ec0a60

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed
Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
JustMock Lite
3-
Copyright © 2010-2015 Progress Software Corporation
3+
Copyright © 2010-2015,2019 Progress Software Corporation
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -36,52 +36,64 @@ public MSpecContextResolver()
3636

3737
public override MocksRepository ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
3838
{
39-
var testMethod = this.GetTestMethod();
40-
if (testMethod != null)
41-
return repositories[testMethod.DeclaringType];
42-
if (unresolvedContextBehavior == UnresolvedContextBehavior.DoNotCreateNew)
43-
return null;
44-
45-
var stackTrace = new StackTrace();
46-
var frames = stackTrace.EnumerateFrames().ToList();
47-
var caller = frames.FirstOrDefault(method => method.Module.Assembly != typeof(MocksRepository).Assembly);
48-
var mspecTestClass = caller.DeclaringType;
49-
50-
MocksRepository parentRepo;
51-
repositories.TryGetValue(mspecTestClass.BaseType, out parentRepo);
52-
53-
var repo = new MocksRepository(parentRepo, caller);
54-
repositories.Add(mspecTestClass, repo);
55-
56-
return repo;
39+
lock (this.repositorySync)
40+
{
41+
var testMethod = this.GetTestMethod();
42+
if (testMethod != null)
43+
{
44+
return repositories[testMethod.DeclaringType];
45+
}
46+
47+
if (unresolvedContextBehavior == UnresolvedContextBehavior.DoNotCreateNew)
48+
{
49+
return null;
50+
}
51+
52+
var stackTrace = new StackTrace();
53+
var frames = stackTrace.EnumerateFrames().ToList();
54+
var caller = frames.FirstOrDefault(method => method.Module.Assembly != typeof(MocksRepository).Assembly);
55+
var mspecTestClass = caller.DeclaringType;
56+
57+
MocksRepository parentRepo;
58+
repositories.TryGetValue(mspecTestClass.BaseType, out parentRepo);
59+
60+
var repo = new MocksRepository(parentRepo, caller);
61+
repositories.Add(mspecTestClass, repo);
62+
63+
return repo;
64+
}
5765
}
5866

5967
public override bool RetireRepository()
6068
{
61-
var stackTrace = new StackTrace();
62-
var testMethod = FindExistingTestMethod(stackTrace.EnumerateFrames());
63-
64-
if (testMethod == null)
65-
return false;
66-
67-
var key = testMethod.DeclaringType;
68-
var repo = repositories[key];
69-
repositories.Remove(key);
70-
repo.Retire();
71-
72-
return true;
69+
lock (this.repositorySync)
70+
{
71+
var stackTrace = new StackTrace();
72+
var testMethod = FindExistingTestMethod(stackTrace.EnumerateFrames());
73+
if (testMethod == null)
74+
{
75+
return false;
76+
}
77+
78+
var key = testMethod.DeclaringType;
79+
var repo = repositories[key];
80+
repositories.Remove(key);
81+
repo.Retire();
82+
83+
return true;
84+
}
7385
}
7486

75-
public override MethodBase GetTestMethod()
76-
{
77-
var stackTrace = new StackTrace();
78-
var frames = stackTrace.EnumerateFrames().ToList();
79-
var testMethod = this.FindExistingTestMethod(frames);
87+
public override MethodBase GetTestMethod()
88+
{
89+
var stackTrace = new StackTrace();
90+
var frames = stackTrace.EnumerateFrames().ToList();
91+
var testMethod = this.FindExistingTestMethod(frames);
8092

81-
return testMethod;
82-
}
93+
return testMethod;
94+
}
8395

84-
public static bool IsAvailable
96+
public static bool IsAvailable
8597
{
8698
get { return FindType(MSpecAssertionFailedName, false) != null; }
8799
}
@@ -94,5 +106,5 @@ private MethodBase FindExistingTestMethod(IEnumerable<MethodBase> frames)
94106

95107
return q.FirstOrDefault();
96108
}
97-
}
109+
}
98110
}

0 commit comments

Comments
 (0)