public void DeleteTimeSeries_IsForwarded() { string identity = "mockid", datasetName = "mydataset"; var timeSeries = GetTimeSeries(180); IForecastingApi api; var mocks = new MockRepository(); using (mocks.Record()) { api = mocks.StrictMock<IForecastingApi>(); Expect.Call(api.DeleteTimeSeries(identity, datasetName, null)) .Return(string.Empty) .IgnoreArguments() .Repeat.Twice(); // 180 time-series => two requests } using (mocks.Playback()) { var client = new ForecastingClient(identity, api); client.DeleteTimeSeries(datasetName, timeSeries.Select(d => d.Name).ToArray()); } }
public void DeleteDatasets_IsForwarded() { string identity = "mockid"; var dataset = GetDataset(); IForecastingApi api; var mocks = new MockRepository(); using (mocks.Record()) { api = mocks.StrictMock<IForecastingApi>(); Expect.Call(api.DeleteDataset(identity, dataset.Name)) .Return(string.Empty); } using (mocks.Playback()) { var client = new ForecastingClient(identity, api); client.DeleteDataset(dataset.Name); } }
public void Data_round_trip() { // insert test dataset var dataset = new Dataset { Name = "SDKIntTest" + DateTime.Now.ToString("yyyyMMddHHmmssfffff"), Horizon = 60, Period = PeriodCodes.Week }; _forecastingApi.InsertDataset(Identity, dataset); var timeseries = GetTimeSeries(100); var errorCode = _forecastingApi.UpsertTimeSeries(Identity, dataset.Name, timeseries, true); Assert.IsEmpty(errorCode); var client = new ForecastingClient(Identity, _forecastingApi); var data = client.ListTimeSeries(dataset.Name); var loaded = data.ToDictionary(s => s.Name); foreach (var exp in timeseries) { var actual = loaded[exp.Name]; CollectionAssert.AreEquivalent(exp.Tags, actual.Tags, "Tags equal for {0}", exp.Name); CollectionAssert.AreEqual(exp.Values.Select(s => s.ToString()).ToArray(), actual.Values.Select(s => s.ToString()).ToArray(), "Values are equal"); CollectionAssert.AreEqual(exp.Events.Select(s => s.ToString()).ToArray(), actual.Events.Select(s => s.ToString()).ToArray(), "Events are equal"); Assert.AreEqual(exp.Tau, actual.Tau); Assert.AreEqual(exp.Lambda, actual.Lambda); } _forecastingApi.DeleteDataset(Identity, dataset.Name); }
public void GetForecasts_IsForwarded() { string identity = "mockid", datasetName = "mydataset"; var timeSeries = GetTimeSeries(180); IForecastingApi api; var mocks = new MockRepository(); using (mocks.Record()) { api = mocks.StrictMock<IForecastingApi>(); Expect.Call(api.GetForecastStatus(identity, datasetName)) .Return(new ForecastStatus { ForecastsReady = true }); // 180 time-series => 4 requests Expect.Call(api.GetForecasts(identity, datasetName, null)) .Return(new ForecastCollection { Series = new[] { new ForecastSerie { Name = timeSeries[0].Name } } }) .IgnoreArguments(); Expect.Call(api.GetForecasts(identity, datasetName, null)) .Return(new ForecastCollection { Series = new[] { new ForecastSerie { Name = timeSeries[1].Name } } }) .IgnoreArguments(); Expect.Call(api.GetForecasts(identity, datasetName, null)) .Return(new ForecastCollection { Series = new[] { new ForecastSerie { Name = timeSeries[2].Name } } }) .IgnoreArguments(); Expect.Call(api.GetForecasts(identity, datasetName, null)) .Return(new ForecastCollection { Series = new[] { new ForecastSerie { Name = timeSeries[3].Name } } }) .IgnoreArguments(); } using (mocks.Playback()) { var client = new ForecastingClient(identity, api); var forecasts = client.GetForecasts(datasetName, timeSeries.Select(d => d.Name).ToArray()); Assert.IsNotNull(forecasts, "#A00"); Assert.AreEqual(4, forecasts.Length, "#A01"); Assert.AreEqual(timeSeries[0].Name, forecasts[0].Name, "#A02"); Assert.AreEqual(timeSeries[1].Name, forecasts[1].Name, "#A03"); Assert.AreEqual(timeSeries[2].Name, forecasts[2].Name, "#A04"); Assert.AreEqual(timeSeries[3].Name, forecasts[3].Name, "#A05"); } }
public void UpsertTimeSeries_IsForwarded() { string identity = "mockid"; var timeSeries = GetTimeSeries(180); IForecastingApi api; var mocks = new MockRepository(); using (mocks.Record()) { api = mocks.StrictMock<IForecastingApi>(); Expect.Call(api.UpsertTimeSeries(identity, null, null, false)) .Return(string.Empty) .IgnoreArguments() .Repeat.Twice(); // 180 series => two requests } using (mocks.Playback()) { var client = new ForecastingClient(identity, api); client.UpsertTimeSeries("mockdataset", timeSeries, false); } }
public void ListTimeSeries_IsForwarded() { string identity = "mockid", token = "mytoken", datasetName = "mydataset"; IForecastingApi api; var mocks = new MockRepository(); using (mocks.Record()) { api = mocks.StrictMock<IForecastingApi>(); Expect.Call(api.ListTimeSeries(identity, datasetName, null)) .Return(new TimeSerieCollection { TimeSeries = new TimeSerie[0], ContinuationToken = token }); // 2nd call comes with continuation token Expect.Call(api.ListTimeSeries(identity, datasetName, token)) .Return(new TimeSerieCollection { TimeSeries = new TimeSerie[0], ContinuationToken = null }); } using (mocks.Playback()) { var client = new ForecastingClient(identity, api); var result = client.ListTimeSeries(datasetName); Assert.AreEqual(0, result.Count(), "#A00"); } }