public async void GetAddressShouldReturnNull() { // Arrange (create a moq repo and add a test address) var mockLogger = new Mock <ILogger <AddressController> >(); var mockAddressLogic = new Mock <IAddressLogic>(); var options = TestDbContext.TestDbInitalizer("CanCreate"); using var database = TestDbContext.CreateTestDb(options); var mapper = new Mapper(); var logger = new NullLogger <Address.DataAccess.DataAccess>(); var dataAccess = new Address.DataAccess.DataAccess(database, mapper, logger); var test = new AddressController(dataAccess, mockAddressLogic.Object, mockLogger.Object); var newAddy = new Address.Api.Models.AddressModel { Id = new Guid("566e1a61-c283-4d33-9b9b-9a981393cf2b"), Street = "ooooooo", City = "oooooo", State = "Texas", Country = "US", ZipCode = "76010" }; // act (send address to database) var address = await test.GetAddress(newAddy); // Assert correct address was received Assert.Null(address.Value); }
public void HomesController_GetPropertyUsingInvalidGuid_ReturnBadRequest() { AddressController addressController = new AddressController(_findAddress); var requestType = addressController.GetAddress(Guid.NewGuid()); BadRequestObjectResult badRequest = (BadRequestObjectResult)requestType.Result; Assert.True(badRequest.StatusCode == 400); }
public void AddressController_GetAddressUsingGuid_ReturnAddreessFirstLive() { AddressController addressController = new AddressController(_findAddress); var requestType = addressController.GetAddress(Guid.Parse("e3944055-9df7-4ad7-b36a-84bcd00ee1b4")); OkObjectResult okRequest = requestType.Result as OkObjectResult; IAddress result = (IAddress)okRequest.Value; Assert.NotNull(result); }
public void GetAddressesByIdTest() { // Arrange AddressController controller = new AddressController(); // Act var result = controller.GetAddress(5); // Assert Assert.IsNotNull(result); }
public void TestGetAddress() { // db is empty using (var context = new ProTickDatabaseContext(dbOptions)) { var dbm = new DatabaseQueryManager(context); var converter = new ResourceDTOConverter(dbm); var controller = new AddressController(context, converter, dbm); Assert.Throws <DatabaseEntryNotFoundException>( () => controller.GetAddress(0) ); } // seeding DB using (var context = new ProTickDatabaseContext(dbOptions)) { DbContextSeeder.SeedFull(context); } // db is Test-Ready using (var context = new ProTickDatabaseContext(dbOptions)) { var dbm = new DatabaseQueryManager(context); var converter = new ResourceDTOConverter(dbm); var controller = new AddressController(context, converter, dbm); var expected = DbContextSeeder.GetSeededAddressDTOs( 3 ) .ToList(); expected[0].Should().BeEquivalentTo(controller.GetAddress(1)); expected[1].Should().BeEquivalentTo(controller.GetAddress(2)); expected[2].Should().BeEquivalentTo(controller.GetAddress(3)); } }
public async Task GetAddressOfContact_ShouldReturnAddressList() { var tenentid = Guid.NewGuid(); var userid = Guid.NewGuid(); var contactid = Guid.NewGuid(); var contact = new Contact(); List <Address> addresses = new List <Address>(); _contactRepo.Setup(y => y.FirstOrDefault(x => x.Id == contactid && x.User.Id == userid && x.User.Tenent.Id == tenentid)).ReturnsAsync(contact); _addressRepo.Setup(y => y.GetListBasedOnCondition(x => x.Contact.Id == contactid && x.Contact.User.Id == userid && x.Contact.User.Tenent.Id == tenentid)).ReturnsAsync(addresses); var result = await _addressController.GetAddress(tenentid, userid, contactid); Assert.Equal(addresses, result.Value); }
public void GetAddressByIdTest() { int id = 1; string Address1 = "Test"; string Address2 = "Test"; string City = "Test"; string ZipCode = "71000"; bool isDeleted = false; int AddressTypeId = 1; int CreatedByUserId = 1; var address = new AddressDto { AddressId = id, Address1 = Address1, Address2 = Address2, City = City, ZipCode = ZipCode, AddressTypeId = AddressTypeId, CreatedByUserId = CreatedByUserId, IsDeleted = isDeleted, DateCreated = DateTime.Now, DateModified = DateTime.Now }; var mockRepo = new Mock <IAddressRepository>(); mockRepo.Setup(x => x.GetAddressById(It.Is <int>(q => q == 1))).Returns(address); var addressManipulation = new AddressManipulation(mockRepo.Object); var controller = new AddressController(addressManipulation); var result = controller.GetAddress(1); var okObjectResult = result as OkObjectResult; Assert.NotNull(okObjectResult); var model = okObjectResult.Value as AddressDto; Assert.NotNull(model); output.WriteLine(model.Address1); Assert.IsType <OkObjectResult>(result); }
protected void Page_Load(object sender, System.EventArgs e) { try { // Get the navigation settings _nav = new CustomerNavigation(Request.QueryString); if (!Null.IsNull(dataSource)) { _addressID = (int)dataSource; _nav.AddressID = _addressID.ToString(); } else { _addressID = int.Parse(_nav.AddressID); } if (!Page.IsPostBack) { // Load country & region lists loadCountryList(); loadRegionList(); // Set delete confirmation cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');"); // Are we editing or creating new item? if (!Null.IsNull(_addressID)) { AddressController controller = new AddressController(); AddressInfo address = controller.GetAddress(_addressID); if (address != null) { cmdDelete.Visible = true; txtDescription.Text = address.Description; txtName.Text = address.Name; txtAddress1.Text = address.Address1; txtAddress2.Text = address.Address2; txtCity.Text = address.City; cboCountry.SelectedValue = address.CountryCode; cboRegion.SelectedValue = address.RegionCode; txtPostalCode.Text = address.PostalCode; txtPhone1.Text = address.Phone1; txtPhone2.Text = address.Phone2; chkPrimary.Checked = address.PrimaryAddress; } } } } catch(Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }