using System;
using System.Collections.Generic;
using Amazon.EC2;
using Amazon.EC2.Model;
using Amazon.EC2.Model.Internal.MarshallTransformations;
using Amazon.Runtime.Internal.Transform;
using AWSSDK_DotNet35.UnitTests.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AWSSDK_DotNet35.UnitTests.EC2
{
[TestClass]
public class UnmarshallTests
{
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeImages()
{
const string payloadResponse = @"
c8ed10b1-5ad2-40b0-b44e-da4c4183c026
-
ami-1a2b3c4d
amazon/getting-started
available
111122223333
true
i386
machine
aki-1a2b3c4d
ari-1a2b3c4d
amazon
getting-started
Image Description
ebs
/dev/sda
-
/dev/sda1
snap-1a2b3c4d
15
false
standard
-
/dev/sdb
snap-4a3b2c1d
30
true
gp2
paravirtual
xen
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeImagesResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeImagesResponse;
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Images.Count);
var image = result.Images[0];
Assert.AreEqual("ami-1a2b3c4d", image.ImageId);
Assert.AreEqual("amazon/getting-started", image.ImageLocation);
Assert.AreEqual(ImageState.Available, image.State);
Assert.AreEqual(2, image.BlockDeviceMappings.Count);
Assert.AreEqual("/dev/sda1", image.BlockDeviceMappings[0].DeviceName);
Assert.AreEqual("snap-1a2b3c4d", image.BlockDeviceMappings[0].Ebs.SnapshotId);
Assert.AreEqual(15, image.BlockDeviceMappings[0].Ebs.VolumeSize);
Assert.AreEqual(VolumeType.Standard, image.BlockDeviceMappings[0].Ebs.VolumeType);
Assert.IsFalse(image.BlockDeviceMappings[0].Ebs.DeleteOnTermination);
Assert.AreEqual(VolumeType.Gp2, image.BlockDeviceMappings[1].Ebs.VolumeType);
Assert.IsTrue(image.BlockDeviceMappings[1].Ebs.DeleteOnTermination);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeSpotInstances()
{
const string payloadResponse = @"
59dbff89-35bd-4eac-99ed-be587EXAMPLE
-
sir-e1471206
0.09
one-time
active
PENDING_EVALUATION
2012-13-09 08:31:26 +0000 : Your Spot request has been submitted for review, and is pending evaluation.
ami-1a2b3c4d
MyKey
-
default
m1.small
-
/dev/sda1
true
standard
-
/dev/sdb
false
io1
10
-
/dev/sdc
snap-1a2b3c4d
12
true
standard
false
i-1a2b3c4d
2010-09-13T23:50:44.000Z
Linux/UNIX
us-east-1c
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeSpotInstanceRequestsResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeSpotInstanceRequestsResponse;
Assert.IsNotNull(result);
Assert.IsNotNull(result.SpotInstanceRequests);
Assert.AreEqual(1, result.SpotInstanceRequests.Count);
var spotInstanceRequest = result.SpotInstanceRequests[0];
var blockDeviceMapping = spotInstanceRequest.LaunchSpecification.BlockDeviceMappings;
Assert.AreEqual(3, blockDeviceMapping.Count);
Assert.AreEqual(VolumeType.Standard, blockDeviceMapping[0].Ebs.VolumeType);
Assert.AreEqual(VolumeType.Io1, blockDeviceMapping[1].Ebs.VolumeType);
Assert.AreEqual(10, blockDeviceMapping[1].Ebs.Iops);
Assert.AreEqual(VolumeType.Standard, blockDeviceMapping[2].Ebs.VolumeType);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeVolumes()
{
const string payloadResponse = @"
59dbff89-35bd-4eac-99ed-be587EXAMPLE
-
vol-1a2b3c4d
80
us-east-1a
in-use
2014-03-01T12:03:00.00Z
-
vol-1a2b3c4d
i-1a2b3c4d
/dev/sdh
attached
2014-03-01T12:03:00.00Z
false
standard
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeVolumesResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeVolumesResponse;
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Volumes.Count);
var vol = result.Volumes[0];
Assert.AreEqual("vol-1a2b3c4d", vol.VolumeId);
Assert.AreEqual(80, vol.Size);
Assert.IsTrue(string.IsNullOrEmpty(vol.SnapshotId));
Assert.AreEqual(VolumeType.Standard, vol.VolumeType);
Assert.AreEqual(VolumeState.InUse, vol.State);
Assert.AreEqual(1, vol.Attachments.Count);
Assert.AreEqual("vol-1a2b3c4d", vol.Attachments[0].VolumeId);
Assert.AreEqual("i-1a2b3c4d", vol.Attachments[0].InstanceId);
Assert.IsFalse(vol.Attachments[0].DeleteOnTermination);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestRegisterImage()
{
const string payloadResponse = @"
3b4de853-288e-4c0a-802a-4a7471ba2620
ami-4af95e23
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = RegisterImageResponseUnmarshaller.Instance.Unmarshall(context) as RegisterImageResponse;
Assert.IsNotNull(result);
Assert.IsNotNull(result.ImageId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestRunInstances()
{
const string payloadResponse = @"
9a6bfb4a-1c38-408c-a6f9-b0f1a36db758
r-6e46e03a
251839141158
-
i-ba7af9ee
ami-beb0caec
0
pending
0
m1.large
2012-06-04T23:12:12.000Z
ap-southeast-1b
default
aki-aa225af8
disabled
subnet-a61dafcf
vpc-c31dafaa
10.0.2.106
true
-
sg-188d9f74
default
pending
pending
x86_64
ebs
/dev/sda1
paravirtual
xen
-
eni-ffc37f96
subnet-a61dafcf
vpc-c31dafaa
251839141158
in-use
10.0.2.106
true
-
sg-188d9f74
default
eni-attach-d1d917b8
0
attaching
2012-06-04T23:12:12.000Z
true
-
10.0.2.106
true
-
10.0.2.107
false
-
10.0.2.108
false
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = RunInstancesResponseUnmarshaller.Instance.Unmarshall(context)
as RunInstancesResponse;
Assert.AreEqual("r-6e46e03a", result.Reservation.ReservationId);
Assert.AreEqual(0, result.Reservation.Groups.Count);
Assert.AreEqual(1, result.Reservation.Instances.Count);
var instance = result.Reservation.Instances[0];
Assert.AreEqual("i-ba7af9ee", instance.InstanceId);
Assert.AreEqual("ami-beb0caec", instance.ImageId);
Assert.AreEqual(0, instance.State.Code);
Assert.AreEqual(InstanceStateName.Pending, instance.State.Name);
Assert.AreEqual("ap-southeast-1b", instance.Placement.AvailabilityZone);
Assert.AreEqual(Tenancy.Default, instance.Placement.Tenancy);
Assert.IsTrue(string.IsNullOrEmpty(instance.Placement.GroupName));
Assert.AreEqual(MonitoringState.Disabled, instance.Monitoring.State);
Assert.IsTrue(instance.SourceDestCheck);
Assert.AreEqual(1, instance.SecurityGroups.Count);
Assert.AreEqual("sg-188d9f74", instance.SecurityGroups[0].GroupId);
Assert.AreEqual("default", instance.SecurityGroups[0].GroupName);
Assert.AreEqual("pending", instance.StateReason.Code);
Assert.AreEqual("pending", instance.StateReason.Message);
Assert.AreEqual(1, instance.NetworkInterfaces.Count);
var netInt = instance.NetworkInterfaces[0];
Assert.AreEqual("eni-ffc37f96", netInt.NetworkInterfaceId);
Assert.AreEqual("10.0.2.106", netInt.PrivateIpAddress);
Assert.IsTrue(netInt.SourceDestCheck);
Assert.AreEqual(1, netInt.Groups.Count);
Assert.AreEqual("sg-188d9f74", netInt.Groups[0].GroupId);
Assert.AreEqual("default", netInt.Groups[0].GroupName);
Assert.AreEqual("eni-attach-d1d917b8", netInt.Attachment.AttachmentId);
Assert.IsTrue(netInt.Attachment.DeleteOnTermination);
Assert.AreEqual(3, instance.NetworkInterfaces[0].PrivateIpAddresses.Count);
Assert.AreEqual("10.0.2.106", netInt.PrivateIpAddresses[0].PrivateIpAddress);
Assert.IsTrue(netInt.PrivateIpAddresses[0].Primary);
Assert.AreEqual("10.0.2.108", netInt.PrivateIpAddresses[2].PrivateIpAddress);
Assert.IsFalse(netInt.PrivateIpAddresses[2].Primary);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeImageAttribute()
{
const string payloadResponse = @"
54dc1c70-e0ca-486d-acf1-f1dfb9b72280
ami-ac1471c5
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeImageAttributeResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeImageAttributeResponse;
Assert.IsNotNull(result);
Assert.IsNotNull(result.ResponseMetadata);
Assert.IsNotNull(result.ResponseMetadata.RequestId);
Assert.IsNotNull(result.ImageAttribute);
Assert.IsNotNull(result.ImageAttribute.ImageId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestAssignPrivateIpAddresses()
{
const string payloadResponse = @"
88d011c7-3265-4535-804f-76422b891c56
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = AssignPrivateIpAddressesResponseUnmarshaller.Instance.Unmarshall(context)
as AssignPrivateIpAddressesResponse;
Assert.IsNotNull(result.ResponseMetadata.RequestId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestUnassignPrivateIpAddresses()
{
const string payloadResponse = @"
88d011c7-3265-4535-804f-76422b891c56
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = UnassignPrivateIpAddressesResponseUnmarshaller.Instance.Unmarshall(context)
as UnassignPrivateIpAddressesResponse;
Assert.IsNotNull(result.ResponseMetadata.RequestId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestCreateNetworkInterface()
{
const string payloadResponse = @"
a9565f4c-f928-4113-859b-905886d11658
eni-1a2b3c4d
subnet-1a2b3c4d
vpc-1a2b3c4d
ap-southeast-1b
123456789123
false
attaching
02:74:b0:78:bf:ab
10.0.2.130
true
-
sg-1a2b3c4d
default
-
10.0.2.130
true
-
10.0.2.133
false
-
10.0.2.132
false
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = CreateNetworkInterfaceResponseUnmarshaller.Instance.Unmarshall(context)
as CreateNetworkInterfaceResponse;
Assert.AreEqual(NetworkInterfaceStatus.Attaching, result.NetworkInterface.Status);
Assert.AreEqual("02:74:b0:78:bf:ab", result.NetworkInterface.MacAddress);
Assert.IsTrue(result.NetworkInterface.SourceDestCheck);
Assert.AreEqual(1, result.NetworkInterface.Groups.Count);
Assert.AreEqual("sg-1a2b3c4d", result.NetworkInterface.Groups[0].GroupId);
Assert.AreEqual("default", result.NetworkInterface.Groups[0].GroupName);
Assert.AreEqual(0, result.NetworkInterface.TagSet.Count);
Assert.AreEqual(3, result.NetworkInterface.PrivateIpAddresses.Count);
Assert.AreEqual("10.0.2.130", result.NetworkInterface.PrivateIpAddresses[0].PrivateIpAddress);
Assert.IsTrue(result.NetworkInterface.PrivateIpAddresses[0].Primary);
Assert.AreEqual("10.0.2.132", result.NetworkInterface.PrivateIpAddresses[2].PrivateIpAddress);
Assert.IsFalse(result.NetworkInterface.PrivateIpAddresses[2].Primary);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeVolumeAttribute()
{
const string payloadResponse = @"
1
123456
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeVolumeAttributeResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeVolumeAttributeResponse;
Assert.AreEqual("1", result.ResponseMetadata.RequestId);
Assert.AreEqual("123456", result.VolumeId);
Assert.IsTrue(result.AutoEnableIO);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestModifyVolumeAttribute()
{
const string payloadResponse = @"
1
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = ModifyVolumeAttributeResponseUnmarshaller.Instance.Unmarshall(context)
as ModifyVolumeAttributeResponse;
Assert.AreEqual("1", result.ResponseMetadata.RequestId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestEnableVolumeIO()
{
const string payloadResponse = @"
1
true
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = EnableVolumeIOResponseUnmarshaller.Instance.Unmarshall(context)
as EnableVolumeIOResponse;
Assert.AreEqual("1", result.ResponseMetadata.RequestId);
}
[TestMethod]
[TestCategory("UnitTest")]
[TestCategory("EC2")]
public void TestDescribeVolumeStatus()
{
const string payloadResponse = @"
5jkdf074-37ed-4004-8671-a78ee82bf1cbEXAMPLE
-
vol-11111111
us-east-1d
ok
-
io-enabled
passed
-
vol-22222222
us-east-1d
impaired
-
io-enabled
failed
-
evol-61a54008
potential-data-inconsistency
THIS IS AN EXAMPLE
2011-12-01T14:00:00.000Z
2011-12-01T15:00:00.000Z
-
enable-volume-io
evol-61a54008
potential-data-inconsistency
THIS IS AN EXAMPLE
";
UnmarshallerContext context = new EC2UnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, new WebResponseData());
var result = DescribeVolumeStatusResponseUnmarshaller.Instance.Unmarshall(context)
as DescribeVolumeStatusResponse;
Assert.AreEqual(2, result.VolumeStatuses.Count);
var vol1 = result.VolumeStatuses[0];
Assert.AreEqual("vol-11111111", vol1.VolumeId);
Assert.AreEqual(VolumeStatusInfoStatus.Ok, vol1.VolumeStatus.Status);
Assert.AreEqual(1, vol1.VolumeStatus.Details.Count);
Assert.AreEqual(VolumeStatusName.IoEnabled, vol1.VolumeStatus.Details[0].Name);
Assert.AreEqual("passed", vol1.VolumeStatus.Details[0].Status);
var vol2 = result.VolumeStatuses[1];
Assert.AreEqual(1, vol2.Events.Count);
Assert.AreEqual("evol-61a54008", vol2.Events[0].EventId);
Assert.AreEqual("potential-data-inconsistency", vol2.Events[0].EventType);
Assert.AreEqual(1, vol2.Actions.Count);
Assert.AreEqual("enable-volume-io", vol2.Actions[0].Code);
Assert.AreEqual("THIS IS AN EXAMPLE", vol2.Actions[0].Description);
}
}
}