public async void UpdateAddress_GivenAddressToUpdate_ContextShouldContainUpdatedAddress() { using (var database = new DatabaseWrapper()) { var context = database.WeeeContext; var country = await context.Countries.SingleAsync(c => c.Name == "France"); var aatfAddress = AddressHelper.GetAatfAddress(database); var dataAccess = new AatfSiteDataAccess(context, A.Fake <IGenericDataAccess>()); var returnData = await CreateWeeeReusedSite(dataAccess, aatfAddress, database); var oldAddress = (context.WeeeReusedSite .Where(t => t.WeeeReused.ReturnId == returnData.Item1 && t.WeeeReused.Aatf.Id == returnData.Item2).FirstOrDefault()).Address; var newAddress = new SiteAddressData("Site1", "Address11", "Address21", "Town1", "County1", "PO12ST341", country.Id, country.Name); var newCountry = await context.Countries.SingleAsync(c => c.Name == "Germany"); await dataAccess.Update(oldAddress, newAddress, newCountry); AssertUpdated(context, returnData, newAddress, newCountry); } }
public async void IndexGet_GivenValidViewModel_MapperIsCalled() { var organisationId = Guid.NewGuid(); var returnId = Guid.NewGuid(); var aatfId = Guid.NewGuid(); var siteId = Guid.NewGuid(); var siteAddressData = new SiteAddressData("TEST", "TEST", "TEST", "TEST", "TEST", "TEST", Guid.NewGuid(), "TEST") { Id = siteId }; var addressTonnage = new AddressTonnageSummary() { AddressData = new List <SiteAddressData>() { siteAddressData } }; A.CallTo(() => apiClient.SendAsync(A <string> ._, A <GetAatfSite> .That.Matches(w => w.AatfId == aatfId && w.ReturnId == returnId))).Returns(addressTonnage); await controller.Index(organisationId, returnId, aatfId, siteId); A.CallTo(() => mapper.Map(A <ReturnAndAatfToReusedRemoveSiteViewModelMapTransfer> .That.Matches(t => t.OrganisationId == organisationId && t.ReturnId == returnId && t.AatfId == aatfId && t.SiteId == siteAddressData.Id))).MustHaveHappened(Repeated.Exactly.Once); }
public string CreateLongAddress(SiteAddressData address) { string siteAddressLong = address.Address1; if (address.Address2 != null) { siteAddressLong += ",<br/>" + address.Address2; } siteAddressLong += ",<br/>" + address.TownOrCity; if (address.CountyOrRegion != null) { siteAddressLong += ",<br/>" + address.CountyOrRegion; } if (address.Postcode != null) { siteAddressLong += ",<br/>" + address.Postcode; } siteAddressLong += ",<br/>" + address.CountryName; return(siteAddressLong); }
public void Map_GivenValidSource_PropertiesShouldBeMapped() { var orgId = Guid.NewGuid(); var aatfId = Guid.NewGuid(); var returnId = Guid.NewGuid(); var siteId = Guid.NewGuid(); var siteAddress = "SITE ADDRESS"; var site = new SiteAddressData("TEST NAME", "TEST", "TEST", "TEST", "TEST", "TEST", Guid.NewGuid(), "TEST"); var transfer = new ReturnAndAatfToReusedRemoveSiteViewModelMapTransfer() { ReturnId = returnId, AatfId = aatfId, OrganisationId = orgId, SiteAddress = siteAddress, SiteId = siteId, Site = site }; var result = mapper.Map(transfer); result.OrganisationId.Should().Be(orgId); result.ReturnId.Should().Be(returnId); result.AatfId.Should().Be(aatfId); result.SiteAddress.Should().Be(siteAddress); result.Site.Should().Be(site); result.SiteId.Should().Be(siteId); result.SiteAddressName.Should().Be(site.Name); }
public void Map_GivenSiteAdddressHasBeenSupplied_AddressPropertiesShouldBeMapped() { var id = Guid.NewGuid(); var siteAddress = new SiteAddressData() { Id = id }; var addressSummary = new AddressTonnageSummary { AddressData = new List <SiteAddressData> { siteAddress } }; var source = new SiteAddressDataToReusedOffSiteCreateSiteViewModelMapTransfer() { AatfId = Guid.NewGuid(), OrganisationId = Guid.NewGuid(), ReturnId = Guid.NewGuid(), Countries = new List <CountryData>(), SiteId = id, ReturnedSites = addressSummary }; var result = mapper.Map(source); result.SiteId.Should().Be(source.SiteId); result.AddressData.Should().BeSameAs(siteAddress); result.AddressData.Countries.Should().BeSameAs(source.Countries); }
public async void IndexGet_GivenValidViewModel_BreadcrumbShouldBeSet() { var organisationId = Guid.NewGuid(); var siteId = Guid.NewGuid(); const string orgName = "orgName"; var @return = A.Fake <ReturnData>(); var quarterData = new Quarter(2019, QuarterType.Q1); var quarterWindow = QuarterWindowTestHelper.GetDefaultQuarterWindow(); var aatfInfo = A.Fake <AatfData>(); var aatfId = Guid.NewGuid(); const string reportingQuarter = "2019 Q1 Jan - Mar"; const string reportingPeriod = "Test (WEE/QW1234RE/ATF)"; @return.Quarter = quarterData; @return.QuarterWindow = quarterWindow; const string aatfName = "Test"; aatfInfo.ApprovalNumber = "WEE/QW1234RE/ATF"; var siteAddressData = new SiteAddressData("TEST", "TEST", "TEST", "TEST", "TEST", "TEST", Guid.NewGuid(), "TEST") { Id = siteId }; var addressTonnage = new AddressTonnageSummary() { AddressData = new List <SiteAddressData>() { siteAddressData } }; A.CallTo(() => apiClient.SendAsync(A <string> ._, A <GetAatfSite> .Ignored)).Returns(addressTonnage); A.CallTo(() => cache.FetchOrganisationName(organisationId)).Returns(orgName); A.CallTo(() => apiClient.SendAsync(A <string> ._, A <GetReturn> ._)).Returns(@return); A.CallTo(() => cache.FetchAatfData(organisationId, aatfId)).Returns(aatfInfo); A.CallTo(() => aatfInfo.Name).Returns(aatfName); await controller.Index(organisationId, A.Dummy <Guid>(), aatfId, siteId); breadcrumb.ExternalActivity.Should().Be(BreadCrumbConstant.AatfReturn); breadcrumb.ExternalOrganisation.Should().Be(orgName); breadcrumb.OrganisationId.Should().Be(organisationId); Assert.Contains(reportingQuarter, breadcrumb.QuarterDisplayInfo); Assert.Contains(reportingPeriod, breadcrumb.AatfDisplayInfo); }
public void AddressConcatenate_OnAddressDataWithAllowedNulls_ReturnsCorrectlyFormattedAddress() { var addressData = new SiteAddressData( "Name", "Address1", null, "Town", null, null, A.Dummy <Guid>(), "Country"); var result = addressUtilities.AddressConcatenate(addressData); result.Should().Be("Address1, Town, Country"); }
public void AddressConcatenate_OnAddressData_ReturnsCorrectlyFormattedAddress() { var addressData = new SiteAddressData( "Name", "Address1", "Address2", "Town", "County", "PO12 3ST", A.Dummy <Guid>(), "Country"); var result = addressUtilities.AddressConcatenate(addressData); result.Should().Be("Address1, Address2, Town, County, PO12 3ST, Country"); }
public void Update_GivenNewAddressData_SaveChangesAsyncShouldBeCalled() { var oldSite = A.Fake <AatfAddress>(); var newSite = new SiteAddressData(); var country = A.Fake <Country>(); dataAccess.Update(oldSite, newSite, country); A.CallTo(() => oldSite.UpdateAddress( newSite.Name, newSite.Address1, newSite.Address2, newSite.TownOrCity, newSite.CountyOrRegion, newSite.Postcode, country)).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }
public void CreateLongAddress_WithoutOptionalFields_ReturnsCorrectAddress() { SiteAddressData address = new SiteAddressData() { Name = "Name", Address1 = "Address 1", TownOrCity = "Town", CountryName = "Country" }; string expected = "Address 1,<br/>Town,<br/>Country"; ReusedOffSiteSummaryListViewModel viewModel = new ReusedOffSiteSummaryListViewModel(); string result = viewModel.CreateLongAddress(address); Assert.Equal(expected, result); }
public async Task <Guid> HandleAsync(EditSentOnAatfSite message) { authorization.EnsureCanAccessExternalArea(); var siteCountry = await organisationDetailsDataAccess.FetchCountryAsync(message.SiteAddressData.CountryId); var existingSiteAddress = await genericDataAccess.GetById <AatfAddress>(message.SiteAddressData.Id); var siteAddress = new SiteAddressData() { Name = message.SiteAddressData.Name, Address1 = message.SiteAddressData.Address1, Address2 = message.SiteAddressData.Address2, TownOrCity = message.SiteAddressData.TownOrCity, CountyOrRegion = message.SiteAddressData.CountyOrRegion, Postcode = message.SiteAddressData.Postcode, CountryName = message.SiteAddressData.CountryName, CountryId = message.SiteAddressData.CountryId }; await offSiteDataAccess.Update(existingSiteAddress, siteAddress, siteCountry); var operatorCountry = await organisationDetailsDataAccess.FetchCountryAsync(message.OperatorAddressData.CountryId); var existingOperatorAddress = await genericDataAccess.GetById <AatfAddress>(message.OperatorAddressData.Id); var operatorAddress = new OperatorAddressData() { Name = message.OperatorAddressData.Name, Address1 = message.OperatorAddressData.Address1, Address2 = message.OperatorAddressData.Address2, TownOrCity = message.OperatorAddressData.TownOrCity, CountyOrRegion = message.OperatorAddressData.CountyOrRegion, Postcode = message.OperatorAddressData.Postcode, CountryName = message.OperatorAddressData.CountryName, CountryId = message.OperatorAddressData.CountryId }; await offSiteDataAccess.Update(existingOperatorAddress, operatorAddress, operatorCountry); return(message.WeeeSentOnId); }
public async void IndexGet_GivenValidViewModel_ViewResultIsReturnedCorrectly() { var organisationId = Guid.NewGuid(); var returnId = Guid.NewGuid(); var aatfId = Guid.NewGuid(); var siteId = Guid.NewGuid(); var siteAddressData = new SiteAddressData("TEST", "TEST", "TEST", "TEST", "TEST", "TEST", Guid.NewGuid(), "TEST") { Id = siteId }; var addressTonnage = new AddressTonnageSummary() { AddressData = new List <SiteAddressData>() { siteAddressData } }; var viewModel = new ReusedRemoveSiteViewModel() { OrganisationId = organisationId, ReturnId = returnId, AatfId = aatfId, SiteAddress = controller.GenerateAddress(siteAddressData), SiteId = siteAddressData.Id, Site = siteAddressData }; A.CallTo(() => apiClient.SendAsync(A <string> ._, A <GetAatfSite> .That.Matches(w => w.AatfId == aatfId && w.ReturnId == returnId))).Returns(addressTonnage); A.CallTo(() => mapper.Map(A <ReturnAndAatfToReusedRemoveSiteViewModelMapTransfer> ._)).Returns(viewModel); var result = await controller.Index(organisationId, returnId, aatfId, siteId) as ViewResult; result.Model.Should().BeEquivalentTo(viewModel); }
private static void AssertUpdated(WeeeContext context, Tuple <Guid, Guid> returnData, SiteAddressData newAddress, Domain.Country newCountry) { var updatedAddress = (context.WeeeReusedSite .Where(t => t.WeeeReused.ReturnId == returnData.Item1 && t.WeeeReused.Aatf.Id == returnData.Item2).FirstOrDefault()).Address; updatedAddress.Should().NotBeNull(); updatedAddress.Name.Should().NotBeNullOrEmpty(); updatedAddress.Name.Should().Be(newAddress.Name); updatedAddress.Address1.Should().NotBeNullOrEmpty(); updatedAddress.Address1.Should().Be(newAddress.Address1); updatedAddress.Address2.Should().Be(newAddress.Address2); updatedAddress.TownOrCity.Should().NotBeNullOrEmpty(); updatedAddress.TownOrCity.Should().Be(newAddress.TownOrCity); updatedAddress.CountyOrRegion.Should().Be(newAddress.CountyOrRegion); updatedAddress.Postcode.Should().Be(newAddress.Postcode); updatedAddress.CountryId.Should().NotBeEmpty(); updatedAddress.CountryId.Should().Be(newCountry.Id); }