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)); }
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); }
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)); }
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); }
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)); }
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()); }
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); }