public void NewAzureDedicatedCircuitLinkSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; string vNetName = "DedicatedCircuitNetwork"; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dclMock = new Mock<IDedicatedCircuitLinkOperations>(); DedicatedCircuitLinkGetResponse expected = new DedicatedCircuitLinkGetResponse() { DedicatedCircuitLink = new AzureDedicatedCircuitLink() { VnetName = vNetName, State = DedicatedCircuitLinkState.Provisioned }, RequestId = "", StatusCode = new HttpStatusCode() }; var tGet = new Task<DedicatedCircuitLinkGetResponse>(() => expected); tGet.Start(); ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse() { HttpStatusCode = HttpStatusCode.OK }; var tNew = new Task<ExpressRouteOperationStatusResponse>(() => expectedStatus); tNew.Start(); dclMock.Setup(f => f.NewAsync(It.Is<string>(x => x == serviceKey), It.Is<string>(y => y == vNetName), It.IsAny<CancellationToken>())).Returns((string sKey, string vNet, CancellationToken cancellation) => tNew); dclMock.Setup(f => f.GetAsync(It.Is<string>(skey => skey == serviceKey), It.Is<string>(vnet => vnet == vNetName), It.IsAny<CancellationToken>())).Returns((string skey, string vnet, CancellationToken cancellation) => tGet); client.SetupGet(f => f.DedicatedCircuitLinks).Returns(dclMock.Object); NewAzureDedicatedCircuitLinkCommand cmdlet = new NewAzureDedicatedCircuitLinkCommand() { ServiceKey = Guid.Parse(serviceKey), VNetName = vNetName, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureDedicatedCircuitLink actual = mockCommandRuntime.OutputPipeline[0] as AzureDedicatedCircuitLink; Assert.Equal<string>(expected.DedicatedCircuitLink.VnetName, actual.VnetName); Assert.Equal(expected.DedicatedCircuitLink.State.ToString(), actual.State.ToString()); }
public void RemoveAzureDedicatedCircuitSuccessful() { string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; string vNetName = "DedicatedCircuitNetwork"; ExpressRouteOperationStatusResponse expected = new ExpressRouteOperationStatusResponse() { Status = ExpressRouteOperationStatus.Successful, HttpStatusCode = HttpStatusCode.OK }; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dclMock = new Mock<IDedicatedCircuitLinkOperations>(); var t = new Task<ExpressRouteOperationStatusResponse>(() => expected); t.Start(); dclMock.Setup(f => f.RemoveAsync(It.Is<string>(sKey => sKey == serviceKey), It.Is<string>(vnet => vnet == vNetName), It.IsAny<CancellationToken>())).Returns((string sKey, string vnet, CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuitLink).Returns(dclMock.Object); RemoveAzureDedicatedCircuitLinkCommand cmdlet = new RemoveAzureDedicatedCircuitLinkCommand() { ServiceKey = serviceKey, VNetName = vNetName, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); Assert.IsTrue(mockCommandRuntime.VerboseStream[0].Contains(serviceKey)); }
public void NewAzureDedicatedCircuitSuccessful() { // Setup string circuitName = "TestCircuit"; uint bandwidth = 10; string serviceProviderName = "TestProvider"; string location = "us-west"; string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; BillingType billingType = BillingType.UnlimitedData; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcMock = new Mock<IDedicatedCircuitOperations>(); DedicatedCircuitGetResponse expected = new DedicatedCircuitGetResponse() { DedicatedCircuit = new AzureDedicatedCircuit() { CircuitName = circuitName, Bandwidth = bandwidth, BillingType = billingType.ToString(), Location = location, ServiceProviderName = serviceProviderName, ServiceKey = serviceKey, ServiceProviderProvisioningState = ProviderProvisioningState.NotProvisioned, Status = DedicatedCircuitState.Enabled, }, RequestId = "", StatusCode = new HttpStatusCode() }; var tGet = new Task<DedicatedCircuitGetResponse>(() => expected); tGet.Start(); ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse() { HttpStatusCode = HttpStatusCode.OK, Data = serviceKey }; var tNew = new Task<ExpressRouteOperationStatusResponse>(() => expectedStatus); tNew.Start(); dcMock.Setup(f => f.NewAsync(It.Is<DedicatedCircuitNewParameters>(x => x.Bandwidth == bandwidth && x.CircuitName == circuitName && x.Location == location && x.ServiceProviderName == serviceProviderName), It.IsAny<CancellationToken>())).Returns((DedicatedCircuitNewParameters param, CancellationToken cancellation) => tNew); dcMock.Setup(f => f.GetAsync(It.Is<string>(sKey => sKey == serviceKey), It.IsAny<CancellationToken>())).Returns((string sKey, CancellationToken cancellation) => tGet); client.SetupGet(f => f.DedicatedCircuits).Returns(dcMock.Object); NewAzureDedicatedCircuitCommand cmdlet = new NewAzureDedicatedCircuitCommand() { CircuitName = circuitName, Bandwidth = bandwidth, BillingType = billingType, Location = location, ServiceProviderName = serviceProviderName, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert AzureDedicatedCircuit actual = mockCommandRuntime.OutputPipeline[0] as AzureDedicatedCircuit; Assert.Equal<string>(expected.DedicatedCircuit.CircuitName, actual.CircuitName); Assert.Equal<string>(expected.DedicatedCircuit.BillingType, actual.BillingType); Assert.Equal<uint>(expected.DedicatedCircuit.Bandwidth, actual.Bandwidth); Assert.Equal<string>(expected.DedicatedCircuit.Location, actual.Location); Assert.Equal<string>(expected.DedicatedCircuit.ServiceProviderName, actual.ServiceProviderName); Assert.Equal(expected.DedicatedCircuit.ServiceProviderProvisioningState, actual.ServiceProviderProvisioningState); Assert.Equal(expected.DedicatedCircuit.Status, actual.Status); Assert.Equal<string>(expected.DedicatedCircuit.ServiceKey, actual.ServiceKey); }
public void RemoveAzureBgpPeeringSuccessful() { // Setup string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead"; BgpPeeringAccessType accessType = BgpPeeringAccessType.Private; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var bgpMock = new Mock<IBorderGatewayProtocolPeeringOperations>(); ExpressRouteOperationStatusResponse expected = new ExpressRouteOperationStatusResponse() { Status = ExpressRouteOperationStatus.Successful, HttpStatusCode = HttpStatusCode.OK }; var t = new Task<ExpressRouteOperationStatusResponse>(() => expected); t.Start(); bgpMock.Setup(f => f.RemoveAsync(It.Is<string>(sKey => sKey == serviceKey), It.Is<BgpPeeringAccessType>( y => y == accessType), It.IsAny<CancellationToken>())) .Returns((string sKey, BgpPeeringAccessType aType, CancellationToken cancellation) => t); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); RemoveAzureBGPPeeringCommand cmdlet = new RemoveAzureBGPPeeringCommand() { ServiceKey = serviceKey, AccessType = accessType, CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); Assert.True(mockCommandRuntime.VerboseStream[0].Contains(serviceKey)); }
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 expectedBgp = new BorderGatewayProtocolPeeringGetResponse { BgpPeering = new AzureBgpPeering() { AzureAsn = azureAsn, PeerAsn = peerAsn, PrimaryAzurePort = primaryAzurePort, PrimaryPeerSubnet = primaryPeerSubnet, SecondaryAzurePort = secondaryAzurePort, SecondaryPeerSubnet = secondayPeerSubnet, State = state, VlanId = vlanId }, RequestId = "", StatusCode = new HttpStatusCode() }; ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse() { HttpStatusCode = HttpStatusCode.OK }; var tGet = new Task<BorderGatewayProtocolPeeringGetResponse>(() => expectedBgp); tGet.Start(); var tNew = new Task<ExpressRouteOperationStatusResponse>(() => expectedStatus); tNew.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) => tNew); client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object); 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) => tGet); 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.Equal(expectedBgp.BgpPeering.State, actual.State); Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort); }