public IActionResult GetMappings(ProductCategoryMappingsParametersModel parameters) { if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter")); } if (parameters.Page < Constants.Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter")); } IList <ProductCategoryMappingDto> mappingsAsDtos = _productCategoryMappingsService.GetMappings(parameters.ProductId, parameters.CategoryId, parameters.Limit, parameters.Page, parameters.SinceId).Select(x => x.ToDto()).ToList(); var productCategoryMappingRootObject = new ProductCategoryMappingsRootObject { ProductCategoryMappingDtos = mappingsAsDtos }; var json = JsonFieldsSerializer.Serialize(productCategoryMappingRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public void WhenSomeProductCategoryMappingsExist_ShouldCallTheSerializerWithTheseProductCategoryMappings() { MappingExtensions.Maps.CreateMap <ProductCategory, ProductCategoryMappingDto>(); var returnedMappingsDtoCollection = new List <ProductCategory>() { new ProductCategory(), new ProductCategory() }; var parameters = new ProductCategoryMappingsParametersModel(); //Arange var autoMocker = new RhinoAutoMocker <ProductCategoryMappingsController>(); autoMocker.Get <IProductCategoryMappingsApiService>().Stub(x => x.GetMappings()).Return(returnedMappingsDtoCollection); //Act autoMocker.ClassUnderTest.GetMappings(parameters); //Assert autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <ProductCategoryMappingsRootObject> .Matches(r => r.ProductCategoryMappingDtos.Count == returnedMappingsDtoCollection.Count), Arg <string> .Is.Equal(parameters.Fields))); }
public void WhenFieldsParametersPassed_ShouldCallTheSerializerWithTheSameFields() { var parameters = new ProductCategoryMappingsParametersModel() { Fields = "id,product_id" }; //Arange var autoMocker = new RhinoAutoMocker <ProductCategoryMappingsController>(); autoMocker.Get <IProductCategoryMappingsApiService>().Stub(x => x.GetMappings()).Return(new List <ProductCategory>()); //Act autoMocker.ClassUnderTest.GetMappings(parameters); //Assert autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <ProductCategoryMappingsRootObject> .Is.Anything, Arg <string> .Is.Equal(parameters.Fields))); }
public void WhenInvalidPageParameterPassed_ShouldReturnBadRequest(int invalidPage) { var parameters = new ProductCategoryMappingsParametersModel() { Page = invalidPage }; //Arange var autoMocker = new RhinoAutoMocker <ProductCategoryMappingsController>(); autoMocker.Get <IJsonFieldsSerializer>().Stub(x => x.Serialize(Arg <ProductCategoryMappingsRootObject> .Is.Anything, Arg <string> .Is.Anything)) .IgnoreArguments() .Return(string.Empty); //Act IHttpActionResult result = autoMocker.ClassUnderTest.GetMappings(parameters); //Assert var statusCode = result.ExecuteAsync(new CancellationToken()).Result.StatusCode; Assert.AreEqual(HttpStatusCode.BadRequest, statusCode); }
public void WhenSomeValidParametersPassed_ShouldCallTheServiceWithTheSameParameters() { var parameters = new ProductCategoryMappingsParametersModel() { SinceId = Configurations.DefaultSinceId + 1, // some different than default since id Page = Configurations.DefaultPageValue + 1, // some different than default page Limit = Configurations.MinLimit + 1 // some different than default limit }; //Arange var autoMocker = new RhinoAutoMocker <ProductCategoryMappingsController>(); autoMocker.Get <IProductCategoryMappingsApiService>().Expect(x => x.GetMappings(parameters.ProductId, parameters.CategoryId, parameters.Limit, parameters.Page, parameters.SinceId)).Return(new List <ProductCategory>()); //Act autoMocker.ClassUnderTest.GetMappings(parameters); //Assert autoMocker.Get <IProductCategoryMappingsApiService>().VerifyAllExpectations(); }