public async Task ShouldCreateAddressFromAddressDomainObj() { ResetDatabase(); var address = new AddressDomainObj { AddressLine1 = "123 Made-Up-Street Rd", AddressLine2 = "Ste 1,000,000", City = "Anywhere", StateProvinceID = 9, PostalCode = "12345", AddressTypeID = 3, ParentEntityID = 4 }; string jsonAddress = JsonConvert.SerializeObject(address); HttpContent content = new StringContent(jsonAddress, Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"{serviceAddress}{rootAddress}/address", content); Assert.True(response.IsSuccessStatusCode); var jsonResponse = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <AddressDomainObj>(jsonResponse); Assert.Equal(address.AddressLine1, result.AddressLine1); }
public static void Map(this Address entityObj, AddressDomainObj domainObj) { entityObj.AddressID = domainObj.AddressID; entityObj.AddressLine1 = domainObj.AddressLine1; entityObj.AddressLine2 = domainObj.AddressLine2; entityObj.City = domainObj.City; entityObj.StateProvinceID = domainObj.StateProvinceID; entityObj.PostalCode = domainObj.PostalCode; entityObj.SpatialLocation = domainObj.SpatialLocation; }
public async Task ShouldRaiseExceptionDuplicateAddressInAddressDomainObj() { var vendorID = 4; var addressDomainObj = new AddressDomainObj { AddressLine1 = "28 San Marino Ct", City = "Bellingham", StateProvinceID = 79, PostalCode = "98225", AddressTypeID = 3, ParentEntityID = vendorID }; var exception = await Assert.ThrowsAsync <AdventureWorksUniqueIndexException>(() => _addressRepo.CreateAddress(addressDomainObj)); Assert.Equal("Error: There is an existing entity with this address!", exception.Message); }
public async Task ShouldRaiseExceptionAddressDomainObjWithInvalidAddressType() { var vendorID = 4; var addressDomainObj = new AddressDomainObj { AddressLine1 = "123 Made-Up-Street Rd", AddressLine2 = "Ste 1,000,000", City = "Anywhere", StateProvinceID = 9, PostalCode = "12345", AddressTypeID = 987, ParentEntityID = vendorID }; var exception = await Assert.ThrowsAsync <AdventureWorksInvalidAddressTypeException>(() => _addressRepo.CreateAddress(addressDomainObj)); Assert.Equal("Error: Invalid address type detected.", exception.Message); }
public async Task ShouldRaiseExceptionAddressDomainObjWithInvalidParentEntityID() { var vendorID = 4333; var addressDomainObj = new AddressDomainObj { AddressLine1 = "123 Made-Up-Street Rd", AddressLine2 = "Ste 1,000,000", City = "Anywhere", StateProvinceID = 9, PostalCode = "12345", AddressTypeID = 3, ParentEntityID = vendorID }; var exception = await Assert.ThrowsAsync <AdventureWorksInvalidEntityIdException>(() => _addressRepo.CreateAddress(addressDomainObj)); Assert.Equal("Error: Unable to determine the entity that this address belongs to.", exception.Message); }
public async Task ShouldFailToDeleteAddressWithInvalidAddressID() { ResetDatabase(); var address = new AddressDomainObj { AddressID = -1, AddressLine1 = "28 San Marino Ct", City = "Bellingham", StateProvinceID = 79, PostalCode = "98225", AddressTypeID = 3, ParentEntityID = 7 }; var response = await _client.DeleteAsJsonAsync($"{serviceAddress}{rootAddress}/address", address); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public async Task ShouldFailToCreateAddressDueToInvalidStateProvinceID() { ResetDatabase(); var address = new AddressDomainObj { AddressLine1 = "123 Made-Up-Street Rd", AddressLine2 = "Ste 1,000,000", City = "Anywhere", StateProvinceID = 9999, PostalCode = "12345", AddressTypeID = 3, ParentEntityID = 4 }; string jsonAddress = JsonConvert.SerializeObject(address); HttpContent content = new StringContent(jsonAddress, Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"{serviceAddress}{rootAddress}/address", content); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public async Task ShouldCreateOneAddressUsingAddressDomainObj() { var vendorID = 4; var addressDomainObj = new AddressDomainObj { AddressLine1 = "123 Made-Up-Street Rd", AddressLine2 = "Ste 1,000,000", City = "Anywhere", StateProvinceID = 9, PostalCode = "12345", AddressTypeID = 3, ParentEntityID = vendorID }; await _addressRepo.CreateAddress(addressDomainObj); var result = await _addressRepo.GetAddressByID(addressDomainObj.AddressID); Assert.Equal(addressDomainObj.AddressLine1, result.AddressLine1); var addressDomainObjs = await _addressRepo.GetAddresses(vendorID, new AddressParameters { PageNumber = 1, PageSize = 10 }); Assert.Equal(addressDomainObjs[0].AddressLine1, addressDomainObj.AddressLine1); }
public async Task <IActionResult> DeleteVendorAddress([FromBody] AddressDomainObj address) { await _repository.Address.DeleteAddress(address); return(NoContent()); }
public async Task <IActionResult> CreateVendorAddress([FromBody] AddressDomainObj address) { await _repository.Address.CreateAddress(address); return(CreatedAtRoute("GetVendorAddressByID", new { addressID = address.AddressID }, address)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { /*** View models ***/ modelBuilder.Query <PhoneViewModel>().ToQuery(() => PhoneViewModel.FromSql( @"SELECT BusinessEntityID, PhoneNumber, ph.PhoneNumberTypeID, phtype.Name AS PhoneNumberType FROM Person.PersonPhone ph INNER JOIN Person.PhoneNumberType phtype ON ph.PhoneNumberTypeID = phtype.PhoneNumberTypeID" ).AsQueryable()); modelBuilder.Query <PhoneViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <PhoneViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <AddressViewModel>().ToQuery(() => AddressViewModel.FromSql( @"SELECT bea.BusinessEntityID, a.AddressID, AddressLine1, AddressLine2, City, a.StateProvinceID, StateProvinceCode, PostalCode, a.SpatialLocation, CountryRegionCode, bea.AddressTypeID, t.Name AS AddressTypeName FROM Person.Address a INNER JOIN Person.StateProvince st ON a.StateProvinceID = st.StateProvinceID INNER JOIN Person.BusinessEntityAddress bea ON a.AddressID = bea.AddressID INNER JOIN Person.AddressType t ON bea.AddressTypeID = t.AddressTypeID" ).AsQueryable()); modelBuilder.Query <AddressViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <AddressViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <VendorContactViewModel>().ToQuery(() => VendorContactViewModel.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, bec.ContactTypeID, ct.Name AS ContactPosition, bec.BusinessEntityID AS VendorID FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN Person.BusinessEntityContact bec ON pp.BusinessEntityID = bec.PersonID INNER JOIN Person.ContactType ct ON bec.ContactTypeID = ct.ContactTypeID WHERE bec.BusinessEntityID IN (SELECT BusinessEntityID FROM Purchasing.Vendor)" ).AsQueryable()); modelBuilder.Query <VendorContactViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorContactViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <VendorViewModel>().ToQuery(() => VendorViewModel.FromSql( @"SELECT ven.BusinessEntityID, ven.AccountNumber, ven.Name, CAST(ven.CreditRating AS int) AS CreditRating, ven.PreferredVendorStatus AS PreferredVendor, ven.PurchasingWebServiceURL, ven.ActiveFlag AS IsActive FROM Purchasing.Vendor ven" ).AsQueryable()); modelBuilder.Query <VendorViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <EmployeeViewModel>().ToQuery(() => EmployeeViewModel.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, ee.NationalIDNumber, ee.LoginID, ee.JobTitle, ee.BirthDate, ee.MaritalStatus, ee.Gender, ee.HireDate, ee.SalariedFlag AS IsSalaried, ee.VacationHours, ee.SickLeaveHours, ee.CurrentFlag AS IsActive FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN HumanResources.Employee ee ON ee.BusinessEntityID = pp.BusinessEntityID" ).AsQueryable()); modelBuilder.Query <EmployeeViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <EmployeeViewModel>(query => query.Ignore(e => e.ModifiedDate)); /*** Domain objects ***/ // VendorDomainObj modelBuilder.Query <VendorDomainObj>().ToQuery(() => VendorDomainObj.FromSql( @"SELECT ven.BusinessEntityID, ven.AccountNumber, ven.Name, CAST(ven.CreditRating AS int) AS CreditRating, ven.PreferredVendorStatus AS PreferredVendor, ven.PurchasingWebServiceURL, ven.ActiveFlag AS IsActive FROM Purchasing.Vendor ven" ).AsQueryable()); modelBuilder.Query <VendorDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // ContactDomainObj modelBuilder.Query <ContactDomainObj>().ToQuery(() => ContactDomainObj.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, bec.ContactTypeID, bec.BusinessEntityID AS ParentEntityID FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN Person.BusinessEntityContact bec ON pp.BusinessEntityID = bec.PersonID INNER JOIN Person.ContactType ct ON bec.ContactTypeID = ct.ContactTypeID" ).AsQueryable()); modelBuilder.Query <ContactDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <ContactDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // AddressDomainObj modelBuilder.Query <AddressDomainObj>().ToQuery(() => AddressDomainObj.FromSql( @"SELECT a.AddressID, AddressLine1, AddressLine2, City, a.StateProvinceID, PostalCode, a.SpatialLocation, bea.AddressTypeID, bea.BusinessEntityID AS ParentEntityID FROM Person.Address a INNER JOIN Person.StateProvince st ON a.StateProvinceID = st.StateProvinceID INNER JOIN Person.BusinessEntityAddress bea ON a.AddressID = bea.AddressID INNER JOIN Person.AddressType t ON bea.AddressTypeID = t.AddressTypeID" ).AsQueryable()); modelBuilder.Query <AddressDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <AddressDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // EmployeeDomainObj modelBuilder.Query <EmployeeDomainObj>().ToQuery(() => EmployeeDomainObj.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddress, pw.PasswordHash, pw.PasswordSalt, ee.NationalIDNumber, ee.LoginID, ee.JobTitle, ee.BirthDate, ee.MaritalStatus, ee.Gender, ee.HireDate, ee.SalariedFlag AS IsSalaried, ee.VacationHours, ee.SickLeaveHours, ee.CurrentFlag AS IsActive FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN HumanResources.Employee ee ON ee.BusinessEntityID = pp.BusinessEntityID" ).AsQueryable()); modelBuilder.Query <EmployeeDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <EmployeeDomainObj>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.ApplyConfiguration(new BusinessEntityConfig()); modelBuilder.ApplyConfiguration(new AddressConfig()); modelBuilder.ApplyConfiguration(new AddressTypeConfig()); modelBuilder.ApplyConfiguration(new BusinessEntityAddressConfig()); modelBuilder.ApplyConfiguration(new BusinessEntityContactConfig()); modelBuilder.ApplyConfiguration(new ContactTypeConfig()); modelBuilder.ApplyConfiguration(new CountryRegionConfig()); modelBuilder.ApplyConfiguration(new EmailAddressConfig()); modelBuilder.ApplyConfiguration(new PersonConfig()); modelBuilder.ApplyConfiguration(new PersonPhoneConfig()); modelBuilder.ApplyConfiguration(new PasswordConfig()); modelBuilder.ApplyConfiguration(new PhoneNumberTypeConfig()); modelBuilder.ApplyConfiguration(new StateProvinceConfig()); modelBuilder.ApplyConfiguration(new VendorConfig()); modelBuilder.ApplyConfiguration(new SalesTaxRateConfig()); modelBuilder.ApplyConfiguration(new SalesTerritoryConfig()); modelBuilder.ApplyConfiguration(new DepartmentConfig()); modelBuilder.ApplyConfiguration(new EmployeeConfig()); modelBuilder.ApplyConfiguration(new EmployeeDepartmentHistoryConfig()); modelBuilder.ApplyConfiguration(new EmployeePayHistoryConfig()); modelBuilder.ApplyConfiguration(new JobCandidateConfig()); modelBuilder.ApplyConfiguration(new ShiftConfig()); }