Trying to make some integration tests I have landed in a situation where my post dto becomes empty. But changing the dto to be a GET request it will serialize the request just fine. Any idea why it differs and I get an empty dto in the POST variant?
The test:
-
CreateServicePrice2 is a copy of CreateServicePrice but have an appended “2” on the route and verb set to GET instead of POST
[Fact(DisplayName = "POST new article should return ok")] public async Task PostOwnedShouldReturnOwnedAsync() { // Given var request = new CreateServicePrice { Category = "testcategory", From = DateTime.Now, To = DateTime.Now.AddDays(1), Price = 1, CompanyId = this.DefaultOwnedBookingSupplier.Id, CurrencyId = this.SharedDbContext.Constants.DefaultCurrency.Code, ServiceId = this.Data.OwnedActiveService.LegacyId, FromTime = Time.StartOfDay, ToTime = Time.EndOfDay, VAT = 0.25M, DaysOfWeek = DaysOfWeek.Monday.ToIntArray() }; var request2 = new CreateServicePrice2 { Category = "testcategory", From = DateTime.Now, To = DateTime.Now.AddDays(1), Price = 1, CompanyId = this.DefaultOwnedBookingSupplier.Id, CurrencyId = this.SharedDbContext.Constants.DefaultCurrency.Code, ServiceId = this.Data.OwnedActiveService.LegacyId, FromTime = Time.StartOfDay, ToTime = Time.EndOfDay, VAT = 0.25M, DaysOfWeek = DaysOfWeek.Monday.ToIntArray() }; // When // This works, the dto is delivered to the service var result = await this.Client.GetAsync(request2).ConfigureAwait(false); // This does not work, the dto triggers the service but is empty var response = await this.Client.PostAsync(request).ConfigureAwait(false);
And so on…the service methods looks like this:
public async Task<object> Post(CreateServicePrice request)
{
// Failure here, the request have no values!
...
}
public async Task<object> Get(CreateServicePrice2 request)
{
// Success here! the request have values!
...
}
The dtos looks like this
[Route("/services/prices/",
Verbs = "POST",
Summary = "Create a price",
Notes =
"Create a new price on the service"
)]
public class CreateServicePrice : IReturn<ServicePriceResponse> //ICompany
{
[ApiMember(
Description =
"The company id, if empty will use the company id for the user you are logged in with.",
IsRequired = false)]
public Guid? CompanyId { get; set; }
[ApiMember(
Description = "The service id")]
public int ServiceId { get; set; }
[ApiMember(
Description = "The price")]
public double Price { get; set; }
[ApiMember(
Description = "The price currency")]
public string CurrencyId { get; set; }
[ApiMember(
Description = "The price VAT in percent")]
public decimal VAT { get; set; }
[ApiMember(
Description = "The price category if price has a category")]
public string Category { get; set; }
[ApiMember(
Description = "The valid from date for the price."
)]
public DateTime From { get; set; }
[ApiMember(
Description = "The valid to date for the price."
)]
public DateTime To { get; set; }
[ApiMember(
Description = "If the price is only valid for specific days in week add a comma separated list of which days this day price belongs to, 1 = Monday .. 7 = Sunday. All old days connected will be removed on update."
)]
public int[] DaysOfWeek { get; set; }
[ApiMember(
Description = "If the price is only valid for specific days in week add a comma separated list of which days this day price belongs to, 1 = Monday .. 7 = Sunday. All old days connected will be removed on update."
)]
public TimeSpan? FromTime { get; set; } = new TimeSpan(0, 0, 0);
[ApiMember(
Description = "If the price is only valid for a specific time span during a time of day enter the FromTime and ToTime parameters."
)]
public TimeSpan? ToTime { get; set; } = new TimeSpan(23, 59, 59);
}
[Route("/services/prices2/",
Verbs = "GET",
Summary = "Create a price",
Notes =
"Create a new price on the service"
)]
public class CreateServicePrice2 : IReturn<ServicePriceResponse> //ICompany
{
[ApiMember(
Description =
"The company id, if empty will use the company id for the user you are logged in with.",
IsRequired = false)]
public Guid? CompanyId { get; set; }
[ApiMember(
Description = "The service id")]
public int ServiceId { get; set; }
[ApiMember(
Description = "The price")]
public double Price { get; set; }
[ApiMember(
Description = "The price currency")]
public string CurrencyId { get; set; }
[ApiMember(
Description = "The price VAT in percent")]
public decimal VAT { get; set; }
[ApiMember(
Description = "The price category if price has a category")]
public string Category { get; set; }
[ApiMember(
Description = "The valid from date for the price."
)]
public DateTime From { get; set; }
[ApiMember(
Description = "The valid to date for the price."
)]
public DateTime To { get; set; }
[ApiMember(
Description = "If the price is only valid for specific days in week add a comma separated list of which days this day price belongs to, 1 = Monday .. 7 = Sunday. All old days connected will be removed on update."
)]
public int[] DaysOfWeek { get; set; }
[ApiMember(
Description = "If the price is only valid for specific days in week add a comma separated list of which days this day price belongs to, 1 = Monday .. 7 = Sunday. All old days connected will be removed on update."
)]
public TimeSpan? FromTime { get; set; } = new TimeSpan(0, 0, 0);
[ApiMember(
Description = "If the price is only valid for a specific time span during a time of day enter the FromTime and ToTime parameters."
)]
public TimeSpan? ToTime { get; set; } = new TimeSpan(23, 59, 59);
}