예제 #1
0
        public void Test_Update_Fail()
        {
            const string expectedUri = @"https://test.com/update";

            var status = new StatusResponse();

            status.Error = "FooError";
            status.Errors.Add(new ErrorMessage {
                error_message = "BarError"
            });

            var response = new ApiResponse <StatusResponse>(HttpStatusCode.NotFound, "Not Found");

            response.Data = status;

            var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict);

            gatewayMock.Setup(x => x.InvokeUpdateRequest <StatusResponse>(It.Is <Uri>(y => y.ToString() == expectedUri))).Returns(response);

            var endpoint = new TestEndpoint(gatewayMock.Object);
            var result   = endpoint.Update(expectedUri);

            Assert.That(result, Is.InstanceOf <ErrorWebResult <object> >());
            Assert.That(result.IsSuccess, Is.False);
            Assert.That(result.ErrorMessage, Is.EqualTo("FooError\r\nBarError"));
        }
예제 #2
0
        public void Test_Update_Params_Success()
        {
            const string expectedUri = @"https://test.com/update";

            var testEntity = new TestEntity();

            var response = new ApiResponse <TestEntity>(HttpStatusCode.OK, "OK");

            response.Data = testEntity;

            var parameters = new Dictionary <string, object>();

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

            var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict);

            gatewayMock.Setup(x => x.InvokeUpdateRequest <TestEntity>(It.Is <Uri>(y => y.ToString() == expectedUri), parameters)).Returns(response);

            var endpoint = new TestEndpoint(gatewayMock.Object);
            var result   = endpoint.Update <TestEntity>(expectedUri, parameters);

            Assert.That(result, Is.InstanceOf <SuccessWebResult <TestEntity> >());
            Assert.That(result.IsSuccess, Is.True);
            Assert.That(result.Data, Is.EqualTo(testEntity));
            Assert.That(result.ErrorMessage, Is.EqualTo(string.Empty));
        }
예제 #3
0
        public void Test_Update_Success()
        {
            const string expectedUri = @"https://test.com/update";

            var response = new ApiResponse <StatusResponse>(HttpStatusCode.OK, "OK");

            var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict);

            gatewayMock.Setup(x => x.InvokeUpdateRequest <StatusResponse>(It.Is <Uri>(y => y.ToString() == expectedUri))).Returns(response);

            var endpoint = new TestEndpoint(gatewayMock.Object);
            var result   = endpoint.Update(expectedUri);

            Assert.That(result, Is.InstanceOf <SuccessWebResult <object> >());
            Assert.That(result.IsSuccess, Is.True);
            Assert.That(result.ErrorMessage, Is.EqualTo(string.Empty));
        }
예제 #4
0
        public void Test_Update_Entity_Fail()
        {
            const string expectedUri = @"https://test.com/update";

            var testEntity = new TestEntity();

            var response = new ApiResponse <TestEntity>(HttpStatusCode.NotFound, "Not Found");

            response.Data = testEntity;

            var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict);

            gatewayMock.Setup(x => x.InvokeUpdateRequest <TestEntity>(It.Is <Uri>(y => y.ToString() == expectedUri), testEntity)).Returns(response);

            var endpoint = new TestEndpoint(gatewayMock.Object);
            var result   = endpoint.Update <TestEntity>(expectedUri, testEntity);

            Assert.That(result, Is.InstanceOf <ErrorWebResult <TestEntity> >());
            Assert.That(result.IsSuccess, Is.False);
            Assert.That(result.Data, Is.Null);
            Assert.That(result.ErrorMessage, Is.EqualTo("Not Found"));
        }