public async Task CreateOrderAsync__Order_handle_succeeded__Should_return_201Created_with_order_data() { string orderId = "orderid"; var customerDto = new CustomerDto { Id = "1", DateOfBirth = _orderData.Customer.DateOfBirth, EmailAddress = _orderData.Customer.EmailAddress }; var ticketDtos = new TicketDto[] { new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } }, new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } } }.AsEnumerable(); SetUpForSucceededOrderHandling(orderId, customerDto, ticketDtos); var controller = new OrdersController(_orderHandlerMock.Object, _logger, _mapperMock.Object); var result = await controller.CreateOrderAsync(_orderData); (result as ObjectResult).StatusCode.Should().Be(201); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().BeEquivalentTo(new ApiError()); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Customer.Should().BeEquivalentTo(customerDto); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Tickets.Should().BeEquivalentTo(ticketDtos); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Id.Should().BeEquivalentTo(orderId); }
public async Task TestPlaceOrderWithMinimumCriteria() { // Parameters for the API call Raas.Models.CreateOrderRequestModel body = APIHelper.JsonDeserialize <Raas.Models.CreateOrderRequestModel>("{ \"accountIdentifier\": \"sdkautotest5\", \"amount\": 1.00, \"customerIdentifier\": \"sdkautotest4\", \"sendEmail\": false, \"utid\": \"U561593\" }"); // Perform API call Raas.Models.OrderModel result = null; try { result = await controller.CreateOrderAsync(body); } catch (APIException) {}; // Test response code Assert.AreEqual(201, httpCallBackHandler.Response.StatusCode, "Status should be 201"); // Test whether the captured response is as we expected Assert.IsNotNull(result, "Result should exist"); Assert.IsTrue(TestHelper.IsJsonObjectProperSubsetOf( "{\n \"referenceOrderID\": \"RA180426-1401-64\",\n \"customerIdentifier\": \"sdkautotest4\",\n \"accountIdentifier\": \"sdkautotest5\",\n \"accountNumber\": \"A32386768\",\n \"amountCharged\": {\n \"value\": 1,\n \"currencyCode\": \"USD\",\n \"total\": 1\n },\n \"denomination\": {\n \"value\": 1,\n \"currencyCode\": \"USD\"\n },\n \"utid\": \"U561593\",\n \"rewardName\": \"Reward Link\",\n \"sender\": {\n \"firstName\": \"\",\n \"lastName\": \"\",\n \"email\": \"\"\n },\n \"recipient\": {\n \"email\": \"\",\n \"firstName\": \"\",\n \"lastName\": \"\"\n },\n \"sendEmail\": false,\n \"status\": \"COMPLETE\",\n \"createdAt\": \"2018-04-26T20:08:59.624Z\",\n \"reward\": {\n \"credentials\": {\n \"Redemption Link\": \"https://sandbox.rewardlink.io/r/1/ed0HtzSblNV6oFddNnnlf68eXzGQoREvcxwxu_Vi5Wk\"\n },\n \"credentialList\": [\n {\n \"label\": \"Redemption Link\",\n \"value\": \"https://sandbox.rewardlink.io/r/1/ed0HtzSblNV6oFddNnnlf68eXzGQoREvcxwxu_Vi5Wk\",\n \"type\": \"url\",\n \"credentialType\": \"redemptionUrl\"\n }\n ],\n \"redemptionInstructions\": \"<p>• Click on the redemption link above to activate your Reward Link.<br />\\r\\n• Next, you will be able to spend your balance on retail gift cards.</p>\\r\\n\\r\\n<p>If you don't want to spend your entire Reward Link value right away, save the email or URL and return via the redemption link - your value will be waiting to be spent. This allows you to store the balance to redeem at another time.</p>\\r\\n\"\n }\n}", TestHelper.ConvertStreamToString(httpCallBackHandler.Response.RawBody), false, true, false), "Response body should have matching keys"); }
public async Task <HttpStatusCode> CreateOrder(Order order) { OrdersController ordersController = new OrdersController(); var status = await ordersController.CreateOrderAsync(order); return(status); }
public static async Task CreateOrderAsync_InvokesCreatesOrder( [Frozen] Mock <IOrderService> service, [Frozen] Mock <HttpContext> httpContextMock, Order order, OrderingParty orderingParty, string description, OrdersController controller) { var model = new CreateOrderModel { OrganisationId = orderingParty.Id, Description = description }; var claims = new[] { new Claim("primaryOrganisationId", model.OrganisationId.ToString()) }; var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock")); httpContextMock.Setup(c => c.User).Returns(user); service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() => { order = new Order { CallOffId = order.CallOffId, OrderingParty = new OrderingParty { Id = model.OrganisationId !.Value, }, }; }).ReturnsAsync(order); await controller.CreateOrderAsync(model); service.Verify(o => o.CreateOrder(model.Description, model.OrganisationId !.Value), Times.Once); }
public static async Task CreateOrderAsync_ReturnsExpectedResult( [Frozen] Mock <IOrderService> service, [Frozen] Mock <HttpContext> httpContextMock, Order order, OrderingParty orderingParty, OrdersController controller) { var model = new CreateOrderModel { OrganisationId = orderingParty.Id, Description = "Description" }; var claims = new[] { new Claim("primaryOrganisationId", model.OrganisationId.ToString()) }; var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock")); httpContextMock.Setup(c => c.User).Returns(user); service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() => { order = new Order { CallOffId = order.CallOffId, OrderingParty = new OrderingParty { Id = model.OrganisationId !.Value, }, }; }).ReturnsAsync(order); var result = await controller.CreateOrderAsync(model); result.Should().BeOfType <CreatedAtActionResult>(); result.As <CreatedAtActionResult>().ActionName.Should().Be("Get"); result.As <CreatedAtActionResult>().RouteValues.Should().ContainKey("callOffId"); }
public static async Task CreateOrderAsync_UserFromRelatedOrganisation_CreatesOrder( [Frozen] Mock <IOrderService> service, [Frozen] Mock <HttpContext> httpContextMock, Order order, OrderingParty orderingParty, string description, OrdersController controller) { var model = new CreateOrderModel { OrganisationId = orderingParty.Id, Description = description }; var claims = new[] { new Claim("relatedOrganisationId", model.OrganisationId.ToString()) }; var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock")); httpContextMock.Setup(c => c.User).Returns(user); service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() => { order = new Order { CallOffId = order.CallOffId, Description = model.Description, OrderingParty = orderingParty, }; }).ReturnsAsync(order); await controller.CreateOrderAsync(model); order.OrderingParty.Should().Be(orderingParty); order.Description.Should().Be(description); }
public async Task CreateOrderAsync__Any_problem_with_order_handling_occurred_due_to_unexpected_internal_error__Should_throw_Exception() { _orderHandlerMock.Setup(x => x.CreateOrderAsync(It.IsAny <OrderRequestDto>())); _orderHandlerMock.Setup(x => x.HandleOrderAsync()).ThrowsAsync(new Exception()); var controller = new OrdersController(_orderHandlerMock.Object, _logger, _mapperMock.Object); Func <Task> action = async() => await controller.CreateOrderAsync(_orderData); await action.Should().ThrowExactlyAsync <Exception>(); }
public async Task CreateOrderAsync__Any_problem_with_order_handling_occurred_due_to_client_request__Should_return_400BadRequest_response() { _orderHandlerMock.Setup(x => x.CreateOrderAsync(It.IsAny <OrderRequestDto>())).ThrowsAsync(new InvalidOperationException()); var controller = new OrdersController(_orderHandlerMock.Object, _logger, _mapperMock.Object); var result = await controller.CreateOrderAsync(_orderData); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public static async Task CreateOrderAsync_UnauthorizedUser_ReturnsExpectedResult( Guid orderingPartyId, [Frozen] Mock <HttpContext> httpContextMock, CreateOrderModel model, OrdersController controller) { var claims = new[] { new Claim("primaryOrganisationId", orderingPartyId.ToString()) }; var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock")); httpContextMock.Setup(c => c.User).Returns(user); var result = await controller.CreateOrderAsync(model); result.Should().BeOfType <ForbidResult>(); }
public static void CreateOrderAsync_NullModel_ThrowsArgumentNullException( OrdersController controller) { Assert.ThrowsAsync <ArgumentNullException>(async() => await controller.CreateOrderAsync(null)); }