public IActionResult GetOrders(OrdersParametersModel parameters) { if (parameters.Page < Constants.Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid limit parameter")); } var storeId = _storeContext.CurrentStore.Id; var orders = _orderApiService.GetOrders(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId, parameters.Status, parameters.PaymentStatus, parameters.ShippingStatus, parameters.CustomerId, storeId); IList <OrderDto> ordersAsDtos = orders.Select(x => _dtoHelper.PrepareOrderDTO(x)).ToList(); var ordersRootObject = new OrdersRootObject { Orders = ordersAsDtos }; var json = JsonFieldsSerializer.Serialize(ordersRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public void WhenSomeValidParametersPassed_ShouldCallTheServiceWithTheSameParameters() { var parameters = new OrdersParametersModel() { SinceId = Configurations.DefaultSinceId + 1, // some different than default since id CreatedAtMin = DateTime.Now, CreatedAtMax = DateTime.Now, Page = Configurations.DefaultPageValue + 1, // some different than default page Limit = Configurations.MinLimit + 1, // some different than default limit Ids = new List <int>() { 1, 2, 3 } }; //Arange _autoMocker.Get <IOrderApiService>() .Expect(x => x.GetOrders(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId)).IgnoreArguments().Return(new List <Order>()); //Act _autoMocker.ClassUnderTest.GetOrders(parameters); //Assert _autoMocker.Get <IOrderApiService>().VerifyAllExpectations(); }
public void WhenNoOrdersExist_ShouldCallTheSerializerWithNoOrders() { var returnedOrdersDtoCollection = new List <Order>(); var parameters = new OrdersParametersModel(); //Arange _autoMocker.Get <IOrderApiService>().Stub(x => x.GetOrders()).IgnoreArguments().Return(returnedOrdersDtoCollection); //Act _autoMocker.ClassUnderTest.GetOrders(parameters); //Assert _autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <OrdersRootObject> .Matches(r => r.Orders.Count == returnedOrdersDtoCollection.Count), Arg <string> .Is.Equal(parameters.Fields))); }
public void WhenFieldsParametersPassed_ShouldCallTheSerializerWithTheSameFields() { var parameters = new OrdersParametersModel() { Fields = "id,paymentstatus" }; var returnedOrdersDtoCollection = new List <Order>(); //Arange _autoMocker.Get <IOrderApiService>().Stub(x => x.GetOrders()).IgnoreArguments().Return(returnedOrdersDtoCollection); //Act _autoMocker.ClassUnderTest.GetOrders(parameters); //Assert _autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <OrdersRootObject> .Is.Anything, Arg <string> .Is.Equal(parameters.Fields))); }
public void WhenInvalidLimitParameterPassed_ShouldReturnBadRequest(int invalidLimit) { var parameters = new OrdersParametersModel() { Limit = invalidLimit }; //Arange _autoMocker.Get <IJsonFieldsSerializer>().Stub(x => x.Serialize(Arg <OrdersRootObject> .Is.Anything, Arg <string> .Is.Anything)) .IgnoreArguments() .Return(string.Empty); //Act IActionResult result = _autoMocker.ClassUnderTest.GetOrders(parameters); //Assert var statusCode = ActionResultExecutor.ExecuteResult(result); Assert.AreEqual(HttpStatusCode.BadRequest, statusCode); }
public void WhenInvalidPageParameterPassed_ShouldReturnBadRequest(int invalidPage) { var parameters = new OrdersParametersModel() { Page = invalidPage }; //Arange var autoMocker = new RhinoAutoMocker <OrdersController>(); autoMocker.Get <IJsonFieldsSerializer>().Stub(x => x.Serialize(Arg <OrdersRootObject> .Is.Anything, Arg <string> .Is.Anything)) .IgnoreArguments() .Return(string.Empty); //Act IHttpActionResult result = autoMocker.ClassUnderTest.GetOrders(parameters); //Assert var statusCode = result.ExecuteAsync(new CancellationToken()).Result.StatusCode; Assert.AreEqual(HttpStatusCode.BadRequest, statusCode); }