This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathTestOperation.cs
67 lines (62 loc) · 2.55 KB
/
TestOperation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Xunit.Abstractions;
using Microsoft.Quantum.Simulation.Core;
namespace Microsoft.Quantum.Simulation.XUnit
{
[Serializable]
public class TestOperation : IXunitSerializable
{
public string assemblyName;
public string className;
public string fullClassName;
public string skipReason;
public string testCaseNamePrefix;
/// <summary>
/// Returns an action that takes a single argument - the simulator to run against.
/// </summary>
public Action<IOperationFactory> TestOperationRunner
{
get
{
return (IOperationFactory sim) =>
{
if (skipReason == null)
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assemblyName);
Type operationType = assembly.GetType(fullClassName);
ICallable<QVoid, QVoid> op = (typeof(IOperationFactory)
.GetMethod("Get", new Type[0])
.MakeGenericMethod(typeof(ICallable<QVoid, QVoid>), operationType)
.Invoke(sim, null)
as ICallable<QVoid, QVoid>);
if (op == null)
{
throw new TestOperationException($"Operation with name: {fullClassName} was not found in assembly {assemblyName}");
}
op.Apply(QVoid.Instance);
}
};
}
}
#region Implementation of IXunitSerializable
public void Deserialize(IXunitSerializationInfo info)
{
assemblyName = info.GetValue<string>("assemblyName");
className = info.GetValue<string>("className");
fullClassName = info.GetValue<string>("fullClassName");
skipReason = info.GetValue<string>("skipReason");
testCaseNamePrefix = info.GetValue<string>("testCaseNamePrefix");
}
public void Serialize(IXunitSerializationInfo info)
{
info.AddValue("assemblyName", assemblyName);
info.AddValue("className", className);
info.AddValue("fullClassName", fullClassName);
info.AddValue("skipReason", skipReason);
info.AddValue("testCaseNamePrefix", testCaseNamePrefix);
}
#endregion
}
}