public void DeleteAddressBadRequestFailureTest() { int id = 1; string Address1 = "Test"; string Address2 = "Test"; string City = "Test"; string ZipCode = "Test"; bool isDeleted = false; int AddressTypeId = 1; int CreatedByUserId = 1; NSI.REST.Models.AddressCreateModel address = new AddressCreateModel() { AddressId = id, Address1 = Address1, Address2 = Address2, City = City, ZipCode = ZipCode, AddressTypeId = AddressTypeId, CreatedByUserId = CreatedByUserId, IsDeleted = isDeleted, DateCreated = DateTime.Now, DateModified = DateTime.Now }; var addressRepo = new Mock <IAddressRepository>(); addressRepo.Setup(x => x.DeleteAddressById(It.IsAny <int>())).Throws <Exception>(); var addressManipulation = new AddressManipulation(addressRepo.Object); var controller = new AddressController(addressManipulation); var result = controller.DeleteAddress(1); Assert.IsType <BadRequestObjectResult>(result); }
public async Task DeleteAddressExceptionCatch() { /// Arrange var id = 3; mockRepo.Setup(x => x.Address).Returns(_addressRepoMock.Object); _addressRepoMock.Setup(x => x.GetAddressById(id)).Throws(new Exception()); // Act var result = await _sut.DeleteAddress(id); // Assert //tocheck mockLogger.Verify(x => x.LogError("Something went wrong inside DeleteLandlord(id) action: System.Exception: Exception of type 'System.Exception' was thrown."), Times.Never); Assert.IsType <ObjectResult>(result); }
public async Task Can_Delete_Address() { AddressController addressCtrl = new AddressController(addressRepo); RedirectToRouteResult result = (RedirectToRouteResult)await addressCtrl.DeleteAddress(4); Assert.AreEqual("List", result.RouteValues["action"]); Assert.AreEqual("#421521", result.RouteValues["userId"]); }
public void DeleteNonExistentAddressFailureTest() { // Arrange & Act var mockRepo = new Mock <IAddressManipulation>(); var controller = new AddressController(mockRepo.Object); // Act var result = controller.DeleteAddress(1); // Assert Assert.IsType <NoContentResult>(result); }
public void TestDeleteAddress() { // seeding DB using (var context = new ProTickDatabaseContext(dbOptions)) { DbContextSeeder.SeedFull(context); } // db is Test-Ready using (var context = new ProTickDatabaseContext(dbOptions)) { var dbm = new DatabaseQueryManager(context); var converter = new ResourceDTOConverter(dbm); var controller = new AddressController(context, converter, dbm); var dtos = DbContextSeeder.GetSeededAddressDTOs( 3 ) .ToList(); controller.DeleteAddress(dtos[2].AddressID); var actualCount = context.Address.ToList().Count; Assert.Equal(2, actualCount); Assert.True( context.Address.FirstOrDefault(x => x.AddressID == 3) == null); Assert.True( context.Address.FirstOrDefault(x => x.AddressID != 3) != null); controller.DeleteAddress(dtos[1].AddressID); actualCount = context.Address.ToList().Count; Assert.Equal(1, actualCount); Assert.True( context.Address.FirstOrDefault(x => x.AddressID == 2) == null); } }
public async Task DeleteAddress_ShouldReturnOk() { var tenentid = Guid.NewGuid(); var userid = Guid.NewGuid(); var contactid = Guid.NewGuid(); var addressid = Guid.NewGuid(); var address = new Address(); _addressRepo.Setup(x => x.FirstOrDefault(y => y.Id == addressid && y.Contact.Id == contactid && y.Contact.User.Id == userid && y.Contact.User.Tenent.Id == tenentid)).ReturnsAsync(address); _addressRepo.Setup(x => x.Remove(address)); var result = await _addressController.DeleteAddress(addressid, tenentid, contactid, userid); var okresult = result as OkObjectResult; Assert.Equal(StatusCodes.Status200OK, okresult.StatusCode); }
protected void cmdDelete_Click(object sender, EventArgs e) { try { if (!Null.IsNull(_nav.AddressID)) { AddressController controller = new AddressController(); controller.DeleteAddress(int.Parse(_nav.AddressID)); _nav.AddressID = Null.NullString; } invokeEditComplete(); } catch(Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }