public void TestStreet2_MaxLength() { var model = new OrganizationAddressBindingModel { IsPrimary = true, AddressTypeId = AddressType.Business.Id, CityId = 1, CountryId = 2, DivisionId = 3, Id = 4, PostalCode = "12345", Street1 = "street1", Street2 = "street2", Street3 = "street3", }; var results = new List <ValidationResult>(); var actual = Validator.TryValidateObject(model, new ValidationContext(model), results, true); Assert.IsTrue(actual); Assert.AreEqual(0, results.Count); model.Street2 = new String('a', Location.STREET_MAX_LENGTH + 1); actual = Validator.TryValidateObject(model, new ValidationContext(model), results, true); Assert.IsFalse(actual); Assert.AreEqual(1, results.Count); Assert.AreEqual("Street2", results.First().MemberNames.First()); }
public async Task TestPostAddressAsync() { var model = new OrganizationAddressBindingModel(); var response = await controller.PostAddressAsync(1, model); addressHandler.Verify(x => x.HandleAdditionalAddressAsync <Organization>(It.IsAny <AddressBindingModelBase <Organization> >(), It.IsAny <ApiController>()), Times.Once()); }
public void TestToAdditionalAddress() { var model = new OrganizationAddressBindingModel { IsPrimary = true, AddressTypeId = AddressType.Business.Id, CityId = 1, CountryId = 2, DivisionId = 3, Id = 4, PostalCode = "12345", Street1 = "street1", Street2 = "street2", Street3 = "street3", }; var user = new User(1); var instance = model.ToAdditionalAddress(user); Assert.AreEqual(model.IsPrimary, instance.IsPrimary); Assert.AreEqual(model.AddressTypeId, instance.AddressTypeId); Assert.AreEqual(model.CityId, instance.CityId); Assert.AreEqual(model.CountryId, instance.CountryId); Assert.AreEqual(model.DivisionId, instance.DivisionId); Assert.IsNull(instance.LocationName); Assert.AreEqual(model.PostalCode, instance.PostalCode); Assert.AreEqual(model.Street1, instance.Street1); Assert.AreEqual(model.Street2, instance.Street2); Assert.AreEqual(model.Street3, instance.Street3); Assert.AreEqual(model.Id, instance.GetAddressableEntityId()); Assert.IsTrue(Object.ReferenceEquals(user, instance.Create.User)); }
public async Task TestHandleAdditionalAddressAsync_ModelIsInvalid() { controller.ModelState.AddModelError("key", "error"); var organizationAddress = new OrganizationAddressBindingModel(); var response = await handler.HandleAdditionalAddressAsync <Organization>(organizationAddress, controller); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public async Task TestHandleAdditionalAddressAsync() { userProvider.Setup(x => x.GetCurrentUser()).Returns(new DebugWebApiUser()); userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(new Business.Service.User(1)); locationService.Setup(x => x.GetAddressByIdAsync(It.IsAny <int>())).ReturnsAsync(new Business.Queries.Models.Admin.AddressDTO()); locationService.Setup(x => x.CreateAsync(It.IsAny <AdditionalAddress <Organization> >())).ReturnsAsync(new Address()); var organizationAddress = new OrganizationAddressBindingModel(); organizationAddress.AddressTypeId = AddressType.Business.Id; var response = await handler.HandleAdditionalAddressAsync <Organization>(organizationAddress, controller); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <AddressDTO>)); userProvider.Verify(x => x.GetCurrentUser(), Times.Once()); userProvider.Verify(x => x.GetBusinessUser(It.IsAny <IWebApiUser>()), Times.Once()); locationService.Verify(x => x.CreateAsync(It.IsAny <AdditionalAddress <Organization> >()), Times.Once()); locationService.Verify(x => x.SaveChangesAsync(), Times.Once()); locationService.Verify(x => x.GetAddressByIdAsync(It.IsAny <int>()), Times.Once()); }
public Task <IHttpActionResult> PostAddressAsync(int organizationId, [FromBody] OrganizationAddressBindingModel model) { return(addressHandler.HandleAdditionalAddressAsync <Organization>(model, this)); }