public void PutProduct_ShouldFail_WhenModel2()
        {
            var context = new TestMachineContextBad();

            context.Machines.Add(GetDemoProduct());

            var controller = new MachinesController(context);

            Machine item = new Machine
            {
                Id          = 1,
                Type        = "DemoType",
                Mark        = "DemoMark",
                Model       = "DemoModel",
                Year        = 2000,
                StateNumber = "DemoNum",
                VIN         = "DemoVIN",
                IdUsers     = 1
            };

            controller.Configuration = new HttpConfiguration();
            controller.Validate(item);
            var result = controller.PutMachine(1, item).Result as StatusCodeResult;

            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
        public void PutProduct_ShouldFail_WhenModel()
        {
            var context = new TestMachineContextGood();

            context.Machines.Add(GetDemoProduct());

            var controller = new MachinesController(context);

            Machine item = new Machine
            {
                Type        = "DemoType",
                Mark        = null,
                Model       = null,
                Year        = 1990,
                StateNumber = "DemoNum",
                VIN         = null,
                IdUsers     = 8
            };

            controller.Configuration = new HttpConfiguration();
            controller.Validate(item);
            var result = controller.PutMachine(item.Id, item).Result;

            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
        }
Exemple #3
0
        public void PutMachine_ValidObj_UpdatedOK()
        {
            //Given
            dBContext.Machines.Add(testMachine);
            dBContext.SaveChanges();

            var machId = testMachine.MachineId;

            testMachine.Description = "UPDATED";

            //When
            controller.PutMachine(machId, testMachine);
            var result = dBContext.Machines.Find(machId);

            //Then
            Assert.Equal(testMachine.Description, result.Description);
        }
        public void PutProduct_ShouldFail_WhenDifferentID()
        {
            var controller = new MachinesController(new TestMachineContextGood());

            var badresult = controller.PutMachine(999, GetDemoProduct()).Result;

            Assert.IsInstanceOfType(badresult, typeof(BadRequestResult));
        }
        public void PutProduct_ShouldReturnStatusCode()
        {
            var controller = new MachinesController(new TestMachineContextGood());

            var item = GetDemoProduct();

            var result = controller.PutMachine(item.Id, item).Result as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void PutProduct_ErrorContext()
        {
            var controller = new MachinesController(new TestMachineContextBad());

            Machine item = new Machine
            {
                Type        = "DemoType",
                Mark        = null,
                Model       = null,
                Year        = 1990,
                StateNumber = "DemoNum",
                VIN         = null,
                IdUsers     = 8
            };

            var result = controller.PutMachine(item.Id, item).Result;

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }