示例#1
0
        public void GetProduct_ShouldFail_WhenNoID()
        {
            var context = new TestFinesContextGood();

            context.Fines.Add(GetDemoProduct());

            var controller = new FinesController(context);
            var result     = controller.GetFine(2).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
示例#2
0
        public void GetProduct_ShouldReturnProductWithSameID()
        {
            var context = new TestFinesContextGood();

            context.Fines.Add(GetDemoProduct());

            var controller = new FinesController(context);
            var result     = controller.GetFine(3).Result as OkNegotiatedContentResult <Fine>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
示例#3
0
        public void DeleteProduct_ShouldNotFound()
        {
            var context = new TestFinesContextGood();
            var item    = GetDemoProduct();

            context.Fines.Add(item);

            var controller = new FinesController(context);
            var result     = controller.DeleteFine(555).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
示例#4
0
        public void DeleteProduct_ShouldReturnOK()
        {
            var context = new TestFinesContextGood();
            var item    = GetDemoProduct();

            context.Fines.Add(item);

            var controller = new FinesController(context);
            var result     = controller.DeleteFine(3).Result as OkNegotiatedContentResult <Fine>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
示例#5
0
        public void PutProduct_ShouldFail_WhenModel()
        {
            var context = new TestFinesContextGood();

            context.Fines.Add(GetDemoProduct());

            var controller = new FinesController(context);

            Fine item = new Fine {
                Id = 3, NameFine = string.Empty, AmountFine = 100
            };

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

            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
        }
示例#6
0
        public void test_validation()
        {
            var context = new TestFinesContextGood();

            context.Fines.Add(GetDemoProduct());
            Fine item = new Fine {
                Id         = 3,
                NameFine   = string.Empty,
                AmountFine = 100
            };
            var controller = new FinesController();

            controller.Configuration = new HttpConfiguration();

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

            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
            Assert.AreEqual(1, context.Fines.Count());
        }
示例#7
0
        public void GetProducts_ShouldReturnAllProducts()
        {
            var context = new TestFinesContextGood();

            context.Fines.Add(new Fine {
                Id = 1, NameFine = "Demo1", AmountFine = 100
            });
            context.Fines.Add(new Fine {
                Id = 2, NameFine = "Demo2", AmountFine = 200
            });
            context.Fines.Add(new Fine {
                Id = 3, NameFine = "Demo3", AmountFine = 300
            });

            var controller = new FinesController(context);
            var result     = controller.GetFines() as TestDBSetFines;

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