public void WHEN_AddressId_is_Null_SHOULD_throw_ArgumentException() { //Arrange var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>(); var param = new SetDefaultAddressParam { Scope = GetRandom.String(32), CustomerId = Guid.NewGuid(), }; //Act var ex = Assert.ThrowsAsync <ArgumentException>(() => customerAddressViewService.SetDefaultAddressAsync(param)); //Assert ex.Message.Should().ContainEquivalentOf("AddressId"); }
public void WHEN_Scope_is_Empty_SHOULD_throw_ArgumentException(string scope) { //Arrange var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>(); var param = new SetDefaultAddressParam { Scope = scope, CustomerId = Guid.NewGuid(), AddressId = Guid.NewGuid() }; //Act var ex = Assert.ThrowsAsync <ArgumentException>(() => customerAddressViewService.SetDefaultAddressAsync(param)); //Assert ex.Message.Should().ContainEquivalentOf("Scope"); }
/// <summary> /// Set default Address for the given customer /// </summary> /// <param name="param">Service call params <see cref="SetDefaultAddressParam"/></param> /// <returns> /// The status representing a possible cause of errors. /// </returns> public virtual async Task <SetDefaultAddressStatusViewModel> SetDefaultAddressAsync(SetDefaultAddressParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.AddressId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.AddressId)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var address = await AddressRepository.GetAddressByIdAsync(param.AddressId).ConfigureAwait(false); if (address == null) { return(null); } if (!await EnsureAddressBelongsToCustomer(param.CustomerId, param.Scope, address.Id).ConfigureAwait(false)) { return(null); } address.IsPreferredShipping = true; address.IsPreferredBilling = true; await CustomerAddressRepository.UpdateAddressAsync(param.CustomerId, address).ConfigureAwait(false); return(new SetDefaultAddressStatusViewModel()); }