diff --git a/CHANGELOG.md b/CHANGELOG.md
index c0821a1..012b788 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Unreleased
- Added SearchService.SearchByPostCodeOrSize, a method to search for both parameters at the same time [#31](https://github.com/pyrocumulus/pvoutput.net/pull/31)
+- Added SystemService.PostSystem, enabling the modification of a system's name and/or extended value [#32](https://github.com/pyrocumulus/pvoutput.net/pull/32)
## [0.7.0] - 2020-04-08
diff --git a/src/PVOutput.Net/Builders/ExtendedDataDefinitionBuilder.cs b/src/PVOutput.Net/Builders/ExtendedDataDefinitionBuilder.cs
new file mode 100644
index 0000000..67cec1d
--- /dev/null
+++ b/src/PVOutput.Net/Builders/ExtendedDataDefinitionBuilder.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Dawn;
+using PVOutput.Net.Enums;
+using PVOutput.Net.Objects;
+using PVOutput.Net.Objects.Modules.Implementations;
+
+namespace PVOutput.Net.Builders
+{
+ ///
+ /// Builder for creating extended data definitions, used to update systems.
+ ///
+ public sealed class ExtendedDataDefinitionBuilder
+ {
+ internal ExtendedDataDefinition _definition;
+
+ ///
+ /// Creates a new builder.
+ ///
+ public ExtendedDataDefinitionBuilder()
+ {
+ _definition = new ExtendedDataDefinition();
+ }
+
+ ///
+ /// The index that specifies which extended data value to update.
+ ///
+ /// The index of the extended data value.
+ /// The builder.
+ public ExtendedDataDefinitionBuilder SetIndex(ExtendedDataIndex index)
+ {
+ _definition.Index = index;
+ return this;
+ }
+
+ ///
+ /// Sets the label of the extended data value.
+ ///
+ /// The label to set.
+ /// The builder.
+ public ExtendedDataDefinitionBuilder SetLabel(string label)
+ {
+ Guard.Argument(label).MaxLength(20);
+
+ _definition.Label = label;
+ return this;
+ }
+
+ ///
+ /// Sets the unit of the extended data value.
+ ///
+ /// The unit to set.
+ /// The builder.
+ public ExtendedDataDefinitionBuilder SetUnit(string unit)
+ {
+ Guard.Argument(unit).MaxLength(10);
+
+ _definition.Unit = unit;
+ return this;
+ }
+
+ ///
+ /// Sets the displayed colour of the extended data value.
+ ///
+ /// Hexadecimal colour to display 6 hexadecimal characters.
+ /// The builder.
+ public ExtendedDataDefinitionBuilder SetColour(string colour)
+ {
+ Guard.Argument(colour).Length(6);
+ Guard.Argument(colour).Require(IsHexadecimalString, m => "Colour should be a hexadecimal string.");
+
+ _definition.Colour = colour;
+ return this;
+ }
+
+ ///
+ /// Sets the axis used to display the extended data value on.
+ ///
+ /// The axis to display the extended data value on.
+ /// The builder
+ public ExtendedDataDefinitionBuilder SetAxis(int axis)
+ {
+ Guard.Argument(axis).InRange(0, 5);
+
+ _definition.Axis = axis;
+ return this;
+ }
+
+ ///
+ /// Sets the graph type used to display the extended data value.
+ ///
+ /// Display type to use.
+ /// The builder.
+ public ExtendedDataDefinitionBuilder SetDisplayType(ExtendedDataDisplayType displayType)
+ {
+ _definition.DisplayType = displayType;
+ return this;
+ }
+
+ ///
+ /// Uses information within the builder to return the built data definition.
+ ///
+ /// The extended data definition.
+ public IExtendedDataDefinition Build()
+ {
+ return _definition;
+ }
+
+ ///
+ /// Uses information within the builder to return the built data definition.
+ /// Resets the builder to it's default state after building.
+ ///
+ /// The extended data definition.
+ public IExtendedDataDefinition BuildAndReset()
+ {
+ var result = _definition;
+ _definition = new ExtendedDataDefinition();
+ return result;
+ }
+
+ ///
+ /// Resets the builder to it's default state. Ready to build a new definition.
+ ///
+ /// The builder in it's default state.
+ public ExtendedDataDefinitionBuilder Reset()
+ {
+ _definition = new ExtendedDataDefinition();
+ return this;
+ }
+
+ internal static bool IsHexadecimalString(string colour)
+ {
+ foreach (char character in colour.ToUpperInvariant())
+ {
+ if (!IsHexadecimalCharacter(character))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ internal static bool IsHexadecimalCharacter(char character)
+ {
+ if (character >= '0' && character <= '9')
+ {
+ return true;
+ }
+
+ if (character >= 'A' && character <= 'F')
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/src/PVOutput.Net/Enums/ExtendedDataDisplayType.cs b/src/PVOutput.Net/Enums/ExtendedDataDisplayType.cs
new file mode 100644
index 0000000..8670fe8
--- /dev/null
+++ b/src/PVOutput.Net/Enums/ExtendedDataDisplayType.cs
@@ -0,0 +1,18 @@
+namespace PVOutput.Net.Enums
+{
+ ///
+ /// Defines how to display the extended value.
+ ///
+ public enum ExtendedDataDisplayType
+ {
+ ///
+ /// Display as line in graph.
+ ///
+ Line,
+
+ ///
+ /// Display as area in graph.
+ ///
+ Area
+ }
+}
diff --git a/src/PVOutput.Net/Enums/ExtendedDataIndex.cs b/src/PVOutput.Net/Enums/ExtendedDataIndex.cs
new file mode 100644
index 0000000..900bbe2
--- /dev/null
+++ b/src/PVOutput.Net/Enums/ExtendedDataIndex.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Text;
+
+namespace PVOutput.Net.Enums
+{
+ ///
+ /// Describes the index of an extended data value.
+ ///
+ public enum ExtendedDataIndex
+ {
+ ///
+ /// Extended data value v7.
+ ///
+ v7,
+
+ ///
+ /// Extended data value v8.
+ ///
+ v8,
+
+ ///
+ /// Extended data value v9.
+ ///
+ v9,
+
+ ///
+ /// Extended data value v10.
+ ///
+ v10,
+
+ ///
+ /// Extended data value v11.
+ ///
+ v11,
+
+ ///
+ /// Extended data value v12.
+ ///
+ v12
+ }
+}
diff --git a/src/PVOutput.Net/Modules/OutputService.cs b/src/PVOutput.Net/Modules/OutputService.cs
index ec14892..cb8ee93 100644
--- a/src/PVOutput.Net/Modules/OutputService.cs
+++ b/src/PVOutput.Net/Modules/OutputService.cs
@@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Dawn;
+using PVOutput.Net.Builders;
using PVOutput.Net.Enums;
using PVOutput.Net.Objects;
using PVOutput.Net.Objects.Core;
@@ -148,6 +149,7 @@ public Task> GetAggregatedOutputsAsync(
///
/// Adds a single daily output to the owned system.
/// See the official API information.
+ /// Use the to create objects.
///
/// The output to add.
/// A cancellation token for the request.
@@ -168,6 +170,7 @@ public Task AddOutputAsync(IOutputPost output, Cancellati
///
/// Adds a list of outputs to the owned system.
/// See the official API information.
+ /// Use the to create objects.
///
/// Outputs to add. 30 outputs is the maximum, 100 for donation
/// A cancellation token for the request.
diff --git a/src/PVOutput.Net/Modules/StatusService.cs b/src/PVOutput.Net/Modules/StatusService.cs
index be43122..f3d0e8b 100644
--- a/src/PVOutput.Net/Modules/StatusService.cs
+++ b/src/PVOutput.Net/Modules/StatusService.cs
@@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Dawn;
+using PVOutput.Net.Builders;
using PVOutput.Net.Objects;
using PVOutput.Net.Objects.Core;
using PVOutput.Net.Requests.Handler;
@@ -101,6 +102,7 @@ public Task> GetDayStatisticsForPeriodAsync(Dat
///
/// Adds a single status to the owned system.
/// See the official API information.
+ /// Use the to create objects.
///
/// The status to add.
/// A cancellation token for the request.
@@ -121,6 +123,7 @@ public Task AddStatusAsync(IStatusPost status, Cancellati
///
/// Adds multiple statuses to the owned system.
/// See the official API information.
+ /// Use the to create objects.
///
/// The statuses to add.
/// A cancellation token for the request.
diff --git a/src/PVOutput.Net/Modules/SystemService.cs b/src/PVOutput.Net/Modules/SystemService.cs
index 9f1567e..1b0b8fa 100644
--- a/src/PVOutput.Net/Modules/SystemService.cs
+++ b/src/PVOutput.Net/Modules/SystemService.cs
@@ -1,6 +1,9 @@
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
+using Dawn;
+using PVOutput.Net.Builders;
using PVOutput.Net.Objects;
using PVOutput.Net.Objects.Core;
using PVOutput.Net.Requests.Handler;
@@ -54,5 +57,29 @@ public Task> GetOtherSystemAsync(int systemId, Cancell
var handler = new RequestHandler(Client);
return handler.ExecuteSingleItemRequestAsync(new SystemRequest { SystemId = systemId, MonthlyEstimates = false }, loggingScope, cancellationToken);
}
+
+ ///
+ /// Updates a system's name or extended data values.
+ /// Use the to create definition for extended data values.
+ /// See the official API information.
+ ///
+ /// The system to update.
+ /// A new name for the system.
+ /// List of modified extended data definitions.
+ /// A cancellation token for the request.
+ /// If the operation succeeded.
+ public Task PostSystem(int systemId, string systemName = null, IEnumerable dataDefinitions = null, CancellationToken cancellationToken = default)
+ {
+ var loggingScope = new Dictionary()
+ {
+ [LoggingEvents.RequestId] = LoggingEvents.SystemService_PostSystem,
+ [LoggingEvents.Parameter_SystemId] = systemId
+ };
+
+ Guard.Argument(systemName).MaxLength(30);
+
+ var handler = new RequestHandler(Client);
+ return handler.ExecutePostRequestAsync(new PostSystemRequest() { SystemId = systemId, SystemName = systemName, DataDefinitions = dataDefinitions }, loggingScope, cancellationToken);
+ }
}
}
diff --git a/src/PVOutput.Net/Objects/Core/LoggingEvents.cs b/src/PVOutput.Net/Objects/Core/LoggingEvents.cs
index 1be37bd..1fb8f87 100644
--- a/src/PVOutput.Net/Objects/Core/LoggingEvents.cs
+++ b/src/PVOutput.Net/Objects/Core/LoggingEvents.cs
@@ -96,6 +96,7 @@ internal class LoggingEvents
public const int SystemService_GetOwnSystem = 21001;
public const int SystemService_GetOtherSystem = 21002;
+ public const int SystemService_PostSystem = 21003;
public const int TeamService_GetTeam = 21101;
public const int TeamService_JoinTeam = 21102;
diff --git a/src/PVOutput.Net/Objects/IExtendedDataDefinition.cs b/src/PVOutput.Net/Objects/IExtendedDataDefinition.cs
new file mode 100644
index 0000000..6139f46
--- /dev/null
+++ b/src/PVOutput.Net/Objects/IExtendedDataDefinition.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using PVOutput.Net.Enums;
+
+namespace PVOutput.Net.Objects
+{
+ ///
+ /// Defines an extended data value for a system.
+ ///
+ public interface IExtendedDataDefinition
+ {
+ ///
+ /// The index of the extended data value (v7-v12).
+ ///
+ ExtendedDataIndex Index { get; set; }
+
+ ///
+ /// The label of the extended data value.
+ ///
+ string Label { get; set; }
+
+ ///
+ /// The unit of the extended data value.
+ ///
+ string Unit { get; set; }
+
+ ///
+ /// The hexadecimal colour (ffffff) used to display the extended data value.
+ ///
+ string Colour { get; set; }
+
+ ///
+ /// The axis on which to display the extended data value.
+ ///
+ int? Axis { get; set; }
+
+ ///
+ /// The type of graph to display the extended data value with.
+ ///
+ ExtendedDataDisplayType? DisplayType { get; set; }
+ }
+}
diff --git a/src/PVOutput.Net/Objects/Modules/Implementations/ExtendedDataDefinition.cs b/src/PVOutput.Net/Objects/Modules/Implementations/ExtendedDataDefinition.cs
new file mode 100644
index 0000000..5944e38
--- /dev/null
+++ b/src/PVOutput.Net/Objects/Modules/Implementations/ExtendedDataDefinition.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using PVOutput.Net.Enums;
+
+namespace PVOutput.Net.Objects.Modules.Implementations
+{
+ internal class ExtendedDataDefinition : IExtendedDataDefinition
+ {
+ public ExtendedDataIndex Index { get; set; }
+ public string Label { get; set; }
+ public string Unit { get; set; }
+ public string Colour { get; set; }
+ public int? Axis { get; set; }
+ public ExtendedDataDisplayType? DisplayType { get; set; }
+ }
+}
diff --git a/src/PVOutput.Net/Requests/Modules/PostSystemRequest.cs b/src/PVOutput.Net/Requests/Modules/PostSystemRequest.cs
new file mode 100644
index 0000000..56a873b
--- /dev/null
+++ b/src/PVOutput.Net/Requests/Modules/PostSystemRequest.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using PVOutput.Net.Objects;
+using PVOutput.Net.Objects.Core;
+using PVOutput.Net.Requests.Base;
+
+namespace PVOutput.Net.Requests.Modules
+{
+ internal class PostSystemRequest : PostRequest
+ {
+ public int SystemId { get; set; }
+ public string SystemName { get; set; }
+ public IEnumerable DataDefinitions { get; set; }
+
+ public override HttpMethod Method => HttpMethod.Post;
+ public override string UriTemplate => "postsystem.jsp{?sid,name," +
+ "v7l,v7u,v7c,v7a,v7g,v8l,v8u,v8c,v8a,v8g,v9l,v9u,v9c,v9a,v9g," +
+ "v10l,v10u,v10c,v10a,v10g,v11l,v11u,v11c,v11a,v11g,v12l,v12u,v12c,v12a,v12g}";
+
+ public override IDictionary GetUriPathParameters()
+ {
+ var parameters = new Dictionary
+ {
+ ["sid"] = SystemId,
+ ["name"] = SystemName,
+ };
+
+ AddDataDefinitions(parameters);
+ return parameters;
+ }
+
+ private void AddDataDefinitions(Dictionary parameters)
+ {
+ if (DataDefinitions?.Any() != true)
+ return;
+
+ foreach (IExtendedDataDefinition definition in DataDefinitions)
+ {
+ var index = definition.Index.ToString();
+
+ if (!string.IsNullOrEmpty(definition.Label))
+ {
+ parameters[$"{index}l"] = definition.Label;
+ }
+
+ if (!string.IsNullOrEmpty(definition.Unit))
+ {
+ parameters[$"{index}u"] = definition.Unit;
+ }
+
+ if (!string.IsNullOrEmpty(definition.Colour))
+ {
+ parameters[$"{index}c"] = definition.Colour;
+ }
+
+ if (definition.Axis.HasValue)
+ {
+ parameters[$"{index}a"] = definition.Axis;
+ }
+
+ if (definition.DisplayType.HasValue)
+ {
+ parameters[$"{index}g"] = definition.DisplayType.ToString();
+ }
+ }
+ }
+ }
+}
diff --git a/tests/PVOutput.Net.Tests/Modules/BaseRequestsTest.cs b/tests/PVOutput.Net.Tests/Modules/BaseRequestsTest.cs
index 0ef5f1d..9f72c06 100644
--- a/tests/PVOutput.Net.Tests/Modules/BaseRequestsTest.cs
+++ b/tests/PVOutput.Net.Tests/Modules/BaseRequestsTest.cs
@@ -26,5 +26,14 @@ protected static void AssertStandardResponse(PVOutputArray
Assert.IsNotNull(response.Values);
});
}
+
+ protected static void AssertStandardResponse(PVOutputBasicResponse response)
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.IsNull(response.Error);
+ Assert.IsTrue(response.IsSuccess);
+ });
+ }
}
}
diff --git a/tests/PVOutput.Net.Tests/Modules/System/ExtendedDataDefinitionBuilderTests.cs b/tests/PVOutput.Net.Tests/Modules/System/ExtendedDataDefinitionBuilderTests.cs
new file mode 100644
index 0000000..8bf4253
--- /dev/null
+++ b/tests/PVOutput.Net.Tests/Modules/System/ExtendedDataDefinitionBuilderTests.cs
@@ -0,0 +1,115 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using PVOutput.Net.Builders;
+using PVOutput.Net.Enums;
+using PVOutput.Net.Objects;
+using PVOutput.Net.Objects.Factories;
+using PVOutput.Net.Objects.Modules;
+using PVOutput.Net.Requests.Modules;
+using PVOutput.Net.Tests.Utils;
+
+namespace PVOutput.Net.Tests.Modules.System
+{
+ [TestFixture]
+ public class ExtendedDataDefinitionBuilderTests
+ {
+ [Test]
+ public void Builder_WithIndex_SetsIndex()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetIndex(ExtendedDataIndex.v9);
+ Assert.AreEqual(ExtendedDataIndex.v9, builder._definition.Index);
+ }
+
+ [Test]
+ public void Builder_WithLabel_SetsLabel()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetLabel("New label");
+ Assert.AreEqual("New label", builder._definition.Label);
+ }
+
+ [Test]
+ public void Builder_WithUnit_SetsUnit()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetUnit("Wh");
+ Assert.AreEqual("Wh", builder._definition.Unit);
+ }
+
+ [Test]
+ public void Builder_WithAxis_SetsAxis()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetAxis(2);
+ Assert.AreEqual(2, builder._definition.Axis);
+ }
+
+ [Test]
+ public void Builder_WithDisplayType_SetsDisplayType()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetDisplayType(ExtendedDataDisplayType.Area);
+ Assert.AreEqual(ExtendedDataDisplayType.Area, builder._definition.DisplayType);
+ }
+
+ [Test]
+ public void Builder_WithColour_SetsColour()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetColour("123aBC");
+ Assert.AreEqual("123aBC", builder._definition.Colour);
+ }
+
+ [Test]
+ public void Builder_WithNonHexadecimalColour_Throws()
+ {
+ Assert.Throws(() =>
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetColour("abcT12");
+ });
+ }
+
+ public static IEnumerable HexadecimalValidationsTests
+ {
+ get
+ {
+ foreach (char c in "0123456789ABCDEF".ToList())
+ {
+ yield return new TestCaseData(c).Returns(true);
+ }
+ foreach (char c in "GHIJKLMNOPQRSTUVWXYZ.,;\\[]#".ToList())
+ {
+ yield return new TestCaseData(c).Returns(false);
+ }
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(ExtendedDataDefinitionBuilderTests), "HexadecimalValidationsTests")]
+ public bool Builder_HexadecimalValidations_WorksCorrect(char colour)
+ {
+ return ExtendedDataDefinitionBuilder.IsHexadecimalCharacter(colour);
+ }
+
+ [Test]
+ public void Builder_AfterReset_HasNoStateLeft()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetLabel("Test").SetUnit("W");
+ IExtendedDataDefinition status = builder.Build();
+
+ builder.Reset();
+
+ Assert.AreNotSame(status, builder._definition);
+ }
+
+
+ [Test]
+ public void Builder_AfterBuildAndReset_HasNoStateLeft()
+ {
+ var builder = new ExtendedDataDefinitionBuilder().SetLabel("Test").SetUnit("W");
+ IExtendedDataDefinition status = builder.BuildAndReset();
+
+ Assert.AreNotSame(status, builder._definition);
+ }
+ }
+}
diff --git a/tests/PVOutput.Net.Tests/Modules/System/PostSystemRequestTests.cs b/tests/PVOutput.Net.Tests/Modules/System/PostSystemRequestTests.cs
new file mode 100644
index 0000000..44b56c3
--- /dev/null
+++ b/tests/PVOutput.Net.Tests/Modules/System/PostSystemRequestTests.cs
@@ -0,0 +1,151 @@
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using PVOutput.Net.Enums;
+using PVOutput.Net.Objects;
+using PVOutput.Net.Objects.Modules.Implementations;
+using PVOutput.Net.Requests.Modules;
+
+namespace PVOutput.Net.Tests.Modules.System
+{
+ [TestFixture]
+ public class PostSystemRequestTests
+ {
+ private PostSystemRequest CreateRequestWithDefinition(IExtendedDataDefinition definition)
+ {
+ return new PostSystemRequest() { DataDefinitions = new List() { definition } };
+ }
+
+ [Test]
+ public void Parameter_SystemName_CreatesCorrectUriParameters()
+ {
+ var request = new PostSystemRequest() { SystemName = "New name" };
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual("New name", parameters["name"]);
+ }
+
+ [Test]
+ public void Parameter_SystemId_CreatesCorrectUriParameters()
+ {
+ var request = new PostSystemRequest() { SystemId = 54321 };
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(54321, parameters["sid"]);
+ }
+
+ public static IEnumerable DefinitionLabelTests
+ {
+ get
+ {
+ yield return new TestCaseData(ExtendedDataIndex.v7, "New label", "v7l");
+ yield return new TestCaseData(ExtendedDataIndex.v8, "New label", "v8l");
+ yield return new TestCaseData(ExtendedDataIndex.v9, "New label", "v9l");
+ yield return new TestCaseData(ExtendedDataIndex.v10, "New label", "v10l");
+ yield return new TestCaseData(ExtendedDataIndex.v11, "New label", "v11l");
+ yield return new TestCaseData(ExtendedDataIndex.v12, "New label", "v12l");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(PostSystemRequestTests), "DefinitionLabelTests")]
+ public void Parameter_DefinitionLabel_CreatesCorrectUriParameters(ExtendedDataIndex index, string label, string parameterKey)
+ {
+ var request = CreateRequestWithDefinition(new ExtendedDataDefinition() { Index = index, Label = label });
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(label, parameters[parameterKey]);
+ }
+
+ public static IEnumerable DefinitionUnitTests
+ {
+ get
+ {
+ yield return new TestCaseData(ExtendedDataIndex.v7, "Unit", "v7u");
+ yield return new TestCaseData(ExtendedDataIndex.v8, "Unit", "v8u");
+ yield return new TestCaseData(ExtendedDataIndex.v9, "Unit", "v9u");
+ yield return new TestCaseData(ExtendedDataIndex.v10, "Unit", "v10u");
+ yield return new TestCaseData(ExtendedDataIndex.v11, "Unit", "v11u");
+ yield return new TestCaseData(ExtendedDataIndex.v12, "Unit", "v12u");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(PostSystemRequestTests), "DefinitionUnitTests")]
+ public void Parameter_DefinitionUnit_CreatesCorrectUriParameters(ExtendedDataIndex index, string unit, string parameterKey)
+ {
+ var request = CreateRequestWithDefinition(new ExtendedDataDefinition() { Index = index, Unit = unit });
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(unit, parameters[parameterKey]);
+ }
+
+ public static IEnumerable DefinitionAxisTests
+ {
+ get
+ {
+ yield return new TestCaseData(ExtendedDataIndex.v7, 0, "v7a");
+ yield return new TestCaseData(ExtendedDataIndex.v8, 1, "v8a");
+ yield return new TestCaseData(ExtendedDataIndex.v9, 2, "v9a");
+ yield return new TestCaseData(ExtendedDataIndex.v10, 3, "v10a");
+ yield return new TestCaseData(ExtendedDataIndex.v11, 4, "v11a");
+ yield return new TestCaseData(ExtendedDataIndex.v12, 5, "v12a");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(PostSystemRequestTests), "DefinitionAxisTests")]
+ public void Parameter_DefinitionAxis_CreatesCorrectUriParameters(ExtendedDataIndex index, int axis, string parameterKey)
+ {
+ var request = CreateRequestWithDefinition(new ExtendedDataDefinition() { Index = index, Axis = axis});
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(axis, parameters[parameterKey]);
+ }
+
+ public static IEnumerable DefinitionColourTests
+ {
+ get
+ {
+ yield return new TestCaseData(ExtendedDataIndex.v7, "abcdef", "v7c");
+ yield return new TestCaseData(ExtendedDataIndex.v8, "abcdef", "v8c");
+ yield return new TestCaseData(ExtendedDataIndex.v9, "abcdef", "v9c");
+ yield return new TestCaseData(ExtendedDataIndex.v10, "abcdef", "v10c");
+ yield return new TestCaseData(ExtendedDataIndex.v11, "abcdef", "v11c");
+ yield return new TestCaseData(ExtendedDataIndex.v12, "abcdef", "v12c");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(PostSystemRequestTests), "DefinitionColourTests")]
+ public void Parameter_DefinitionColour_CreatesCorrectUriParameters(ExtendedDataIndex index, string colour, string parameterKey)
+ {
+ var request = CreateRequestWithDefinition(new ExtendedDataDefinition() { Index = index, Colour = colour });
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(colour, parameters[parameterKey]);
+ }
+
+ public static IEnumerable DefinitionDisplayTypeTests
+ {
+ get
+ {
+ yield return new TestCaseData(ExtendedDataIndex.v7, ExtendedDataDisplayType.Line, "v7g");
+ yield return new TestCaseData(ExtendedDataIndex.v8, ExtendedDataDisplayType.Line, "v8g");
+ yield return new TestCaseData(ExtendedDataIndex.v9, ExtendedDataDisplayType.Line, "v9g");
+ yield return new TestCaseData(ExtendedDataIndex.v10, ExtendedDataDisplayType.Line, "v10g");
+ yield return new TestCaseData(ExtendedDataIndex.v11, ExtendedDataDisplayType.Line, "v11g");
+ yield return new TestCaseData(ExtendedDataIndex.v12, ExtendedDataDisplayType.Line, "v12g");
+ yield return new TestCaseData(ExtendedDataIndex.v7, ExtendedDataDisplayType.Area, "v7g");
+ yield return new TestCaseData(ExtendedDataIndex.v8, ExtendedDataDisplayType.Area, "v8g");
+ yield return new TestCaseData(ExtendedDataIndex.v9, ExtendedDataDisplayType.Area, "v9g");
+ yield return new TestCaseData(ExtendedDataIndex.v10, ExtendedDataDisplayType.Area, "v10g");
+ yield return new TestCaseData(ExtendedDataIndex.v11, ExtendedDataDisplayType.Area, "v11g");
+ yield return new TestCaseData(ExtendedDataIndex.v12, ExtendedDataDisplayType.Area, "v12g");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(typeof(PostSystemRequestTests), "DefinitionDisplayTypeTests")]
+ public void Parameter_DefinitionDisplayType_CreatesCorrectUriParameters(ExtendedDataIndex index, ExtendedDataDisplayType displayType, string parameterKey)
+ {
+ var request = CreateRequestWithDefinition(new ExtendedDataDefinition() { Index = index, DisplayType = displayType });
+ var parameters = request.GetUriPathParameters();
+ Assert.AreEqual(displayType.ToString(), parameters[parameterKey]);
+ }
+ }
+}
diff --git a/tests/PVOutput.Net.Tests/Modules/System/SystemServiceTests.cs b/tests/PVOutput.Net.Tests/Modules/System/SystemServiceTests.cs
index dbe43fb..bb34157 100644
--- a/tests/PVOutput.Net.Tests/Modules/System/SystemServiceTests.cs
+++ b/tests/PVOutput.Net.Tests/Modules/System/SystemServiceTests.cs
@@ -6,6 +6,8 @@
using PVOutput.Net.Objects;
using PVOutput.Net.Tests.Utils;
using RichardSzalay.MockHttp;
+using PVOutput.Net.Objects.Modules.Implementations;
+using System.Collections.Generic;
namespace PVOutput.Net.Tests.Modules.System
{
@@ -39,6 +41,20 @@ public async Task SystemService_GetOtherSystem_CallsCorrectUri()
AssertStandardResponse(response);
}
+ [Test]
+ public async Task SystemService_PostSystem_CallsCorrectUri()
+ {
+ PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider);
+
+ testProvider.ExpectUriFromBase(POSTSYSTEM_URL)
+ .WithExactQueryString("sid=54321&name=New%20name&v7l=New%20power&v7u=W")
+ .RespondPlainText("");
+
+ var response = await client.System.PostSystem(54321, "New name", new List() { new ExtendedDataDefinition() { Label = "New power", Unit = "W" } });
+ testProvider.VerifyNoOutstandingExpectation();
+ AssertStandardResponse(response);
+ }
+
/*
* Deserialisation tests below
*/
diff --git a/tests/PVOutput.Net.Tests/Modules/System/SystemSystemTestsData.cs b/tests/PVOutput.Net.Tests/Modules/System/SystemSystemTestsData.cs
index e627f0a..e05c337 100644
--- a/tests/PVOutput.Net.Tests/Modules/System/SystemSystemTestsData.cs
+++ b/tests/PVOutput.Net.Tests/Modules/System/SystemSystemTestsData.cs
@@ -3,6 +3,8 @@
public partial class SystemServiceTests
{
public const string GETSYSTEM_URL = "getsystem.jsp";
+
+ public const string POSTSYSTEM_URL = "postsystem.jsp";
public const string SYSTEM_RESPONSE_SIMPLE = "Test System,4125,1234,15,275,JA Solar mono,1,5500,Fronius Primo 3.6-1,E,53.0,No,20161001,51.0,0.0,5;;0";