示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }