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

            var testEntity = new TestEntity();

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

            response.Data = testEntity;

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

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

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

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

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

            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"));
        }
예제 #2
0
        public void Test_Create_Entity_Success_No_Data()
        {
            const string expectedUri = @"https://test.com/create";

            var testEntity = new TestEntity();

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

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

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

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

            Assert.That(result, Is.InstanceOf <SuccessWebResult <TestEntity> >());
            Assert.That(result.IsSuccess, Is.True);
            Assert.That(result.Data, Is.Null);
            Assert.That(result.ErrorMessage, Is.EqualTo(string.Empty));
        }