Exemplo n.º 1
0
        public VpnLocations Convert(string payload)
        {
            var locationResponse = new VpnLocations();

            var xdoc = XDocument.Parse(payload);

            foreach (var element in xdoc.Root.Elements())
            {
                var name = element.Name.LocalName;

                switch (name)
                {
                case XML_ICONS:
                    _IconDictionary = GetIconDictionary(GetIcons(element));
                    break;

                case XML_LOCATIONS:
                    locationResponse.Locations = GetLocations(element);
                    break;

                case XML_BUTTONTEXT:
                    locationResponse.ButtonText = element.Value;
                    break;

                default:
                    break;
                }
            }

            return(locationResponse);
        }
Exemplo n.º 2
0
        private void ButonTextTest()
        {
            var VpnLocations = new VpnLocations();

            VpnLocations.ButtonText = "Test Button Text";

            var converterMock = new Mock <ILocationResponseConverter>();

            converterMock.Setup(x => x.Convert(null)).Returns(VpnLocations);
            var typedLocations = converterMock.Object.Convert(null);

            var serviceMock = new Mock <ILocationService>();

            serviceMock.Setup(x => x.GetLocations()).Returns(Task.FromResult(typedLocations));

            var pingerMock = new Mock <IExecutePing>();

            pingerMock.Setup(x => x.RoundtripTime).Returns(1L);

            var pingerFactoryMock = new Mock <IExecutePingFactory>();

            pingerFactoryMock.Setup(x => x.Create()).Returns(pingerMock.Object);

            var viewModel = new LocationViewModel(serviceMock.Object, pingerFactoryMock.Object);

            viewModel.RefreshCommand.Execute(null);

            Assert.NotNull(viewModel.ButtonText);
            Assert.Equal(VpnLocations.ButtonText, viewModel.ButtonText);
        }
Exemplo n.º 3
0
        private void LocationsTest()
        {
            var location0 = new Location();

            location0.Name      = "India - Mumbai";
            location0.SortOrder = 99;
            location0.Icon      = new Icon()
            {
                Id = 1, Value = IconData.IconId03Bytes
            };
            location0.Servers = new Server[]
            {
                new Server()
                {
                    IP = IPAddress.Parse("10.10.10.10")
                },
                new Server()
                {
                    IP = IPAddress.Parse("20.20.20.20")
                }
            };

            var location1 = new Location();

            location1.Name      = "India - Banglore";
            location1.SortOrder = 99;
            location1.Icon      = new Icon()
            {
                Id = 1, Value = IconData.IconId03Bytes
            };
            location1.Servers = new Server[]
            {
                new Server()
                {
                    IP = IPAddress.Parse("30.30.30.30")
                }
            };

            var VpnLocations = new VpnLocations();

            VpnLocations.ButtonText = "Test Button Text";
            VpnLocations.Locations  = new Location[] { location0, location1 };

            var converterMock = new Mock <ILocationResponseConverter>();

            converterMock.Setup(x => x.Convert(null)).Returns(VpnLocations);
            var typedLocations = converterMock.Object.Convert(null);

            var serviceMock = new Mock <ILocationService>();

            serviceMock.Setup(x => x.GetLocations()).Returns(Task.FromResult(typedLocations));

            var pingerMock = new Mock <IExecutePing>();

            pingerMock.Setup(x => x.RoundtripTime).Returns(1L);

            var pingerFactoryMock = new Mock <IExecutePingFactory>();

            pingerFactoryMock.Setup(x => x.Create()).Returns(pingerMock.Object);

            var viewModel = new LocationViewModel(serviceMock.Object, pingerFactoryMock.Object);

            viewModel.RefreshCommand.Execute(null);

            while (viewModel.DataRequestInprogress)
            {
            }

            Assert.NotNull(viewModel.Locations);
            Assert.Equal(3, viewModel.Locations.Count);
        }