public void NewAzureBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; var state = BgpPeeringState.Enabled; uint vlanId = 2; var accessType = BgpPeeringAccessType.Private; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var bgpMock = new Mock <IBorderGatewayProtocolPeeringOperations>(); BorderGatewayProtocolPeeringGetResponse expected = new BorderGatewayProtocolPeeringGetResponse { BgpPeering = new AzureBgpPeering() { AzureAutonomousSystemNumber = azureAsn, PeerAutonomousSystemNumber = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VirtualLanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expected); t.Start(); bgpMock.Setup( f => f.NewAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.Is <BorderGatewayProtocolPeeringNewParameters>( z => z.PeerAutonomousSystemNumber == peerAsn && z.PrimaryPeerSubnet == primaryPeerSubnet && z.SecondaryPeerSubnet == secondayPeerSubnet && z.VirtualLanId == vlanId), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringNewParameters param, CancellationToken cancellation) => t); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); NewAzureBGPPeeringCommand cmdlet = new NewAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, PeerAsn = peerAsn, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryPeerSubnet = secondayPeerSubnet, SharedKey = null, VlanId = vlanId, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.AreEqual(expected.BgpPeering.State, actual.State); Assert.AreEqual(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }
public void NewAzureBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; var state = BgpPeeringState.Enabled; uint vlanId = 2; var accessType = BgpPeeringAccessType.Private; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var bgpMock = new Mock<IBorderGatewayProtocolPeeringOperations>(); BorderGatewayProtocolPeeringGetResponse expected = new BorderGatewayProtocolPeeringGetResponse { BgpPeering = new AzureBgpPeering() { AzureAutonomousSystemNumber = azureAsn, PeerAutonomousSystemNumber = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VirtualLanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t = new Task<BorderGatewayProtocolPeeringGetResponse>(() => expected); t.Start(); bgpMock.Setup( f => f.NewAsync(It.Is<string>(x => x == serviceKey), It.Is<BgpPeeringAccessType>( y => y == accessType), It.Is<BorderGatewayProtocolPeeringNewParameters>( z => z.PeerAutonomousSystemNumber == peerAsn && z.PrimaryPeerSubnet == primaryPeerSubnet && z.SecondaryPeerSubnet == secondayPeerSubnet && z.VirtualLanId == vlanId), It.IsAny<CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringNewParameters param, CancellationToken cancellation) => t); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); NewAzureBGPPeeringCommand cmdlet = new NewAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, PeerAsn = peerAsn, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryPeerSubnet = secondayPeerSubnet, SharedKey = null, VlanId = vlanId, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.AreEqual(expected.BgpPeering.State, actual.State); Assert.AreEqual(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }