public void Init() { _settings = Options.Create(new LmiSettings() { ApiUrl = "http://thisisarealuri.com" }); var cachedLmiDataModel = new CachedLmiData { SocCode = 2815.ToString(), JobGrowth = JobGrowth.Increasing, DateWritten = DateTimeOffset.Now }; var cachedLmiData = new StringContent(JsonConvert.SerializeObject(cachedLmiDataModel)); var mockHandler = LmiHelpers.GetMockMessageHandler(LmiHelpers.SuccessfulLmiCall()); _restClient = new RestClient(mockHandler.Object); _cosmosService = Substitute.For <ICosmosService>(); _cosmosService.ReadItemAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = cachedLmiData }); _cosmosService.CreateItemAsync(Arg.Any <object>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage(HttpStatusCode.OK)); _cosmosService.UpsertItemAsync(Arg.Any <object>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage(HttpStatusCode.OK)); }
public void Init() { _cosmosSettings = Options.Create(new CosmosSettings() { ApiUrl = "https://test-account-not-real.documents.azure.com:443/", ApiKey = "VGhpcyBpcyBteSB0ZXN0", DatabaseName = "DatabaseName", UserSessionsCollection = "UserSessions", LmiDataCollection = "LmiData" }); var cachedLmiDataModel = new CachedLmiData { SocCode = 2815.ToString(), JobGrowth = JobGrowth.Increasing, DateWritten = DateTimeOffset.Now }; var cachedLmiData = new StringContent(JsonConvert.SerializeObject(cachedLmiDataModel)); _service = Substitute.For <ICosmosService>(); _service.ReadItemAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = cachedLmiData }); _service.CreateItemAsync(Arg.Any <object>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage(HttpStatusCode.OK)); _service.UpsertItemAsync(Arg.Any <object>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage(HttpStatusCode.OK)); }
public void WhenLmiDataCached_ReturnCachedData() { _restClient = new RestClient(); var matches = new List <OccupationMatch> { new OccupationMatch { SocCode = 2815 } }; var date = DateTimeOffset.Now.Subtract(new TimeSpan(-1, -1, -1)); var cachedLmiDataModel = new CachedLmiData { SocCode = 2815.ToString(), JobGrowth = JobGrowth.Increasing, DateWritten = date, }; _cosmosService.ReadItemAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <CosmosCollection>()) .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(cachedLmiDataModel)) }); var serviceUnderTest = new LmiService(_restClient, _settings, _cosmosService); var result = serviceUnderTest.GetPredictionsForGetOccupationMatches(matches); result[0].SocCode.Should().Be(2815); result[0].JobGrowth.Should().Be(JobGrowth.Increasing); }
internal async Task <HttpResponseMessage> CacheLmiData(int socCode, JobGrowth jobGrowth) { var cachedLmiData = new CachedLmiData { SocCode = socCode.ToString(), JobGrowth = jobGrowth, DateWritten = DateTimeOffset.Now }; return(await _cosmosService.UpsertItemAsync(cachedLmiData, CosmosCollection.LmiData)); }