Пример #1
0
        public async Task UpdateTruck_ChassisAlreadyExists_ReturnsConflict()
        {
            // create model
            var model = new Model();

            model.Description = Guid.NewGuid().ToString();

            IActionResult actionResult = await _modelController.PostModel(model);

            var modelCreatedResult = actionResult as CreatedAtActionResult;

            Assert.IsNotNull(modelCreatedResult);
            Assert.AreEqual(201, modelCreatedResult.StatusCode);
            model.ModelId = Convert.ToInt32(modelCreatedResult.RouteValues["id"]);

            // create truck 1
            var truck1 = new Truck();

            truck1.Chassis = Guid.NewGuid().ToString();
            truck1.Year    = Convert.ToInt16(new Random().Next(1900, 2019));
            truck1.Model   = model;

            actionResult = await _truckController.PostTruck(truck1);

            var createdResult = actionResult as CreatedAtActionResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);

            // create truck 2
            var truck2 = new Truck();

            truck2.Chassis = Guid.NewGuid().ToString();
            truck2.Year    = Convert.ToInt16(new Random().Next(1900, 2019));
            truck2.Model   = model;

            actionResult = await _truckController.PostTruck(truck2);

            createdResult = actionResult as CreatedAtActionResult;
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);

            // try to update truck 2 with truck1.chassis
            truck2.Chassis = truck1.Chassis;
            actionResult   = await _truckController.PutTruck(truck2.TruckId, truck2);

            var conflictResult = actionResult as ConflictResult;

            Assert.IsNotNull(conflictResult);
            Assert.AreEqual(409, conflictResult.StatusCode);

            Assert.Pass();
        }