コード例 #1
0
        public bool UpdateCustomerAddress(string applicationReference, string customerReference, string addressReference, Address address)
        {
            Check.If(applicationReference).IsNotNullOrEmpty();
            Check.If(customerReference).IsNotNullOrEmpty();
            Check.If(addressReference).IsNotNullOrEmpty();
            Check.If(address).IsNotNull();

            return _addressRepository.UpdateCustomerAddressForApplication(applicationReference, customerReference,
                addressReference, address);
        }
コード例 #2
0
        public void AddressMapper_DoesNotMap_DateDeleted()
        {
            //Arrange
            var dateDeleted = DateTime.UtcNow;
            var address1 = new Address { DateDeleted = dateDeleted };
            var address2 = new Address { DateDeleted = DateTime.MinValue };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.DateDeleted.Should().Be(dateDeleted);
        }
コード例 #3
0
        public void AddressMapper_DoesNotMap_AddressReference()
        {
            //Arrange
            const string reference = "ABCD1234";
            var address1 = new Address { AddressReference = reference };
            var address2 = new Address { AddressReference = string.Empty };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.AddressReference.Should().Be(reference);
        }
コード例 #4
0
        public void AddressMapper_DoesNotMap_AddressId()
        {
            //Arrange
            const int id = 123;
            var address1 = new Address { AddressId = id };
            var address2 = new Address { AddressId = 0 };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.AddressId.Should().Be(id);
        }
コード例 #5
0
        public string CreateCustomerAddress(string applicationReference, string customerReference, Address address)
        {
            Check.If(applicationReference).IsNotNullOrEmpty();
            Check.If(customerReference).IsNotNullOrEmpty();
            Check.If(address).IsNotNull();

            if (!string.IsNullOrEmpty(address.AddressReference))
            {
                return null;
            }

            var result = _addressRepository.CreateCustomerAddressForApplication(applicationReference, customerReference,
                address.CreateReference(_referenceGenerator));

            return result ? address.AddressReference : null;
        }
コード例 #6
0
        public bool CreateCustomerAddressForApplication(string applicationReference, string customerReference,
            Address address)
        {
            if (string.IsNullOrEmpty(applicationReference) || string.IsNullOrEmpty(customerReference))
                return false;

            var application =
                _applicationsContext.Applications.Active()
                    .Include(c => c.Customers.Select(a => a.Addresses))
                    .FirstOrDefault(a => a.ApplicationReference == applicationReference);

            var customer =
                application?.Customers.Active().FirstOrDefault(c => c.CustomerReference == customerReference);

            if (customer == null)
                return false;

            customer.Addresses.Add(address);

            return _applicationsContext.SaveChanges() > 0;
        }
コード例 #7
0
        public void AddressMapper_Maps_AddressLine2()
        {
            //Arrange
            const string addressLine2 = "This is a test value";
            var address1 = new Address { AddressLine2 = string.Empty };
            var address2 = new Address { AddressLine2 = addressLine2 };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.AddressLine2.Should().Be(addressLine2);
        }
コード例 #8
0
        public void AddressMapper_Maps_Udprn()
        {
            //Arrange
            const string udrpn = "This is a test value";
            var address1 = new Address { Udprn = string.Empty };
            var address2 = new Address { Udprn = udrpn };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.Udprn.Should().Be(udrpn);
        }
コード例 #9
0
        public void AddressMapper_Maps_ToDate()
        {
            //Arrange
            var toDate = DateTime.UtcNow;
            var address1 = new Address { ToDate = DateTime.MinValue };
            var address2 = new Address { ToDate = toDate };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.ToDate.Should().Be(toDate);
        }
コード例 #10
0
        public void AddressMapper_Maps_Postcode()
        {
            //Arrange
            const string postcode = "This is a test value";
            var address1 = new Address { Postcode = string.Empty };
            var address2 = new Address { Postcode = postcode };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.Postcode.Should().Be(postcode);
        }
コード例 #11
0
        public void AddressMapper_Maps_Owned()
        {
            //Arrange
            var address1 = new Address { Owned = false};
            var address2 = new Address { Owned = true};

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.Owned.Should().Be(true);
        }
コード例 #12
0
        public void AddressMapper_Maps_FromDate()
        {
            //Arrange
            var dateFrom = DateTime.UtcNow;
            var address1 = new Address { DateCreated = DateTime.MinValue };
            var address2 = new Address { DateCreated = dateFrom };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.FromDate.Should().Be(dateFrom);
        }
コード例 #13
0
        public void AddressMapper_Maps_DoNotUse()
        {
            //Arrange
            var address1 = new Address { DoNotUse = false };
            var address2 = new Address { DoNotUse = true };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.DoNotUse.Should().Be(true);
        }
コード例 #14
0
        public void AddressMapper_Maps_County()
        {
            //Arrange
            const string county = "This is a test value";
            var address1 = new Address { County = string.Empty };
            var address2 = new Address { County = county };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.County.Should().Be(county);
        }
コード例 #15
0
        public void AddressMapper_Maps_AddressType()
        {
            //Arrange
            const AddressType type = AddressType.Personal;
            var address1 = new Address { AddressType = AddressType.Unknown };
            var address2 = new Address { AddressType = type };

            //Act
            _mapper.Map(address2, address1);

            //Assert
            address1.AddressType.Should().Be(type);
        }
コード例 #16
0
        public bool UpdateCustomerAddressForApplication(string applicationReference, string customerReference,
            string addressReference,
            Address address)
        {
            var application =
                _applicationsContext.Applications.Active()
                    .Include(c => c.Customers.Select(a => a.Addresses))
                    .FirstOrDefault(a => a.ApplicationReference == applicationReference);

            var existingCustomer =
                application?.Customers.Active().FirstOrDefault(c => c.CustomerReference == customerReference);

            var existingAddress =
                existingCustomer?.Addresses.Active().FirstOrDefault(a => a.AddressReference == addressReference);

            if (existingAddress == null)
                return false;

            var isDirty = _addressMapper.Map(address, existingAddress);

            return !isDirty || _applicationsContext.SaveChanges() > 0;
        }