public void Delete_Get_Object() { var actionResult = _adressController.Delete(1); var viewResult = actionResult as ViewResult; var address = (Address)viewResult.Model; Assert.AreEqual(1, address.Id); }
public async void Test_Controller_Delete() { var resultFail = await _controller.Delete(0); var resultPass = await _controller.Delete(1); Assert.NotNull(resultFail); Assert.NotNull(resultPass); }
public async void ReturnValidModelForCorrectId(int?id) { var result = await sut.Delete(id); var vr = Assert.IsType <ViewResult>(result); fixture.repositoryWrapper.Verify(y => y.Address.GetAddressByIdAsync(id), Times.Once); Assert.Equal("Delete", vr.ViewName); Assert.IsAssignableFrom <AddressDTO>(vr.Model); }
public void TestDelete() { var options = TestDbContext.TestDbInitalizer("TestingDeleteAddressController"); using (var dbcreate = TestDbContext.CreateTestDb(options)) { _AC = new AddressController(); _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(dbcreate); var newAddy = new AddressApiModel { Key = new Guid("566e1a61-c283-4d33-9b9b-9a981393cf2b"), Street = "123 Unit Test St", City = "Arlington", StateProvince = "TX", PostalCode = "76019", Country = "US" }; var result = _AC.Post(newAddy); Assert.IsType <OkObjectResult>(result); result = _AC.Delete(newAddy.Key); Assert.IsType <OkObjectResult>(result); } }
public void TestControllerHelperDatabase() { var options = TestDbContext.TestDbInitalizer("TestingDeleteAddressController"); using (var dbcreate = TestDbContext.CreateTestDb(options)) { _AC = new AddressController(); _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(dbcreate); var CityState = new AddressApiModel { Key = Guid.NewGuid(), Street = "1560 Broadway St.", City = "Denver", StateProvince = "CO", PostalCode = "80112", Country = "US", }; var postres = _AC.Post(CityState); var getres = _AC._addressHelper.Get(); var dbresult = dbcreate.Addresses.ToList(); var result = _AC.Delete(dbresult.FirstOrDefault().Key); Assert.NotNull(getres); Assert.Equal("denver".ToUpper(), dbresult.FirstOrDefault().City.ToUpper()); Assert.IsType <OkObjectResult>(postres); Assert.IsType <OkObjectResult>(result); } }
public void RemoveAddress_ServiceReturnException_ReturnInternalServerError() { AddressService.ResetCalls(); var addressId = 2315; long clientId = 1; var exceptionMessage = "some exception message"; AddressService.Setup(x => x.RemoveAddress(clientId, addressId)).Throws(new Exception(exceptionMessage)); var controller = new AddressController(AddressService.Object, Logger.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; controller.ControllerContext.HttpContext.Items.Add("clientId", clientId); var actionResult = controller.Delete(addressId); var result = actionResult as OkObjectResult; var result1 = actionResult as ObjectResult; AddressService.Verify(x => x.RemoveAddress(clientId, addressId), Times.Once); Assert.IsTrue(result == null); Assert.IsTrue(result1 != null); Assert.AreEqual(result1.StatusCode, 500); Assert.AreEqual(result1.Value, exceptionMessage); }
public void RemoveAddress_Fail_ReturnOkAndFalse() { AddressService.ResetCalls(); var addressId = 2315; long clientId = 1; AddressService.Setup(x => x.RemoveAddress(clientId, addressId)).Returns(false); var controller = new AddressController(AddressService.Object, Logger.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; controller.ControllerContext.HttpContext.Items.Add("clientId", clientId); var actionResult = controller.Delete(addressId); var result = actionResult as OkObjectResult; AddressService.Verify(x => x.RemoveAddress(clientId, addressId), Times.Once); Assert.AreEqual(result.StatusCode, 200); Assert.AreEqual(result.Value, false); }
public void DeleteByIdDeletsFromRepo() { testRepo.data.Add(a); testRepo.data.Add(b); testRepo.data.Add(c); Assert.AreEqual(3, testRepo.data.Count); controller.Delete(1); Assert.AreEqual(2, testRepo.data.Count); }
public void DeleteAddress() { // Arrange AddressController controller = new AddressController(); var actResult = controller.Delete(1); // Act var result = actResult as OkNegotiatedContentResult <bool>; // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Content == true); }
public async Task ShouldNotDeleteAddressIfNotExists() { var addressRepository = Substitute.For <IRepository <Address, Guid> >(); var addressDataProvider = Substitute.For <IAddressDataProvider>(); var addressFactory = new AddressFactory(); Guid entityId = Guid.NewGuid(); addressRepository.Get(entityId).Returns(default(Address)); AddressController addressController = new AddressController(addressRepository, addressDataProvider, new AddressFactory(), Substitute.For <IMeterReadDataProvider>()); await addressController.Delete(entityId); addressRepository.Received(0).Delete(entityId); }
public async void Delete_Errors() { AddressControllerMockFacade mock = new AddressControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); AddressController controller = new AddressController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async Task ShouldDeleteAddressIfExists() { var addressRepository = Substitute.For <IRepository <Address, Guid> >(); var addressDataProvider = Substitute.For <IAddressDataProvider>(); var addressFactory = new AddressFactory(); var addressEntity = addressFactory.Create(new AddressFactoryInput() { City = "test", Street = "test", HomeNumber = "test", StreetNumber = "test", Id = Guid.NewGuid() }); addressRepository.Get(addressEntity.Id).Returns(addressEntity); AddressController addressController = new AddressController(addressRepository, addressDataProvider, addressFactory, Substitute.For <IMeterReadDataProvider>()); await addressController.Delete(addressEntity.Id); addressRepository.Received(1).Delete(addressEntity.Id); }
public void Address_Controller_Delete_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { AddressController addressController = new AddressController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(addressController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, addressController.DatabaseType); Address addressLast = new Address(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; AddressService addressService = new AddressService(query, db, ContactID); addressLast = (from c in db.Addresses select c).FirstOrDefault(); } // ok with Address info IHttpActionResult jsonRet = addressController.GetAddressWithID(addressLast.AddressID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Address> Ret = jsonRet as OkNegotiatedContentResult <Address>; Address addressRet = Ret.Content; Assert.AreEqual(addressLast.AddressID, addressRet.AddressID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return newly added Address addressRet.AddressID = 0; addressController.Request = new System.Net.Http.HttpRequestMessage(); addressController.Request.RequestUri = new System.Uri("http://localhost:5000/api/address"); IHttpActionResult jsonRet3 = addressController.Post(addressRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <Address> addressRet3 = jsonRet3 as CreatedNegotiatedContentResult <Address>; Assert.IsNotNull(addressRet3); Address address = addressRet3.Content; BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); // Delete to return success IHttpActionResult jsonRet2 = addressController.Delete(addressRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Address> addressRet2 = jsonRet2 as OkNegotiatedContentResult <Address>; Assert.IsNotNull(addressRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Delete to return CSSPError because AddressID of 0 does not exist addressRet.AddressID = 0; IHttpActionResult jsonRet4 = addressController.Delete(addressRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <Address> addressRet4 = jsonRet4 as OkNegotiatedContentResult <Address>; Assert.IsNull(addressRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest4); } } }