Remove Jenkinsfile and add unit tests for various models including Address, Domain, Nameserver, Section, Session, Subnetwork, Tag, Vlan, and Vrf. Introduce mock classes for HTTP requests and cmdlet testing.
This commit is contained in:
116
classlib.tests/Models/AddressTests.cs
Normal file
116
classlib.tests/Models/AddressTests.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
namespace PS.IPAM.Tests.Models;
|
||||
|
||||
using FluentAssertions;
|
||||
using PS.IPAM;
|
||||
using Xunit;
|
||||
|
||||
public class AddressTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_SetsAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
var id = 1;
|
||||
var subnetId = 10;
|
||||
var ip = "192.168.1.100";
|
||||
var isGateway = true;
|
||||
var description = "Test server";
|
||||
var hostname = "server01.example.com";
|
||||
var mac = "00:11:22:33:44:55";
|
||||
var owner = "admin";
|
||||
var tagId = 2;
|
||||
var deviceId = 5;
|
||||
var location = "DC1";
|
||||
var port = "eth0";
|
||||
var note = "Production server";
|
||||
var lastSeen = new DateTime(2026, 1, 15, 10, 30, 0);
|
||||
var excludePing = false;
|
||||
var ptrIgnore = true;
|
||||
var ptr = 1;
|
||||
var firewallObject = "FW_SERVER01";
|
||||
var editDate = new DateTime(2026, 1, 10, 8, 0, 0);
|
||||
var customerId = 100;
|
||||
var extendedData = new Dictionary<string, object> { { "custom_field1", "value1" } };
|
||||
|
||||
// Act
|
||||
var address = new Address(
|
||||
id, subnetId, ip, isGateway, description, hostname, mac, owner,
|
||||
tagId, deviceId, location, port, note, lastSeen, excludePing,
|
||||
ptrIgnore, ptr, firewallObject, editDate, customerId, extendedData
|
||||
);
|
||||
|
||||
// Assert
|
||||
address.Id.Should().Be(id);
|
||||
address.SubnetId.Should().Be(subnetId);
|
||||
address.Ip.Should().Be(ip);
|
||||
address.IsGateway.Should().Be(isGateway);
|
||||
address.Description.Should().Be(description);
|
||||
address.Hostname.Should().Be(hostname);
|
||||
address.MAC.Should().Be(mac);
|
||||
address.Owner.Should().Be(owner);
|
||||
address.TagId.Should().Be(tagId);
|
||||
address.DeviceId.Should().Be(deviceId);
|
||||
address.Location.Should().Be(location);
|
||||
address.Port.Should().Be(port);
|
||||
address.Note.Should().Be(note);
|
||||
address.LastSeen.Should().Be(lastSeen);
|
||||
address.ExcludePing.Should().Be(excludePing);
|
||||
address.PTRignore.Should().Be(ptrIgnore);
|
||||
address.PTR.Should().Be(ptr);
|
||||
address.FirewallAddressObject.Should().Be(firewallObject);
|
||||
address.EditDate.Should().Be(editDate);
|
||||
address.CustomerId.Should().Be(customerId);
|
||||
address.ExtendedData.Should().BeEquivalentTo(extendedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithNullOptionalFields_SetsNullValues()
|
||||
{
|
||||
// Act
|
||||
var address = new Address(
|
||||
1, 10, "10.0.0.1", false, "", "", "", "",
|
||||
0, 0, "", "", "", null, false,
|
||||
false, 0, "", null, 0, null
|
||||
);
|
||||
|
||||
// Assert
|
||||
address.LastSeen.Should().BeNull();
|
||||
address.EditDate.Should().BeNull();
|
||||
address.ExtendedData.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_ReturnsIpAddress()
|
||||
{
|
||||
// Arrange
|
||||
var address = new Address(
|
||||
1, 10, "192.168.1.50", false, "Test", "host.local", "", "",
|
||||
0, 0, "", "", "", null, false,
|
||||
false, 0, "", null, 0, null
|
||||
);
|
||||
|
||||
// Act
|
||||
var result = address.ToString();
|
||||
|
||||
// Assert
|
||||
result.Should().Be("192.168.1.50");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("10.0.0.1")]
|
||||
[InlineData("172.16.0.100")]
|
||||
[InlineData("192.168.255.255")]
|
||||
[InlineData("2001:db8::1")]
|
||||
public void ToString_ReturnsCorrectIp_ForVariousAddresses(string expectedIp)
|
||||
{
|
||||
// Arrange
|
||||
var address = new Address(
|
||||
1, 1, expectedIp, false, "", "", "", "",
|
||||
0, 0, "", "", "", null, false,
|
||||
false, 0, "", null, 0, null
|
||||
);
|
||||
|
||||
// Act & Assert
|
||||
address.ToString().Should().Be(expectedIp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user