public void GetAzureBgpPeeringSuccessful()
        {
            // Setup

            string serviceKey             = "aa28cd19-b10a-41ff-981b-53c6bbf15ead";
            UInt32 peerAsn                = 64496;
            string primaryPeerSubnet      = "aaa";
            string secondayPeerSubnet     = "bbb";
            string primaryPeerSubnetIpv6  = "ccc";
            string secondayPeerSubnetIpv6 = "ddd";
            UInt32 azureAsn               = 64494;
            string primaryAzurePort       = "8081";
            string secondaryAzurePort     = "8082";
            var    state      = BgpPeeringState.Enabled;
            uint   vlanId     = 2;
            var    accessType = BgpPeeringAccessType.Microsoft;
            string advertisedPublicPrefixes     = "111";
            string advertisedPublicPrefixesIpv6 = "222";
            uint   customerAsn               = 11;
            uint   customerAsnIpv6           = 22;
            string advertisedCommunities     = "aaa";
            string advertisedCommunitiesIpv6 = "bbb";
            uint   legacyMode                        = 0;
            string routingRegistryName               = "yy";
            string routingRegistryNameIpv6           = "xx";
            string advertisedPublicPrefixesState     = "Configured";
            string advertisedPublicPrefixesStateIpv6 = "Configured";


            MockCommandRuntime mockCommandRuntime      = new MockCommandRuntime();
            Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient();
            var bgpMock = new Mock <IBorderGatewayProtocolPeeringOperations>();

            BorderGatewayProtocolPeeringGetResponse expected =
                new BorderGatewayProtocolPeeringGetResponse()
            {
                BgpPeering = new AzureBgpPeering()
                {
                    AdvertisedPublicPrefixes      = advertisedPublicPrefixes,
                    AdvertisedPublicPrefixesState = advertisedPublicPrefixesState,
                    AzureAsn = azureAsn,
                    CustomerAutonomousSystemNumber = customerAsn,
                    PeerAsn             = peerAsn,
                    PrimaryAzurePort    = primaryAzurePort,
                    PrimaryPeerSubnet   = primaryPeerSubnet,
                    SecondaryAzurePort  = secondaryAzurePort,
                    SecondaryPeerSubnet = secondayPeerSubnet,
                    State  = state,
                    VlanId = vlanId,
                    AdvertisedCommunities              = advertisedCommunities,
                    AdvertisedPublicPrefixesIpv6       = advertisedPublicPrefixesIpv6,
                    AdvertisedPublicPrefixesStateIpv6  = advertisedPublicPrefixesStateIpv6,
                    PrimaryPeerSubnetIpv6              = primaryPeerSubnetIpv6,
                    SecondaryPeerSubnetIpv6            = secondayPeerSubnetIpv6,
                    CustomerAutonomousSystemNumberIpv6 = customerAsnIpv6,
                    LegacyMode = legacyMode,
                    AdvertisedCommunitiesIpv6 = advertisedCommunitiesIpv6,
                    RoutingRegistryName       = routingRegistryName,
                    RoutingRegistryNameIpv6   = routingRegistryNameIpv6
                },
                RequestId  = "",
                StatusCode = new HttpStatusCode()
            };
            var t = new Task <BorderGatewayProtocolPeeringGetResponse>(() => expected);

            t.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);
            client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object);

            GetAzureBGPPeeringCommand cmdlet = new GetAzureBGPPeeringCommand()
            {
                ServiceKey         = Guid.Parse(serviceKey),
                AccessType         = accessType,
                CommandRuntime     = mockCommandRuntime,
                ExpressRouteClient = new ExpressRouteClient(client.Object)
            };

            cmdlet.ExecuteCmdlet();

            // Assert
            AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering;

            Assert.Equal(expected.BgpPeering.State, actual.State);
            Assert.Equal(expected.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort);
        }
Exemple #2
0
        public void GetAzureBgpPeeringSuccessful()
        {
            // 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.GetAsync(It.Is <string>(x => x == 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);

            GetAzureBGPPeeringCommand cmdlet = new GetAzureBGPPeeringCommand()
            {
                ServiceKey         = serviceKey,
                AccessType         = accessType,
                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 GetAzureBgpPeeringSuccessful()
        {
            // 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.GetAsync(It.Is<string>(x => x == 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);

            GetAzureBGPPeeringCommand cmdlet = new GetAzureBGPPeeringCommand()
            {
                ServiceKey = serviceKey,
                AccessType = accessType,
                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);
        }