public void SetBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string newPrimaryPeerSubnet = "ccc"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; BgpPeeringState state = BgpPeeringState.Enabled; uint vlanId = 2; BgpPeeringAccessType 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(); BorderGatewayProtocolPeeringGetResponse expected2 = new BorderGatewayProtocolPeeringGetResponse() { BgpPeering = new AzureBgpPeering() { AzureAutonomousSystemNumber = azureAsn, PeerAutonomousSystemNumber = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = newPrimaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VirtualLanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t2 = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expected2); t2.Start(); bgpMock.Setup( f => f.GetAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => t); bgpMock.Setup( f => f.UpdateAsync(It.Is <string>(x => x == serviceKey), It.Is <BgpPeeringAccessType>( y => y == accessType), It.Is <BorderGatewayProtocolPeeringUpdateParameters>(z => z.PrimaryPeerSubnet == newPrimaryPeerSubnet), It.IsAny <CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringUpdateParameters param, CancellationToken cancellation) => t2); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); SetAzureBGPPeeringCommand cmdlet = new SetAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, PrimaryPeerSubnet = newPrimaryPeerSubnet, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.AreEqual <string>(expected2.BgpPeering.PrimaryPeerSubnet, actual.PrimaryPeerSubnet); Assert.AreEqual(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }
public void SetBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; UInt32 peerAsn = 64496; string primaryPeerSubnet = "aaa"; string newPrimaryPeerSubnet = "ccc"; string secondayPeerSubnet = "bbb"; UInt32 azureAsn = 64494; string primaryAzurePort = "8081"; string secondaryAzurePort = "8082"; BgpPeeringState state = BgpPeeringState.Enabled; uint vlanId = 2; BgpPeeringAccessType 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(); BorderGatewayProtocolPeeringGetResponse expected2 = new BorderGatewayProtocolPeeringGetResponse() { BgpPeering = new AzureBgpPeering() { AzureAutonomousSystemNumber = azureAsn, PeerAutonomousSystemNumber = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = newPrimaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VirtualLanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; var t2 = new Task<BorderGatewayProtocolPeeringGetResponse>(() => expected2); t2.Start(); bgpMock.Setup( f => f.GetAsync(It.Is<string>(x => x == serviceKey), It.Is<BgpPeeringAccessType>( y => y == accessType), It.IsAny<CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => t); bgpMock.Setup( f => f.UpdateAsync(It.Is<string>(x => x == serviceKey), It.Is<BgpPeeringAccessType>( y => y == accessType), It.Is<BorderGatewayProtocolPeeringUpdateParameters>(z => z.PrimaryPeerSubnet == newPrimaryPeerSubnet), It.IsAny<CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringUpdateParameters param, CancellationToken cancellation) => t2); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); SetAzureBGPPeeringCommand cmdlet = new SetAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, PrimaryPeerSubnet = newPrimaryPeerSubnet, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering; Assert.AreEqual<string>(expected2.BgpPeering.PrimaryPeerSubnet, actual.PrimaryPeerSubnet); Assert.AreEqual(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }