public async Task CreateTruck_ChassisAlreadyExists_ReturnsConflict() { // create model var model = new Model(); model.Description = Guid.NewGuid().ToString(); IActionResult actionResult1 = await _modelController.PostModel(model); var modelCreatedResult = actionResult1 as CreatedAtActionResult; Assert.IsNotNull(modelCreatedResult); Assert.AreEqual(201, modelCreatedResult.StatusCode); model.ModelId = Convert.ToInt32(modelCreatedResult.RouteValues["id"]); // create truck var truck = new Truck(); truck.Chassis = Guid.NewGuid().ToString(); truck.Year = Convert.ToInt16(new Random().Next(1900, 2019)); truck.Model = model; IActionResult actionResult2 = await _truckController.PostTruck(truck); var truckCreatedResult = actionResult2 as CreatedAtActionResult; Assert.IsNotNull(truckCreatedResult); Assert.AreEqual(201, truckCreatedResult.StatusCode); // try create another with same chassis IActionResult actionResult3 = await _truckController.PostTruck(truck); var conflictResult = actionResult3 as ConflictResult; Assert.IsNotNull(conflictResult); Assert.AreEqual(409, conflictResult.StatusCode); Assert.Pass(); }