Ejemplo n.º 1
0
        public void CanConvertFromString_WithCorrectValue_IsTrue()
        {
            const string input     = "192.168.1.1";
            var          converter = new IPEndPointConverter();

            Assert.IsTrue(converter.CanConvertFrom(input.GetType()));
        }
        public AutoMapperInfraDataConfig()
        {
            CreateMap <ModClientApiJson, ModNetworkContent>()
            .Include <ModClientApiJsonV3WithGameId, ModNetworkContent>()
            .BeforeMap((json, content) => { content?.Publishers.Clear(); })
            .ForMember(x => x.Version, opt => opt.ResolveUsing(src => src.GetVersion()))
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            .ForMember(x => x.RecentInfo, opt => opt.Ignore());
            // Does not get inherited?!
            CreateMap <ModClientApiJsonV3WithGameId, ModNetworkContent>()
            .BeforeMap((json, content) => { content?.Publishers.Clear(); })
            .ForMember(x => x.Version, opt => opt.ResolveUsing(src => src.GetVersion()))
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            .ForMember(x => x.RecentInfo, opt => opt.Ignore());

            CreateMap <ModClientApiJsonV3WithGameId, ModClientApiJsonV3WithGameId>();

            CreateMap <ContentPublisherApiJson, ContentPublisher>()
            .ConstructUsing(src => new ContentPublisher(src.Type, src.Id))
            .ForMember(x => x.Publisher, opt => opt.MapFrom(src => src.Type))
            .ForMember(x => x.PublisherId, opt => opt.MapFrom(src => src.Id));

            CreateMap <ContentDtoV2, NetworkContent>()
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            //.ForMember(x => x.Aliases, opt => opt.ResolveUsing(ResolveAliases))
            .ForMember(x => x.RecentInfo, opt => opt.Ignore())
            .ForMember(x => x.Size, opt => opt.MapFrom(src => src.SizeWd))
            .ForMember(x => x.SizePacked, opt => opt.MapFrom(src => src.Size))
            .Include <ModDtoV2, ModNetworkContent>()
            .Include <MissionDtoV2, MissionNetworkContent>();

            // TODO: Why do the above includes not work??
            CreateMap <ModDtoV2, ModNetworkContent>()
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            //.ForMember(x => x.Aliases, opt => opt.ResolveUsing(ResolveAliases))
            .ForMember(x => x.RecentInfo, opt => opt.Ignore())
            .ForMember(x => x.Version, opt => opt.ResolveUsing(src => src.GetVersion()));
            CreateMap <MissionDtoV2, MissionNetworkContent>()
            //.ForMember(x => x.Aliases, opt => opt.ResolveUsing(ResolveAliases))
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            .ForMember(x => x.RecentInfo, opt => opt.Ignore());

            CreateMap <CollectionVersionModel, SubscribedCollection>()
            .ForMember(x => x.Dependencies, opt => opt.Ignore())
            .ForMember(x => x.Id, opt => opt.Ignore());
            CreateMap <CollectionModelWithLatestVersion, SubscribedCollection>()
            .AfterMap((src, dst) => src.LatestVersion.MapTo(dst))
            .ForMember(x => x.IsOwner,
                       opt => opt.ResolveUsing((src, dst, b, ctx) => src.AuthorId == (Guid)ctx.Items["user-id"]));

            CreateMap <CollectionServer, CollectionVersionServerModel>()
            .ForMember(x => x.Address, opt => opt.MapFrom(src => src.Address.ToString()));
            CreateMap <CollectionVersionServerModel, CollectionServer>()
            .ForMember(x => x.Address, opt => opt.MapFrom(src => IPEndPointConverter.ToIpEndpoint(src.Address)));

            CreateMap <ModDtoV2, ModDtoV2>();
        }
Ejemplo n.º 3
0
        public void ConvertFromString_WithIPv6AddressAndNoBrackets_ParsesIPEndPoint()
        {
            var          expected  = new IPEndPoint(IPAddress.Parse("[1fbf:0:a88:85a3::ac1f]"), 8000);
            const string input     = "[1fbf:0:a88:85a3::ac1f]:8000";
            var          converter = new IPEndPointConverter();

            var actual = converter.ConvertFromString(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void ConvertFromString_WithCorrectValue_ParsesIPEndPoint()
        {
            var          expected  = new IPEndPoint(IPAddress.Parse("192.168.1.1"), 8000);
            const string input     = "192.168.1.1:8000";
            var          converter = new IPEndPointConverter();

            var actual = converter.ConvertFromString(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
		public TcpClient(string remoteEP)
		{
			if(string.IsNullOrWhiteSpace(remoteEP))
				throw new ArgumentNullException("remoteEP");

			IPEndPointConverter converter = new IPEndPointConverter();
			IPEndPoint endPoint = converter.ConvertFrom(remoteEP) as IPEndPoint;

			if(endPoint == null)
				throw new ArgumentException();

			if(endPoint.Port == 0)
				endPoint.Port = 7969;

			_remoteEP = endPoint;
		}
Ejemplo n.º 6
0
        public TcpClient(string remoteEP)
        {
            if (string.IsNullOrWhiteSpace(remoteEP))
            {
                throw new ArgumentNullException("remoteEP");
            }

            IPEndPointConverter converter = new IPEndPointConverter();
            IPEndPoint          endPoint  = converter.ConvertFrom(remoteEP) as IPEndPoint;

            if (endPoint == null)
            {
                throw new ArgumentException();
            }

            if (endPoint.Port == 0)
            {
                endPoint.Port = 7969;
            }

            _remoteEP = endPoint;
        }
Ejemplo n.º 7
0
 public void ParseTest()
 {
     Assert.NotNull(IPEndPointConverter.Parse("http://192.168.1.100:8080"));
     Assert.Null(IPEndPointConverter.Parse("http://www.google.com:80"));
 }
Ejemplo n.º 8
0
        public void CanConvertToIPEndPoint_WithCorrectValue_IsTrue()
        {
            var converter = new IPEndPointConverter();

            Assert.IsTrue(converter.CanConvertTo(typeof(IPEndPoint)));
        }