You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
eglib
external
Lucene.Net.Light
Newtonsoft.Json
aspnetwebstack
binary-reference-assemblies
cecil
debian-snapshot
ikdasm
ikvm
referencesource
rx
Ix
Rx
NET
Resources
Samples
Source
.nuget
Microsoft.Reactive.Testing
Playground
References
Rx_Xamarin
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reactive.WindowsRuntime
Tests.System.Reactive
Dummies
Properties
Stress
Tests
Concurrency
AsyncLockTest.cs
ConcurrencyTest.cs
ControlSchedulerTest.cs
CurrentThreadSchedulerTest.cs
DefaultSchedulerTest.cs
DispatcherSchedulerTest.cs
EventLoopSchedulerTest.cs
HistoricalSchedulerTest.cs
ImmediateSchedulerTest.cs
NewThreadSchedulerTest.cs
ScheduledItemTest.cs
SchedulerTest.cs
StopwatchTest.cs
SynchronizationContextSchedulerTest.cs
SynchronizationTest.cs
TaskPoolSchedulerTest.cs
ThreadPoolSchedulerTest.cs
VirtualSchedulerTest.cs
Disposables
Linq
Aliases.cs
AnonymousTest.cs
ConnectableObservable.cs
ConnectableObservableTest.cs
DefaultConcurrencyAbstractionLayerTest.cs
EventPatternSourceBaseTest.cs
ListObservableTest.cs
MySubject.cs
NotificationTest.cs
ObserverTest.cs
PrivateTypesTest.cs
RegressionTest.cs
RogueEnumerable.cs
SystemClockTest.cs
TaskObservableExtensionsTest.cs
TimeTests.cs
UnitTest.cs
App.cs
DispatcherHelpers.cs
Extensions.cs
MockDisposable.cs
MockEnumerable.cs
NullErrorObservable.cs
Semaphore.cs
TestBase.cs
TestLongRunningScheduler.cs
TestTaskScheduler.cs
Tests.System.Reactive.csproj
Utils.cs
packages
.gitattributes
.gitignore
35MSSharedLib1024.snk
Build.bat
BuildAll.proj
BuildSetup.bat
Clean.bat
Common.targets
Import.targets
Local.testsettings
README.txt
Rx.ruleset
Rx.sln.REMOVED.git-id
Test.ruleset
TraceAndTestImpact.testsettings
license.txt
packages.config
Test
tools
component
xpkg
.gitignore
README-microsoft-original.md
README.md
Rakefile
mono.patch
replacer.sh
ikvm-native
libgc
m4
man
mcs
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
ChangeLog.REMOVED.git-id
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
140 lines
3.5 KiB
C#
140 lines
3.5 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
|
|
|
#if !SILVERLIGHT // MethodAccessException
|
|
using System;
|
|
using System.Reactive.Concurrency;
|
|
using System.Reflection;
|
|
#if NUNIT
|
|
using NUnit.Framework;
|
|
using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
|
|
using TestMethodAttribute = NUnit.Framework.TestAttribute;
|
|
using TestInitializeAttribute = NUnit.Framework.SetUpAttribute;
|
|
#else
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
#endif
|
|
|
|
namespace ReactiveTests.Tests
|
|
{
|
|
[TestClass]
|
|
public class AsyncLockTest
|
|
{
|
|
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
|
|
public void Wait_ArgumentChecking()
|
|
{
|
|
var asyncLock = new AsyncLock();
|
|
asyncLock.Wait(null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Wait_Graceful()
|
|
{
|
|
var ok = false;
|
|
new AsyncLock().Wait(() => { ok = true; });
|
|
Assert.IsTrue(ok);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Wait_Fail()
|
|
{
|
|
var l = new AsyncLock();
|
|
|
|
var ex = new Exception();
|
|
try
|
|
{
|
|
l.Wait(() => { throw ex; });
|
|
Assert.Fail();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Assert.AreSame(ex, e);
|
|
}
|
|
|
|
// has faulted; should not run
|
|
l.Wait(() => { Assert.Fail(); });
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Wait_QueuesWork()
|
|
{
|
|
var l = new AsyncLock();
|
|
|
|
var l1 = false;
|
|
var l2 = false;
|
|
l.Wait(() => { l.Wait(() => { Assert.IsTrue(l1); l2 = true; }); l1 = true; });
|
|
Assert.IsTrue(l2);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Dispose()
|
|
{
|
|
var l = new AsyncLock();
|
|
|
|
var l1 = false;
|
|
var l2 = false;
|
|
var l3 = false;
|
|
var l4 = false;
|
|
|
|
l.Wait(() =>
|
|
{
|
|
l.Wait(() =>
|
|
{
|
|
l.Wait(() =>
|
|
{
|
|
l3 = true;
|
|
});
|
|
|
|
l2 = true;
|
|
|
|
l.Dispose();
|
|
|
|
l.Wait(() =>
|
|
{
|
|
l4 = true;
|
|
});
|
|
});
|
|
|
|
l1 = true;
|
|
});
|
|
|
|
Assert.IsTrue(l1);
|
|
Assert.IsTrue(l2);
|
|
Assert.IsFalse(l3);
|
|
Assert.IsFalse(l4);
|
|
}
|
|
|
|
public class AsyncLock
|
|
{
|
|
object instance;
|
|
|
|
public AsyncLock()
|
|
{
|
|
instance = typeof(Scheduler).Assembly.GetType("System.Reactive.Concurrency.AsyncLock").GetConstructor(new Type[] { }).Invoke(new object[] { });
|
|
}
|
|
|
|
public void Wait(Action action)
|
|
{
|
|
try
|
|
{
|
|
instance.GetType().GetMethod("Wait").Invoke(instance, new object[] { action });
|
|
}
|
|
catch (TargetInvocationException ex)
|
|
{
|
|
throw ex.InnerException;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
instance.GetType().GetMethod("Dispose").Invoke(instance, new object[0]);
|
|
}
|
|
catch (TargetInvocationException ex)
|
|
{
|
|
throw ex.InnerException;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif |