/// <summary> /// Calculate subnets /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void calculateButton_Click(object sender, RoutedEventArgs e) { // don't do a thing if there's no requests if (requests.Count == 0) { return; } // create and try to populate subnet collection subnetCollection = new SubnetCollection(); try { // ip address if (InputParser.TryParseIPAddress(IPAddressBox.Text.Trim(), out IPAddress iPAddress, out string errorMessage)) { subnetCollection.NetworkID = iPAddress; } else { throw new Exception(errorMessage); } // subnet mask if (InputParser.TryParseSubnetMask(subnetMaskBox.Text, out IPAddress subnetMask, out errorMessage)) { subnetCollection.SubnetMask = subnetMask; }
public void SubnetCollectionSerialization() { var subnets = new SubnetCollection { Subnets = { new Subnet { Id = Guid.NewGuid() } }, SubnetsLinks = { new Link("next", "http://api.com/next") } }; string json = JsonConvert.SerializeObject(subnets, Formatting.None); Assert.Contains("\"subnets\"", json); Assert.DoesNotContain("\"subnet\"", json); var result = JsonConvert.DeserializeObject <SubnetCollection>(json); Assert.NotNull(result); Assert.Equal(1, result.Count()); Assert.Equal(1, result.Subnets.Count()); Assert.Equal(1, result.SubnetsLinks.Count()); }