public async Task Response_WithApiRateInformation_ParsesCorrectInformation() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); var resetTimeStamp = new DateTime(2020, 3, 15, 11, 20, 0); var offset = (DateTimeOffset)DateTime.SpecifyKind(resetTimeStamp, DateTimeKind.Utc); var responseHeaders = new Dictionary <string, string>() { { "X-Rate-Limit-Remaining", "156" }, { "X-Rate-Limit-Limit", "300" }, { "X-Rate-Limit-Reset", offset.ToUnixTimeSeconds().ToString() } }; testProvider.ExpectUriFromBase("getsystem.jsp") .Respond(responseHeaders, "text/plain", ""); var response = await client.System.GetOwnSystemAsync(); testProvider.VerifyNoOutstandingExpectation(); Assert.Multiple(() => { Assert.That(response.ApiRateInformation.LimitRemaining, Is.EqualTo(156)); Assert.That(response.ApiRateInformation.CurrentLimit, Is.EqualTo(300)); Assert.That(response.ApiRateInformation.LimitResetAt, Is.EqualTo(resetTimeStamp)); }); }
public void StatisticsService_GetStatisticsForPeriod_WithReversedRange_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Statistics.GetStatisticsForPeriodAsync(new DateTime(2016, 8, 30), new DateTime(2016, 8, 29)); }); }
public void OutputService_AddOutput_WithNullOutput_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentNullException>(async() => { _ = await client.Output.AddOutputAsync(null); }); }
public void OutputService_GetTeamOutputForDate_WithFutureDate_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Output.GetTeamOutputForDateAsync(DateTime.Today.AddDays(1), 1234); }); }
public void StatusService_DeleteStatus_WithDateOutsideBounds_Throws(DateTime testDate) { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Status.DeleteStatusAsync(testDate); }); }
public void ExtendedService_GetExtendedDataForPeriod_WithReversedRange_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Extended.GetExtendedDataForPeriodAsync(new DateTime(2016, 3, 7), new DateTime(2016, 3, 6)); }); }
public void OutputService_AddBatchOutput_WithEmptyOutputs_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentException>(async() => { _ = await client.Output.AddBatchOutputAsync(new List <IBatchOutputPost>()); }); }
public void ExtendedService_GetExtendedDataForPeriod_WithLimitThatIsTooHigh_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Extended.GetExtendedDataForPeriodAsync(DateTime.Today.AddDays(-1), DateTime.Today, 100); }); }
public void SearchService_Search_WithEmptyQuery_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentException>(async() => { _ = await client.Search.SearchAsync(""); }); }
public void StatusService_AddBatchNetStatus_WithEmptyStatuses_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentException>(async() => { _ = await client.Status.AddBatchNetStatusAsync(new List <IBatchNetStatusPost>()); }); }
public void StatusService_AddBatchStatus_WithNullStatuses_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentNullException>(async() => { _ = await client.Status.AddBatchStatusAsync(null); }); }
public void StatusService_GetDayStatisticsForPeriod_WithFutureRange_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Status.GetDayStatisticsForPeriodAsync(DateTime.Today, DateTime.Today.AddDays(1)); }); }
public void OutputService_GetAggregatedOutputs_WithReversedRange_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Output.GetAggregatedOutputsAsync(new DateTime(2016, 8, 30), new DateTime(2016, 8, 29), AggregationPeriod.Month); }); }
public void OutputService_GetAggregatedOutputs_WithFutureRange_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { _ = await client.Output.GetAggregatedOutputsAsync(DateTime.Today, DateTime.Today.AddDays(1), AggregationPeriod.Month); }); }
public static PVOutputClient GetMockClient(out MockHttpMessageHandler mockHandler) { var provider = new TestHttpClientProvider(); mockHandler = provider.MockHttpMessageHandler; mockHandler.Fallback.RespondPlainText(""); var client = new PVOutputClient(TestConstants.PVOUTPUT_API_KEY, TestConstants.PVOUTPUT_SYSTEM_ID, new TestOutputLogger()); client.HttpClientProvider = provider; return(client); }
public void Create_ClientWithLogger_CreatesClientWithLogger() { var loggerSubstitute = Substitute.For <ILogger <PVOutputClient> >(); var client = new PVOutputClient("apikey", 1234, loggerSubstitute); Assert.Multiple(() => { Assert.That(client.ApiKey, Is.EqualTo("apikey")); Assert.That(client.OwnedSystemId, Is.EqualTo(1234)); Assert.That(client.Logger, Is.Not.EqualTo(NullLogger <PVOutputClient> .Instance)); }); }
public async Task SearchService_WithQuery_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(SEARCH_URL) .RespondPlainText(""); var response = await client.Search.SearchAsync("test query"); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task StatisticsService_GetLifetimeStatistics_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETSTATISTIC_URL) .RespondPlainText(STATISTIC_RESPONSE_SIMPLE); var response = await client.Statistics.GetLifetimeStatisticsAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task FavouriteService_GetSingle() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETFAVOURITE_URL) .RespondPlainText(FAVOURITE_RESPONSE_SINGLE); PVOutputArrayResponse <IFavourite> response = await client.Favourite.GetFavouritesAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task ExtendedService_GetRecent_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETEXTENDED_URL) .RespondPlainText(EXTENDED_RESPONSE_RECENT); var response = await client.Extended.GetRecentExtendedDataAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task OutputService_AddOutput_CallsCorrectUri(IOutputPost outputToPost, string expectedQueryString) { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(ADDOUTPUT_URL) .WithQueryString(expectedQueryString) .RespondPlainText(""); await client.Output.AddOutputAsync(outputToPost); testProvider.VerifyNoOutstandingExpectation(); }
public async Task InsolationService_GetForOwnSystem_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETINSOLATION_URL) .RespondPlainText(INSOLATION_RESPONSE_BASIC); var response = await client.Insolation.GetInsolationForOwnSystemAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public void Create_ClientWithValidParameters_CreatesCorrectClient() { var client = new PVOutputClient("apikey", 1234); Assert.Multiple(() => { Assert.That(client.ApiKey, Is.EqualTo("apikey")); Assert.That(client.OwnedSystemId, Is.EqualTo(1234)); Assert.That(client.Logger, Is.EqualTo(NullLogger <PVOutputClient> .Instance)); Assert.That(client.HttpClientProvider, Is.Not.Null); }); }
public async Task SupplyService_WithNoParameters_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETSUPPLY_URL) .RespondPlainText(""); var response = await client.Supply.GetSupplyAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task SystemService_GetOwnSystem_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETSYSTEM_URL) .RespondPlainText(SYSTEM_RESPONSE_EXTENDED); PVOutputResponse <ISystem> response = await client.System.GetOwnSystemAsync(); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public void CallbackUrl_TooLong_Throws() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(REGISTERNOTIFICATION_URL) .RespondPlainText(""); var exception = Assert.ThrowsAsync <ArgumentException>(async() => { _ = await client.Notification.RegisterNotificationAsync("my.application.id", new string('*', 151)); }); }
public async Task NotificationService_RegisterNotificationViaUri_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(REGISTERNOTIFICATION_URL) .WithQueryString("appid=my.application.id&type=17&url=http://www.microsoft.com/callmeback") .RespondPlainText(""); var response = await client.Notification.RegisterNotificationAsync("my.application.id", new Uri("http://www.microsoft.com/callmeback"), 17); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task NotificationService_DeregisterNotification_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(DEREGISTERNOTIFICATION_URL) .WithQueryString("appid=my.application.id&type=24") .RespondPlainText(""); var response = await client.Notification.DeregisterNotificationAsync("my.application.id", 24); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task TeamService_GetStatusForTeam_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETTEAM_URL) .WithQueryString("tid=350") .RespondPlainText(TEAM_RESPONSE_SIMPLE); var response = await client.Team.GetTeamAsync(350); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }
public async Task InsolationService_GetForLocation_CallsCorrectUri() { PVOutputClient client = TestUtility.GetMockClient(out MockHttpMessageHandler testProvider); testProvider.ExpectUriFromBase(GETINSOLATION_URL) .WithQueryString("ll=-84.623970,42.728820") .RespondPlainText(INSOLATION_RESPONSE_BASIC); var response = await client.Insolation.GetInsolationForLocationAsync(new PVCoordinate(-84.62397m, 42.72882m)); testProvider.VerifyNoOutstandingExpectation(); AssertStandardResponse(response); }