dimanche 1 mars 2015

Asp.net model date testing

Say I have a model for a product:



public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
...
}


For this product I have a Dto:



public class ProductDto
{
[Required]
public string Name { get; set; }
...
}


Now, In my controller, I have a method that "creates" new products and records the current time in the Created attribute:



public IHttpActionResult PostProduct(ProductDto dto)
{
return Ok(new Product()
{
Created = DateTime.Now,
Name = dto.Name
});
}


Say I wanted to unit test this method to verify that a newly created product is assigned a DateTime object other than the default {01-01-0001 00:00:00} it gets from the prop snippet, how would I go about that? I would prefer that Created, in the model, is not nullable.


Aucun commentaire:

Enregistrer un commentaire