public void GetCustomersByID_Valid() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.GetCustomer(1); taskReturn.Wait(); var result = taskReturn.Result.Value; Customer testData = result; #endregion #region ASSERT Assert.AreEqual(testData.Id, 1); Assert.AreEqual(testData.Name, "John Doe"); Assert.AreEqual(testData.UserName, "*****@*****.**"); Assert.AreEqual(testData.Street, "123 A Street"); Assert.AreEqual(testData.City, "Here"); Assert.AreEqual(testData.StateID, 1); Assert.AreEqual(testData.ZipCode, 10000); #endregion }
public void DeleteCustomer_Valid() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.DeleteCustomer(1); taskReturn.Wait(); var resultData = taskReturn.Result.Value; Customer checkData = testRepo.SelectById(1).Result; #endregion #region ASSERT Assert.AreEqual(resultData.Id, 1); Assert.AreEqual(resultData.Name, "John Doe"); Assert.AreEqual(resultData.UserName, "*****@*****.**"); Assert.AreEqual(resultData.Street, "123 A Street"); Assert.AreEqual(resultData.City, "Here"); Assert.AreEqual(resultData.StateID, 1); Assert.AreEqual(resultData.ZipCode, 10000); Assert.IsNull(checkData); #endregion }
public void CustomersApiController_Constructor_ValidArgumentTest() { var mockModel = new Mock <IModel>(); CustomersApiController target = null; Assert.DoesNotThrow(() => target = new CustomersApiController(mockModel.Object)); Assert.AreEqual(mockModel.Object, target.Model); }
public void PostCustomer_Valid() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); Customer testData = new Customer() { Id = 3, Name = "Jane Doe", UserName = "******", Street = "999 Q Street", City = "NoWhere", StateID = 3, ZipCode = 30000, }; #endregion #region ACT var taskReturn = testController.PostCustomer(testData); taskReturn.Wait(); var resultStatus = taskReturn.Result.Result; Customer checkData = testRepo.SelectById(3).Result; #endregion #region ASSERT Assert.IsTrue(resultStatus is CreatedAtActionResult); Assert.AreEqual((resultStatus as CreatedAtActionResult).StatusCode, 201); Assert.AreEqual((resultStatus as CreatedAtActionResult).RouteValues["id"], 3); var testReturn = ((resultStatus as CreatedAtActionResult).Value as Customer); Assert.AreEqual(testReturn.Id, 3); Assert.AreEqual(testReturn.Name, "Jane Doe"); Assert.AreEqual(testReturn.UserName, "*****@*****.**"); Assert.AreEqual(testReturn.Street, "999 Q Street"); Assert.AreEqual(testReturn.City, "NoWhere"); Assert.AreEqual(testReturn.StateID, 3); Assert.AreEqual(testReturn.ZipCode, 30000); Assert.AreEqual(checkData.Id, 3); Assert.AreEqual(checkData.Name, "Jane Doe"); Assert.AreEqual(checkData.UserName, "*****@*****.**"); Assert.AreEqual(checkData.Street, "999 Q Street"); Assert.AreEqual(checkData.City, "NoWhere"); Assert.AreEqual(checkData.StateID, 3); Assert.AreEqual(checkData.ZipCode, 30000); #endregion }
public void DeleteCustomer_NonExistingCustomer() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.DeleteCustomer(0); taskReturn.Wait(); var resultStatus = taskReturn.Result.Result; var checkData = testRepo.SelectAll().Result; #endregion #region ASSERT Assert.IsTrue(resultStatus is NotFoundResult); Assert.AreEqual((resultStatus as NotFoundResult).StatusCode, 404); Assert.AreEqual(checkData.Count, 2); Assert.AreEqual(checkData[0].Id, 1); Assert.AreEqual(checkData[0].Name, "John Doe"); Assert.AreEqual(checkData[0].UserName, "*****@*****.**"); Assert.AreEqual(checkData[0].Street, "123 A Street"); Assert.AreEqual(checkData[0].City, "Here"); Assert.AreEqual(checkData[0].StateID, 1); Assert.AreEqual(checkData[0].ZipCode, 10000); Assert.AreEqual(checkData[1].Id, 2); Assert.AreEqual(checkData[1].Name, "Mary Sue"); Assert.AreEqual(checkData[1].UserName, "*****@*****.**"); Assert.AreEqual(checkData[1].Street, "345 B Avenue"); Assert.AreEqual(checkData[1].City, "There"); Assert.AreEqual(checkData[1].StateID, 2); Assert.AreEqual(checkData[1].ZipCode, 20000); #endregion }
public void GetCustomers() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.GetCustomer(); taskReturn.Wait(); var result = taskReturn.Result.Value; List <Customer> testList = new List <Customer>(result); #endregion #region ASSERT Assert.AreEqual(testList.Count, 2); Assert.AreEqual(testList[0].Id, 1); Assert.AreEqual(testList[0].Name, "John Doe"); Assert.AreEqual(testList[0].UserName, "*****@*****.**"); Assert.AreEqual(testList[0].Street, "123 A Street"); Assert.AreEqual(testList[0].City, "Here"); Assert.AreEqual(testList[0].StateID, 1); Assert.AreEqual(testList[0].ZipCode, 10000); Assert.AreEqual(testList[1].Id, 2); Assert.AreEqual(testList[1].Name, "Mary Sue"); Assert.AreEqual(testList[1].UserName, "*****@*****.**"); Assert.AreEqual(testList[1].Street, "345 B Avenue"); Assert.AreEqual(testList[1].City, "There"); Assert.AreEqual(testList[1].StateID, 2); Assert.AreEqual(testList[1].ZipCode, 20000); #endregion }
public void ShouldGetCustomersReturnCustomerRecords() { var mockRepository = new MockRepository(MockBehavior.Default); var mockCustomers = new List <Customer> { new Customer { CustomerId = 11, CustomerName = "Northwind", Address = "Bangalore", CreditLimit = 23000, ActiveStatus = true, EmailId = "*****@*****.**", PhoneNumber = "080-49834343", Remarks = "Simple" }, new Customer { CustomerId = 12, CustomerName = "Southwind", Address = "Bangalore", CreditLimit = 23000, ActiveStatus = true, EmailId = "*****@*****.**", PhoneNumber = "080-49834343", Remarks = "Simple" }, new Customer { CustomerId = 13, CustomerName = "Westwind", Address = "Bangalore", CreditLimit = 23000, ActiveStatus = true, EmailId = "*****@*****.**", PhoneNumber = "080-49834343", Remarks = "Simple" }, new Customer { CustomerId = 14, CustomerName = "Eastwind", Address = "Bangalore", CreditLimit = 23000, ActiveStatus = true, EmailId = "*****@*****.**", PhoneNumber = "080-49834343", Remarks = "Simple" }, new Customer { CustomerId = 15, CustomerName = "Oxyrich", Address = "Bangalore", CreditLimit = 23000, ActiveStatus = true, EmailId = "*****@*****.**", PhoneNumber = "080-49834343", Remarks = "Simple" } }; var mockCustomersBusinessComponent = mockRepository.Create <ICustomersBusinessComponent>(); mockCustomersBusinessComponent .Setup(businessComponent => businessComponent.GetCustomers(default(string), default(string))) .Returns(mockCustomers); var customersApiController = new CustomersApiController(mockCustomersBusinessComponent.Object); var result = customersApiController.GetCustomers() as OkObjectResult; var customersList = result.Value as IEnumerable <Customer>; Assert.NotNull(result); Assert.NotNull(customersList); var expectedNoOfCustomers = 5; var actualNoOfCustomers = customersList.Count(); Assert.Equal <int>(expectedNoOfCustomers, actualNoOfCustomers); }
public void PutCustomer_InvalidID() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); Customer testData = new Customer() { Id = 1, Name = "Jane Doe", UserName = "******", Street = "123 A Street", City = "There", StateID = 1, ZipCode = 10000, }; #endregion #region ACT var taskReturn = testController.PutCustomer(2, testData); taskReturn.Wait(); var result = taskReturn.Result; Customer resultData = testRepo.SelectById(1).Result; #endregion #region ASSERT Assert.IsTrue(result is BadRequestResult); Assert.AreEqual((result as BadRequestResult).StatusCode, 400); Assert.AreEqual(resultData.Name, "John Doe"); Assert.AreEqual(resultData.City, "Here"); #endregion }
public void GetCustomersByID_NonExistentUser() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.GetCustomer(0); taskReturn.Wait(); var result = taskReturn.Result.Result; #endregion #region ASSERT Assert.IsTrue(result is NotFoundResult); Assert.AreEqual((result as NotFoundResult).StatusCode, 404); #endregion }
public CustomerApiControllerShould() { _mockCustomerService = new Mock <ICustomerService>(); _customerApiControllerSut = new CustomersApiController(_mockCustomerService.Object); }