コード例 #1
0
        public async Task TestGetCustomer()
        {
            // Parameters for the API call
            string customerIdentifier = "sdkautotest1";

            // Perform API call
            Raas.Models.CustomerModel result = null;

            try
            {
                result = await controller.GetCustomerAsync(customerIdentifier);
            }
            catch (APIException) {};

            // Test response code
            Assert.AreEqual(200, httpCallBackHandler.Response.StatusCode,
                            "Status should be 200");

            // Test whether the captured response is as we expected
            Assert.IsNotNull(result, "Result should exist");

            Assert.IsTrue(TestHelper.IsJsonObjectProperSubsetOf(
                              "{\n  \"customerIdentifier\": \"sdkautotest1\",\n  \"displayName\": \"SDK Auto Testing 1\",\n  \"status\": \"active\",\n  \"createdAt\": \"2018-04-26T18:13:12.874Z\",\n  \"accounts\": [\n    {\n      \"accountIdentifier\": \"sdkautotest3\",\n      \"accountNumber\": \"A01335766\",\n      \"displayName\": \"SDK Auto Testing 3\",\n      \"createdAt\": \"2018-04-26T18:16:51.652Z\",\n      \"status\": \"ACTIVE\"\n    },\n    {\n      \"accountIdentifier\": \"sdkautotest2\",\n      \"accountNumber\": \"A11720237\",\n      \"displayName\": \"SDK Auto Testing 2\",\n      \"createdAt\": \"2018-04-26T18:13:45.196Z\",\n      \"status\": \"ACTIVE\"\n    }\n  ]\n}",
                              TestHelper.ConvertStreamToString(httpCallBackHandler.Response.RawBody),
                              true, true, false),
                          "Response body should have matching keys");
        }
コード例 #2
0
        public async Task GetCustomerAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new Exception());
            var controller = new CustomersController(_customerDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetCustomerAsync("1");

            await result.Should().ThrowExactlyAsync <Exception>();
        }
コード例 #3
0
        public async Task GetCustomerAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException());
            var controller = new CustomersController(_customerDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCustomerAsync("1");

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
コード例 #4
0
        public async Task GetCustomerAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            _customerDbServiceMock.Setup(x => x.GetAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new CustomersController(_customerDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCustomerAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
コード例 #5
0
        public async Task GetCustomerAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException()
        {
            // Example of these errors: database does not exist, table does not exist etc.

            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new CustomersController(_customerDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetCustomerAsync("1");

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
コード例 #6
0
        public async Task GetCustomerAsync__Data_retrieve_succeeded__Should_return_200Ok_response_with_data()
        {
            string id = "15891fb0-faec-43c6-9e83-04a4a17c3660";

            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(_validCustomer);
            _mapperMock.Setup(x => x.Map <CustomerDto>(It.IsNotNull <Customer>())).Returns(new CustomerDto {
                Id = id, EmailAddress = "*****@*****.**"
            });
            var controller = new CustomersController(_customerDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCustomerAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull();
        }