Unit tests for .Net Core (Xunit)

This commit is contained in:
xinchen 2016-05-27 13:42:51 -07:00
Родитель db822c41d3
Коммит 6826b52d85
12 изменённых файлов: 153 добавлений и 29 удалений

10
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1,10 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Denote all files that are truly binary and should not be modified.
*.exe binary
*.dll binary
*.pdb binary
*.ico binary
*.png binary
*.jpg binary

Просмотреть файл

@ -31,6 +31,7 @@
"../Microsoft.Azure.Amqp/Exceptions/*.cs",
"../Microsoft.Azure.Amqp/Extensions/*.cs",
"../Microsoft.Azure.Amqp/Interop/*.cs",
"../Microsoft.Azure.Amqp/Properties/InternalVisible.cs",
"../Microsoft.Azure.Amqp/Tracing/*.cs"
]
},

Просмотреть файл

@ -14,7 +14,7 @@ namespace Microsoft.Azure.Amqp.Transport
static readonly AsyncCallback onOpenComplete = OnOpenComplete;
static readonly AsyncCallback onWriteComplete = OnWriteComplete;
static readonly AsyncCallback onReadComplete = OnReadComplete;
const SslProtocols DefaultSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls | SslProtocols.Ssl3;
const SslProtocols DefaultSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
readonly TransportBase innerTransport;
readonly CustomSslStream sslStream;
TlsTransportSettings tlsSettings;

Просмотреть файл

@ -208,6 +208,7 @@
<Compile Include="IteratorAsyncResult.cs" />
<Compile Include="PartialTrustHelpers.cs" />
<Compile Include="PlatformSupport.cs" />
<Compile Include="Properties\InternalVisible.cs" />
<Compile Include="ResourcesGeneric.Designer.cs">
<DependentUpon>ResourcesGeneric.resx</DependentUpon>
<AutoGen>True</AutoGen>

Просмотреть файл

@ -23,5 +23,3 @@ using System.Runtime.InteropServices;
// Version information for an assembly follows semantic versioning 1.0.0 (because
// NuGet didn't support semver 2.0.0 before VS 2015). See semver.org for details.
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: InternalsVisibleTo("Test.Microsoft.Azure.Amqp")]

Просмотреть файл

@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Test.Microsoft.Azure.Amqp")]
[assembly: InternalsVisibleTo("Test.Microsoft.Azure.Amqp.Core")]

3
global.json Normal file
Просмотреть файл

@ -0,0 +1,3 @@
{
"projects": [ ".", "./test" ]
}

Просмотреть файл

@ -173,7 +173,7 @@
initiator.ConnectAsync(TimeSpan.FromSeconds(120), args);
complete.WaitOne();
complete.Close();
complete.Dispose();
if (args.Exception != null)
{
@ -207,7 +207,7 @@
sb.AppendFormat("{0:X2}", item.Array[i + item.Offset]);
}
System.Diagnostics.Trace.WriteLine(sb.ToString());
System.Diagnostics.Debug.WriteLine(sb.ToString());
}
}
@ -220,8 +220,8 @@
}
catch (Exception exception)
{
System.Diagnostics.Trace.WriteLine(string.Format("Exception occurred at offset {0}", buffer.Offset));
System.Diagnostics.Trace.WriteLine(exception.ToString());
System.Diagnostics.Debug.WriteLine(string.Format("Exception occurred at offset {0}", buffer.Offset));
System.Diagnostics.Debug.WriteLine(exception.ToString());
}
}
@ -246,8 +246,11 @@
false);
}
#if DOTNET
store.Dispose();
#else
store.Close();
#endif
if (collection.Count > 0)
{
return collection[0];
@ -420,7 +423,7 @@
sb.Append(value);
System.Diagnostics.Trace.WriteLine(sb.ToString());
System.Diagnostics.Debug.WriteLine(sb.ToString());
}
public static async Task<AmqpMessage> ReceiveMessageAsync(this ReceivingAmqpLink link, TimeSpan timeout)

Просмотреть файл

@ -12,6 +12,8 @@
[KnownType(typeof(Teacher))]
class Person
{
public Person() { }
public Person(string name)
{
this.Name = name;
@ -60,7 +62,7 @@
[AmqpContract(Name = "student", Code = 1)]
class Student : Person
{
Student() : base(null) { }
public Student() : base(null) { }
public Student(string name)
: base(name)
@ -77,6 +79,8 @@
[AmqpContract(Name = "teacher", Code = 2)]
class Teacher : Person
{
public Teacher() { }
public Teacher(string name)
: base(name)
{
@ -123,6 +127,8 @@
this.uuid = uuid;
}
public EmployeeId() { }
public int EncodeSize
{
get { return FixedWidth.UuidEncoded; }

Просмотреть файл

@ -12,9 +12,13 @@
using global::Microsoft.Azure.Amqp.Sasl;
using global::Microsoft.Azure.Amqp.Serialization;
using global::Microsoft.Azure.Amqp.Transaction;
#if !DOTNET
using global::Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
#if !DOTNET
[TestClass]
#endif
public class AmqpCodecTests
{
bool boolTrue = true;
@ -124,13 +128,11 @@
bin32ValueBin[4] = 0x00;
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecSingleValueTest()
{
byte[] workBuffer = new byte[2048];
@ -305,7 +307,11 @@
Assert.IsTrue(str32Utf8 == strValue, "UTF8 string32 string value is not equal.");
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecListTest()
{
byte[] workBuffer = new byte[4096];
@ -406,7 +412,11 @@
EnsureEqual((IList)described.Value, (IList)described4.Value);
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecList0Test()
{
byte[] list0Bin = new byte[] { 0x45 };
@ -421,7 +431,11 @@
Assert.IsTrue(list0v.Count == 0, "The list should contain 0 items.");
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecMapTest()
{
byte[] workBuffer = new byte[4096];
@ -508,7 +522,11 @@
Assert.IsTrue(described.Value.Equals(described1.Value), "Described value 1 value is different");
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecMultipleTest()
{
byte[] workBuffer = new byte[2048];
@ -535,7 +553,11 @@
Assert.IsTrue(Multiple<AmqpSymbol>.Intersect(threeValues, threeDecoded).Count == 3, "multiple of three symbol values failed");
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecFramingTypeTest()
{
byte[] workBuffer = new byte[1024 * 16];
@ -615,7 +637,11 @@
Assert.IsTrue(buffer.Length == 0, "All bytes in the buffer should be consumed");
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecDescribedArrayTest()
{
int size = AmqpCodec.GetObjectEncodeSize(described5);
@ -625,14 +651,18 @@
Assert.IsTrue(decoded.Descriptor.Equals(described5.Descriptor), "Descriptor value not equal");
string[] original = (string[])described5.Value;
string[] array = (string[])decoded.Value;
Assert.IsTrue(original.Length == array.Length, "length not equal {0} != {1}", original.Length, array.Length);
Assert.IsTrue(original.Length == array.Length, string.Format("length not equal {0} != {1}", original.Length, array.Length));
for (int i = 0; i < original.Length; ++i)
{
Assert.IsTrue(original[i] == array[i], "index {0}: {1} != {2}", i, original[i], array[i]);
Assert.IsTrue(original[i] == array[i], string.Format("index {0}: {1} != {2}", i, original[i], array[i]));
}
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpCodecArrayTest()
{
ArrayTest<bool>(
@ -729,7 +759,11 @@
(n1, n2) => { });
}
[TestMethod()]
#if DOTNET
[Xunit.Fact]
#else
[TestMethod]
#endif
public void AmqpSerializerListEncodingTest()
{
Action<Person, Person> personValidator = (p1, p2) =>
@ -785,7 +819,7 @@
// Inter-op: it should be an AMQP described list as other clients see it
stream.Seek(0, SeekOrigin.Begin);
DescribedType dl1 = DescribedEncoding.Decode(new ByteBuffer(stream.GetBuffer(), 0, (int)stream.Length));
DescribedType dl1 = DescribedEncoding.Decode(new ByteBuffer(stream.ToArray(), 0, (int)stream.Length));
Assert.AreEqual(dl1.Descriptor, 1ul);
List<object> lv = dl1.Value as List<object>;
Assert.IsNotNull(lv);
@ -841,6 +875,7 @@
Assert.AreEqual(teacher.Classes[205], ((Teacher)p6).Classes[205]);
}
#if !DOTNET
[TestMethod]
public void AmqpExceptionSerializeTest()
{
@ -859,6 +894,7 @@
Assert.AreEqual(amqpException1.Error.Description, amqpException2.Error.Description, "Error.Description differs!");
}
}
#endif
static void EncodeDescribedList(ByteBuffer buffer, object descriptor, params object[] values)
{
@ -871,7 +907,7 @@
static void ArrayTest<T>(T[] array, Action<T, T> validate)
{
Trace.WriteLine(string.Format("Array testing for type {0}", typeof(T).ToString()));
Debug.WriteLine(string.Format("Array testing for type {0}", typeof(T).ToString()));
byte[] workBuffer = new byte[4096];
ByteBuffer buffer = null;
AmqpCodec.EncodeArray(array, buffer = new ByteBuffer(workBuffer));

Просмотреть файл

@ -0,0 +1,30 @@
namespace Test.Microsoft.Azure.Amqp
{
static class Assert
{
public static void IsTrue(bool b, string m = null)
{
Xunit.Assert.True(b, m);
}
public static void IsFalse(bool b, string m = null)
{
Xunit.Assert.False(b, m);
}
public static void IsNull(object o, string m = null)
{
Xunit.Assert.True(o == null, m);
}
public static void IsNotNull(object o, string m = null)
{
Xunit.Assert.True(o != null, m);
}
public static void AreEqual(object a, object b, string m = null)
{
Xunit.Assert.Equal(a, b);
}
}
}

Просмотреть файл

@ -0,0 +1,32 @@
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"Microsoft.Azure.Amqp.Core": "1.1.0-*",
"System.Diagnostics.Debug": "4.0.11-rc2-24027",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025"
},
"buildOptions": {
"compile": [
"Assert.cs",
"../Test.Microsoft.Amqp/Common/*.cs",
"../Test.Microsoft.Amqp/TestCases/AmqpCodecTests.cs"
],
"define": [ "TRACE", "DOTNET" ]
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}