Skip to content

Commit

Permalink
-SensorParametersInternal now has an internal constructor
Browse files Browse the repository at this point in the history
-Improved integration test handling of repairing a renamed probe name
-Implemented additional request engine, SetObjectPropertyParameter unit tests
-XmlDoc improvements
  • Loading branch information
lordmilko committed Nov 20, 2017
1 parent 3985a88 commit b0d14b8
Show file tree
Hide file tree
Showing 49 changed files with 587 additions and 101 deletions.
33 changes: 31 additions & 2 deletions PrtgAPI.Tests.IntegrationTests/Support/BasePrtgClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,18 @@ private static void RepairState()
{
if (client.GetProbes(Property.Id, Settings.Probe).First().Name != Settings.ProbeName)
{
Logger.Log("Restoring probe name");
client.SetObjectProperty(Settings.Probe, ObjectProperty.Name, Settings.ProbeName);
RestoreProbeName(client);
}
else
{
if (client.GetProbes(Property.Name, Settings.ProbeName).Count == 0)
{
Logger.Log("Probe could not be retrieved by name; previous rename may have failed. Re-attempting rename");
RestoreProbeName(client);

Logger.Log("Sleeping for 30 seconds so name change can properly apply");
Thread.Sleep(30000);
}
}
}
catch (Exception ex)
Expand All @@ -276,6 +286,25 @@ private static void RepairState()
}
}

private static void RestoreProbeName(PrtgClient client)
{
Logger.Log("Restoring probe name");
client.SetObjectProperty(Settings.Probe, ObjectProperty.Name, Settings.ProbeName);

var probe = client.GetProbes(Property.Name, Settings.ProbeName);

if (probe.Count == 0)
{
Logger.Log("Probe name didn't stick. Restoring probe name again");
client.SetObjectProperty(Settings.Probe, ObjectProperty.Name, Settings.ProbeName);

probe = client.GetProbes(Property.Name, Settings.ProbeName);

if (probe.Count == 0)
throw new Exception("Couldn't restore probe name");
}
}

protected static void RepairConfig()
{
Logger.Log("Repairing config");
Expand Down
35 changes: 35 additions & 0 deletions PrtgAPI.Tests.UnitTests/InfrastructureTests/PrtgClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -273,5 +274,39 @@ private void ExecuteFailedRequest(HttpStatusCode statusCode, string xml, string
Assert.Fail($"Exception did not contain expected error message. Expected: '{expectedError}'. Received: '{ex.Message}'");
}
}

[TestMethod]
[ExpectedException(typeof(TimeoutException))]
public void PrtgClient_HandlesTimeoutSocketException()
{
ExecuteSocketException(SocketError.TimedOut);
}

[TestMethod]
[ExpectedException(typeof(WebException))]
public void PrtgClient_HandlesConnectionRefusedSocketException()
{
ExecuteSocketException(SocketError.ConnectionRefused);
}

private void ExecuteSocketException(SocketError error)
{
var ctor = typeof(SocketException).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[]
{
typeof (int), typeof (EndPoint)
}, null);

var ex = (SocketException)ctor.Invoke(new object[]
{
(int) error, new IPEndPoint(new IPAddress(0x2414188f), 80)
});

var response = new ExceptionResponse(ex);
var webClient = new MockWebClient(response);

var client = new PrtgClient("prtg.example.com", "username", "1234567890", AuthMode.PassHash, webClient);

client.GetSensors();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using PrtgAPI.Parameters;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class AddNotificationTriggerTests : BaseTest
Expand Down
5 changes: 1 addition & 4 deletions PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/AddSensorTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Parameters;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class AddSensorTests : BaseTest
Expand Down
8 changes: 2 additions & 6 deletions PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/AdminToolTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class AdminToolTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class AutoDiscoverTests : BaseTest
Expand Down
8 changes: 2 additions & 6 deletions PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/CloneTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class CloneTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestItems;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class GetSensorHistoryTests : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using PrtgAPI.Tests.UnitTests.ObjectTests.TestItems;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class LogTests : StreamableObjectTests<Log, MessageItem, MessageResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Parameters;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class ParameterTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using PrtgAPI.Tests.UnitTests.ObjectTests.TestItems;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class PositionTests : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/RefreshTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class RefreshTests : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/RemoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class RemoveTests : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/RenameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class RenameTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class SensorSettingsTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using PrtgAPI.Tests.UnitTests.ObjectTests.TestItems;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class ServerStatusTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrtgAPI.Parameters;
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses;

namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
[TestClass]
public class SetNotificationTriggerTests : BaseTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
class FakeMultipleFormattable : IFormattableMultiple
{
public string GetSerializedFormat()
{
return "firstValue";
}

public string[] GetSerializedFormats()
{
return new[] {"firstValue", "secondValue"};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using PrtgAPI.Attributes;

namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
enum FakeObjectProperty
{
#region SetObjectPropertyParameters

[TypeLookup(typeof(FakeSettings))]
NormalProperty,

[TypeLookup(typeof(FakeSettings))]
[System.ComponentModel.Description("missingxmlelementbuthasdescription")]
MissingXmlElementButHasDescription,

[TypeLookup(typeof(FakeSettings))]
MissingXmlElementAndDescription,

MissingTypeLookup,

[TypeLookup(typeof(FakeSettings))]
[SecondaryProperty(nameof(SecondaryProperty))]
HasSecondaryProperty,

SecondaryProperty,

[TypeLookup(typeof(FakeSettings))]
MissingFromTypeLookupTarget,

[TypeLookup(typeof(FakeSettings))]
ParentProperty,

[DependentProperty(nameof(ParentProperty), "value")]
ChildProperty,

[TypeLookup(typeof(FakeSettings))]
ParentOfWrongType,

[DependentProperty(nameof(ParentOfWrongType), true)]
ChildWithWrongType,

[TypeLookup(typeof(FakeSettings))]
ParentOfReverseDependencyMissingTypeLookup,

[DependentProperty(nameof(ParentOfReverseDependencyMissingTypeLookup), "value", true)]
ChildPropertyWithReverseDependencyAndIsMissingTypeLookup,

[TypeLookup(typeof(FakeSettings))]
ParentOfReverseDependency,

[TypeLookup(typeof(FakeSettings))]
[DependentProperty(nameof(ParentOfReverseDependency), "value", true)]
ChildPropertyWithReverseDependency,

[TypeLookup(typeof(FakeSettings))]
[DependentProperty(nameof(ParentOfReverseDependency), "value1", true)]
ChildPropertyWithReverseDependencyAndWrongValue,

[TypeLookup(typeof(FakeSettings))]
[DependentProperty(nameof(ChildPropertyWithReverseDependencyAndWrongValue), "blah", true)]
GrandChildProperty,

PropertyParameterProperty,

#endregion SetObjectPropertyParameters
#region DynamicPropertyTypeParser

[TypeLookup(typeof(FakeSettings))]
ArrayProperty

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Reflection;
using PrtgAPI.Parameters;

namespace PrtgAPI.Tests.UnitTests.ObjectTests
{
class FakeSetObjectPropertyParameters : BaseSetObjectPropertyParameters<FakeObjectProperty>
{
private Func<Enum, PropertyInfo> getPropertyInfo;

public FakeSetObjectPropertyParameters(Func<Enum, PropertyInfo> getPropertyInfo)
{
this.getPropertyInfo = getPropertyInfo;
}

public void AddValue(Enum property, object value, bool disableDependentsOnNotReqiuiredValue)
{
AddTypeSafeValue(property, value, disableDependentsOnNotReqiuiredValue);
}

protected override PropertyInfo GetPropertyInfo(Enum property)
{
return getPropertyInfo(property);
}
}
}
Loading

0 comments on commit b0d14b8

Please sign in to comment.