コード例 #1
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_executing_if_its_OK_there_is_no_error()
        {
            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Return(new RestResponse() { StatusCode = HttpStatusCode.OK });
            ICallResponseValidation validation = MockRepository.GenerateMock<ICallResponseValidation>();
            validation.Stub(x => x.Execute(Arg<IRestResponse>.Is.Anything)).Return(false);
            Call call = new Call(client) { Url = "http://google.com", Validation = validation};
               var response = call.Execute();

            Assert.That(response.Message, Is.Null);
        }
コード例 #2
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_Executing_if_there_is_an_exception_then_return_exception_message()
        {
            const string errorMessage = "error message";

            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Throw(new Exception(errorMessage));
            Call call = new Call(client) { Url = "http://google.com", Validation = new HttpStatusCodeIsOK() };

            var response = call.Execute();

            Assert.That(response.Message,Is.EqualTo(errorMessage));
        }
コード例 #3
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_Executing_if_its_response_OK_then_return_OK()
        {
            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Return(new RestResponse() { StatusCode = HttpStatusCode.OK} );
            ICallResponseValidation validation = MockRepository.GenerateMock<ICallResponseValidation>();
            validation.Stub(x => x.Execute(Arg<IRestResponse>.Is.Anything)).Return(true);
            Call call = new Call(client) { Url = "http://google.com", Validation = validation };

            var response = call.Execute();

            Assert.That(response.Status, Is.EqualTo(CallStatus.OK));
            client.AssertWasCalled(x => x.Execute(Arg<IRestRequest>.Is.Anything));
        }
コード例 #4
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_executing_if_its_not_OK_there_is_error()
        {
            const string errormessage = "errorMessage";

            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Return(new RestResponse());
            ICallResponseValidation validation = MockRepository.GenerateMock<ICallResponseValidation>();
            validation.Stub(x => x.Execute(Arg<IRestResponse>.Is.Anything)).Return(false);
            validation.Stub(x => x.Message).Return(errormessage);
            Call call = new Call(client) {Url = "http://google.com", Validation = validation};

            var response = call.Execute();

            Assert.That(response.Message, Is.EqualTo(errormessage));
        }
コード例 #5
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_Executing_if_there_is_no_exception_but_not_OK_then_fail()
        {
            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Return(new RestResponse());
            ICallResponseValidation validation = MockRepository.GenerateMock<ICallResponseValidation>();
            validation.Stub(x => x.Execute(Arg<IRestResponse>.Is.Anything)).Return(false);
            Call call = new Call(client) { Url = "http://google.com", Validation = validation};

            var response = call.Execute();

            Assert.That(response.Status, Is.EqualTo(CallStatus.Failed));
            client.AssertWasCalled(x => x.Execute(Arg<IRestRequest>.Is.Anything));
        }
コード例 #6
0
ファイル: CallTests.cs プロジェクト: goncalopereira/smokey
        public void When_Executing_if_there_is_an_exception_then_return_failed()
        {
            IRestClient client = MockRepository.GenerateMock<IRestClient>();
            client.Stub(x => x.Execute(Arg<IRestRequest>.Is.Anything)).Throw(new Exception());
            Call call = new Call(client) { Url = "http://google.com"};

            var response = call.Execute();

            Assert.That(response.Status, Is.EqualTo(CallStatus.Failed));
            client.AssertWasCalled(x => x.Execute(Arg<IRestRequest>.Is.Anything));
        }