public void Initialise_ValidCredenitalsExpiredApiToken_ShouldSetClientAuthenticator() { // Setup var source = new Source { Name = "Ents24", BaseUrl = "https://api.ents24.com", ClientId = "9cf2fed5cfbf039aecd0f50b83218ab59fefc68d", ClientSecret = "599c661ed7d3c99cd7d2d98d0a23361d68227720", ApiToken = "CurrentToken", TokenExpiryDate = DateTime.Now.AddDays(-1) }; var mockResponse = ValidRestResponse(); _mockRestClient.Setup(c => c.Execute <AuthorisationResponse>(It.IsAny <RestRequest>())).Returns(mockResponse.Object); // Perform var ents24Client = new Ents24Client(source, _mockSourceRepository.Object, _mockRestClient.Object); // Verify Assert.NotNull(ents24Client); _mockRestClient.VerifySet(c => c.BaseUrl = It.Is <Uri>(a => a == new Uri(source.BaseUrl))); _mockSourceRepository.Verify(r => r.UpdateById(It.IsAny <string>(), source), Times.Once); Assert.AreEqual(DateTime.Now.AddDays(60).ToShortDateString(), source.TokenExpiryDate.ToShortDateString()); }
public void Initialise_ValidCredenitalsNoApiToken_ShouldGetApiToken() { // Setup var source = new Source { Name = "Ents24", BaseUrl = "https://api.ents24.com", ClientId = "9cf2fed5cfbf039aecd0f50b83218ab59fefc68d", ClientSecret = "599c661ed7d3c99cd7d2d98d0a23361d68227720" }; var mockResponse = ValidRestResponse(); _mockRestClient.Setup(c => c.Execute <AuthorisationResponse>(It.IsAny <RestRequest>())).Returns(mockResponse.Object); _mockRestClient.Setup(c => c.AddDefaultHeader("Authorization", It.IsAny <string>())); // Perform var ents24Client = new Ents24Client(source, _mockSourceRepository.Object, _mockRestClient.Object); // Verify Assert.NotNull(ents24Client); _mockRestClient.VerifySet(c => c.BaseUrl = It.Is <Uri>(a => a == new Uri(source.BaseUrl))); _mockRestClient.Verify(c => c.AddDefaultHeader("Authorization", It.IsAny <string>()), Times.Once); // mockResponse.VerifySet(r => r.Headers = It.Is<List<Parameter>>(a => a.Contains(new Parameter("Authorization", It.IsAny<string>(), ParameterType.HttpHeader)))); _mockSourceRepository.Verify(r => r.UpdateById(It.IsAny <string> (), source), Times.Once); Assert.AreEqual(DateTime.Now.AddDays(60).ToShortDateString(), source.TokenExpiryDate.ToShortDateString()); }
public void GigsForArtist_ArtistWithGigs_ShouldReturnListOfGigs() { var source = new Source { Name = "Ents24", BaseUrl = "https://api.ents24.com", ClientId = "9cf2fed5cfbf039aecd0f50b83218ab59fefc68d", ClientSecret = "599c661ed7d3c99cd7d2d98d0a23361d68227720" }; var ents24Client = new Ents24Client(source, _mockSourceRepository.Object, new RestClientWrapper(new RestClient())); var gigs = ents24Client.GigsForArtist("tool"); Assert.NotNull(gigs); Assert.AreEqual(3, gigs.Count); }
public void Initialise_ValidCredenitalsCurrentApiToken_ShouldSetClientAuthenticator() { // Setup var source = new Source { Name = "Ents24", BaseUrl = "https://api.ents24.com", ClientId = "9cf2fed5cfbf039aecd0f50b83218ab59fefc68d", ClientSecret = "599c661ed7d3c99cd7d2d98d0a23361d68227720", ApiToken = "CurrentToken", TokenExpiryDate = DateTime.Now.AddDays(30) }; // Perform var ents24Client = new Ents24Client(source, _mockSourceRepository.Object, _mockRestClient.Object); // Verify Assert.NotNull(ents24Client); _mockRestClient.VerifySet(c => c.BaseUrl = It.Is <Uri>(a => a == new Uri(source.BaseUrl))); _mockSourceRepository.Verify(r => r.UpdateById(It.IsAny <string>(), source), Times.Never); }
public void Initialise_CurrentApiKeyDontPassInSourceRepository_ShouldSetClientAuthenticator() { // Setup var source = new Source { Name = "Ents24", BaseUrl = "https://api.ents24.com", ClientId = "9cf2fed5cfbf039aecd0f50b83218ab59fefc68d", ClientSecret = "599c661ed7d3c99cd7d2d98d0a23361d68227720", ApiToken = "CurrentToken", TokenExpiryDate = DateTime.Now.AddDays(30) }; // Perform var ents24Client = new Ents24Client(source, _mockRestClient.Object); // Verify Assert.NotNull(ents24Client); _mockRestClient.VerifySet(c => c.BaseUrl = It.Is <Uri>(a => a == new Uri(source.BaseUrl))); _mockRestClient.Verify(c => c.Execute <AuthorisationResponse>(It.IsAny <RestRequest>()), Times.Never); }