public void CreatePropertyTest() { var actionResult = PropertyController.CreateProperty(FakeProperty).Result; Assert.AreEqual(((ObjectResult)actionResult).StatusCode, (int)System.Net.HttpStatusCode.Created); Assert.AreEqual(((ObjectResult)actionResult).Value.ToString().ToEntitySimple <Property>().IdProperty, FakeProperty.IdProperty); }
public async Task PostPropertyTestAsync() { var portfolio3 = new Portfolio { Name = "Portfolio3" }; var property = new Property { Address = new Address { City = "Torquay", CreatedDateTime = DateTime.Now.AddDays(-3), IsActive = true, Line1 = "Line 1", Line2 = "Line 2", PostCode = "Postcode", Town = "Town" }, Description = "Description", IsActive = true, NoOfBeds = 2, PropertyValue = 12345, PurchaseDate = new DateTime(2008, 3, 1), PurchasePrice = 12343, RentalPrice = 431, CreatedDateTime = DateTime.Now.AddDays(-1), Portfolio = portfolio3, Tenants = new List <Tenant> { new Tenant { FirstName = "Jeff", LastName = "LastName1", EmailAddress = "*****@*****.**", IsActive = true, Profession = "Window cleaner", TenancyStartDate = DateTime.Now.AddDays(-1) }, new Tenant { FirstName = "Mandy", LastName = "LastName2", EmailAddress = "*****@*****.**", IsActive = true, Profession = "Superstar DJ", TenancyStartDate = DateTime.Now.AddDays(-1) } } }; _propertyServiceMock.Setup(s => s.CreateProperty(property, It.IsAny <Guid>())) .Returns(Task.FromResult <Property>(property)).Verifiable(); var controller = new PropertiesController(_propertyServiceMock.Object, _mapperMock); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = _principle } }; var createProperty = _mapperMock.Map <PropertyCreateDto>(property); var results = await controller.CreateProperty(It.IsAny <Guid>(), createProperty); var okResult = results.Result as CreatedAtActionResult; Assert.AreEqual((int)System.Net.HttpStatusCode.Created, okResult.StatusCode); }