//コンストラクタ public BindAddr(string str) { if (str == null) { ThrowException("BindAddr(null)"); //初期化失敗 return; } var tmp = str.Split(','); if (tmp.Length != 3) { ThrowException(str); //初期化失敗 } if (tmp[0] == "V4_ONLY" || tmp[0] == "V4Only" || tmp[0] == "V4ONLY") { tmp[0] = "V4Only"; } else if (tmp[0] == "V6_ONLY" || tmp[0] == "V6Only" || tmp[0] == "V6ONLY") { tmp[0] = "V6Only"; } else if (tmp[0] == "V46_DUAL" || tmp[0] == "V46Dual" || tmp[0] == "V46DUAL") { tmp[0] = "V46Dual"; } else { ThrowException(str); //初期化失敗 } try{ BindStyle = (BindStyle)Enum.Parse(typeof(BindStyle), tmp[0]); IpV4 = new Ip(tmp[1]); //Ver5.7.x以前のコンバート if (tmp[2] == "0.0.0.0") { tmp[2] = "::0"; } IpV6 = new Ip(tmp[2]); } catch (Exception) { ThrowException(str); //初期化失敗 } if (IpV4.InetKind != InetKind.V4) { ThrowException(str); //初期化失敗 } if (IpV6.InetKind != InetKind.V6) { ThrowException(str); //初期化失敗 } }
public void パラメータBindStyle_ipv4_ipv6でnewしたBindAddrオブジェクトをToStringで確認する( BindStyle bindStyle, string ipV4, string ipV6, string expected) { //setUp var sut = new BindAddr(bindStyle, new Ip(ipV4), new Ip(ipV6)); //exercise var actual = sut.ToString(); //verify Assert.That(actual, Is.EqualTo(expected)); }
//コンストラクタ public BindAddr(BindStyle bindStyle, Ip ipV4, Ip ipV6) { BindStyle = bindStyle; IpV4 = ipV4; IpV6 = ipV6; }
//デフォルト値の初期化 protected override sealed void Init() { BindStyle = BindStyle.V4Only; IpV4 = new Ip(IpKind.InAddrAny); IpV6 = new Ip(IpKind.In6AddrAnyInit); }