public void Test_Create_Parameters_Success()
        {
            var parameters = new Dictionary <string, object>();

            parameters.Add("foo", "bar");

            var responseEntity = new TestEntity {
                Value = "Foo"
            };

            var uri = new Uri("http://localhost:9191/create");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Post("/create")).Return(JsonConvert.SerializeObject(responseEntity)).Ok();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeCreateRequest <TestEntity>(uri, parameters);

            httpMock.AssertWasCalled(x => x.Post("/create"));
            Assert.That(response.IsSuccess, Is.True);
            Assert.That(response.IsError, Is.False);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.ContainsData, Is.True);
            Assert.That(response.Data.Value, Is.EqualTo(responseEntity.Value));
        }
        public void Test_Update_Entity_Success()
        {
            var entity = new TestEntity {
                Value = "Bar"
            };
            var responseEntity = new TestEntity {
                Value = "Foo"
            };

            var uri = new Uri("http://localhost:9191/update");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Put("/update")).Return(JsonConvert.SerializeObject(responseEntity)).Ok();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeUpdateRequest <TestEntity>(uri, entity);

            httpMock.AssertWasCalled(x => x.Put("/update"));
            Assert.That(response.IsSuccess, Is.True);
            Assert.That(response.IsError, Is.False);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.ContainsData, Is.True);
            Assert.That(response.Data.Value, Is.EqualTo(responseEntity.Value));
        }
Beispiel #3
0
        private SoundCloudClient()
        {
            var gateway = new SoundCloudApiGateway();

            _comments  = new Comments(gateway);
            _oAuth2    = new OAuth2(gateway);
            _playlists = new Playlists(gateway);
            _tracks    = new Tracks(gateway);
            _users     = new Users(gateway);
            _groups    = new Groups(gateway);
            _me        = new Me(gateway);
            _apps      = new Apps(gateway);
            _resolve   = new Resolve(gateway);
        }
Beispiel #4
0
        public SoundCloudClient(IHttpClientFactory httpClientFactory, SoundCloudAuthInfo authInfo)
        {
            AuthInfo = authInfo;

            var gateway = new SoundCloudApiGateway(httpClientFactory);

            Apps      = new Apps(gateway);
            Comments  = new Comments(gateway);
            OAuth2    = new OAuth2(gateway);
            Playlists = new Playlists(gateway);
            Tracks    = new Tracks(gateway);
            Users     = new Users(gateway);
            Me        = new Me(gateway);
            Resolve   = new Resolve(gateway);
        }
        public void Test_Update_Fail()
        {
            var uri = new Uri("http://localhost:9191/update");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Put("/update")).NotFound();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeUpdateRequest <TestEntity>(uri);

            httpMock.AssertWasCalled(x => x.Put("/update"));
            Assert.That(response.IsSuccess, Is.False);
            Assert.That(response.IsError, Is.True);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
            Assert.That(response.ContainsData, Is.False);
            Assert.That(response.Data, Is.Null);
        }
        public void Test_Get_Deserialization_Failed()
        {
            var uri = new Uri("http://localhost:9191/get");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Get("/get")).Return("{ { }").Ok();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeGetRequest <TestEntity>(uri);

            httpMock.AssertWasCalled(x => x.Get("/get"));
            Assert.That(response.IsSuccess, Is.True);
            Assert.That(response.IsError, Is.False);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.ContainsData, Is.False);
            Assert.That(response.Data, Is.Null);
        }
        public void Test_Delete_Success()
        {
            var status = new Status {
                Message = "200 - OK"
            };
            var uri = new Uri("http://localhost:9191/delete");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Delete("/delete")).Return(JsonConvert.SerializeObject(status)).Ok();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeDeleteRequest <Status>(uri);

            Assert.That(response.IsSuccess, Is.True);
            Assert.That(response.IsError, Is.False);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.ContainsData, Is.True);
            Assert.That(response.Data.Message, Is.EqualTo(status.Message));
        }
        public void Test_Create_Parameters_Fail()
        {
            var parameters = new Dictionary <string, object>();

            parameters.Add("foo", "bar");

            var uri = new Uri("http://localhost:9191/create");

            var httpMock = HttpMockRepository.At("http://localhost:9191");

            httpMock.Stub(x => x.Post("/create")).NotFound();

            var gateway  = new SoundCloudApiGateway();
            var response = gateway.InvokeCreateRequest <TestEntity>(uri, parameters);

            httpMock.AssertWasCalled(x => x.Post("/create"));
            Assert.That(response.IsSuccess, Is.False);
            Assert.That(response.IsError, Is.True);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
            Assert.That(response.ContainsData, Is.False);
            Assert.That(response.Data, Is.Null);
        }