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));
        }
        public void test_validation()
        {
            var context = new TestMachineContextGood();

            context.Machines.Add(GetDemoProduct());
            Machine item = new Machine
            {
                Id          = 1,
                Type        = "DemoType",
                Mark        = string.Empty,
                Model       = "DemoModel",
                Year        = 2000,
                StateNumber = "DemoNum",
                VIN         = "DemoVIN",
                IdUsers     = 1
            };
            var controller = new MachinesController();

            controller.Configuration = new HttpConfiguration();

            controller.Validate(item);
            var result = controller.PostMachine(item).Result;

            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
            Assert.AreEqual(1, context.Machines.Count());
        }
        public void GetProduct_ShouldFail_WhenNoID()
        {
            var context = new TestMachineContextGood();

            context.Machines.Add(GetDemoProduct());

            var controller = new MachinesController(context);
            var result     = controller.GetMachine(2).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
        public void GetProduct_ShouldReturnProductWithSameID()
        {
            var context = new TestMachineContextGood();

            context.Machines.Add(GetDemoProduct());

            var controller = new MachinesController(context);
            var result     = controller.GetMachine(1).Result as OkNegotiatedContentResult <Machine>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Content.Id);
        }
        public void DeleteProduct_ShouldNotFound()
        {
            var context = new TestMachineContextGood();
            var item    = GetDemoProduct();

            context.Machines.Add(item);

            var controller = new MachinesController(context);
            var result     = controller.DeleteMachine(555).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
        public void DeleteProduct_ShouldReturnOK()
        {
            var context = new TestMachineContextGood();
            var item    = GetDemoProduct();

            context.Machines.Add(item);

            var controller = new MachinesController(context);
            var result     = controller.DeleteMachine(1).Result as OkNegotiatedContentResult <Machine>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
        public void GetProducts_ShouldReturnAllProducts()
        {
            var context = new TestMachineContextGood();

            context.Machines.Add(new Machine {
                Id = 1, Type = "DemoType1", Mark = "DemoMark1", Model = "DemoModel1", Year = 2001, StateNumber = "DemoNum1", VIN = "DemoVIN1", IdUsers = 1
            });
            context.Machines.Add(new Machine {
                Id = 2, Type = "DemoType2", Mark = "DemoMark2", Model = "DemoModel2", Year = 2002, StateNumber = "DemoNum2", VIN = "DemoVIN2", IdUsers = 2
            });
            context.Machines.Add(new Machine {
                Id = 3, Type = "DemoType3", Mark = "DemoMark3", Model = "DemoModel3", Year = 2003, StateNumber = "DemoNum3", VIN = "DemoVIN3", IdUsers = 3
            });

            var controller = new MachinesController(context);
            var result     = controller.GetMachines() as TestDBSetMachines;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }