public async Task HandleAsync_WithContactDetailsChange_SendNotificationTrue_SendsChangeEmail() { // Arrange var authorization = A.Dummy <IWeeeAuthorization>(); var dataAccess = A.Fake <IOrganisationDetailsDataAccess>(); var weeeEmailService = A.Dummy <IWeeeEmailService>(); var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService); var contact = new Contact("FirstName", "LastName", "Position"); var countryId = Guid.NewGuid(); var country = new Country(countryId, "Country"); var schemeAddress = new Address("Address1", "Address2", "TownOrCity", "CountyOrRegion", "Postcode", country, "Telephone", "Email"); var scheme = A.Fake <Scheme>(); A.CallTo(() => scheme.Contact).Returns(contact); A.CallTo(() => scheme.Address).Returns(schemeAddress); A.CallTo(() => scheme.SchemeName).Returns("SchemeName"); A.CallTo(() => scheme.CompetentAuthority).Returns(new UKCompetentAuthority(Guid.NewGuid(), "name", "abb", country, "Email", null)); A.CallTo(() => dataAccess.FetchSchemeAsync(A <Guid> ._)).Returns(scheme); A.CallTo(() => dataAccess.FetchCountryAsync(countryId)).Returns(country); var newContactDetails = new ContactData { FirstName = "New FirstName", LastName = "New LastName", Position = "New Position" }; var newSchemeAddress = new AddressData { Address1 = "Address1", Address2 = "Address2", CountryId = countryId, CountyOrRegion = "CountyOrRegion", Email = "Email", Postcode = "Postcode", Telephone = "Telephone", TownOrCity = "TownOrCity" }; var organisationData = new SchemeData() { Contact = newContactDetails, Address = newSchemeAddress }; var request = new UpdateSchemeContactDetails(organisationData, true); // Act await handler.HandleAsync(request); // Assert A.CallTo(() => weeeEmailService.SendOrganisationContactDetailsChanged("Email", "SchemeName", EntityType.Pcs)) .MustHaveHappened(); }
public void HandleAsync_GivenSchemeWithOrganisationIdNotFound_ArgumentExceptionExpected_AndEmailMustNotBeSent() { // Arrange var schemeData = new SchemeData { OrganisationId = Guid.NewGuid() }; var request = new UpdateSchemeContactDetails(schemeData); var authorization = A.Dummy <IWeeeAuthorization>(); var dataAccess = A.Fake <IOrganisationDetailsDataAccess>(); var weeeEmailService = A.Dummy <IWeeeEmailService>(); var scheme = A.Dummy <Scheme>(); A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).Returns((Scheme)null); var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService); // Act Func <Task> action = async() => await handler.HandleAsync(request); // Assert A.CallTo(() => weeeEmailService.SendOrganisationContactDetailsChanged(A <string> ._, A <string> ._, A <EntityType> ._)) .MustNotHaveHappened(); action.Should().Throw <ArgumentException>(); }
public async Task HandleAsync_WithValidData_FetchesSchemeAndUpdatesAndSaves() { // Arrange var schemeData = new SchemeData { Id = Guid.NewGuid(), OrganisationId = Guid.NewGuid(), Contact = new ContactData { FirstName = "FirstName", LastName = "LastName", Position = "Position" }, Address = new Core.Shared.AddressData { Address1 = "Address1", Address2 = "Address2", TownOrCity = "Town", CountyOrRegion = "County", Postcode = "Postcode", CountryId = Guid.NewGuid(), Telephone = "012345678", Email = "*****@*****.**" } }; var request = new UpdateSchemeContactDetails(schemeData); var authorization = A.Dummy <IWeeeAuthorization>(); var dataAccess = A.Fake <IOrganisationDetailsDataAccess>(); var weeeEmailService = A.Dummy <IWeeeEmailService>(); var scheme = A.Dummy <Scheme>(); A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).Returns(scheme); var country = new Country(schemeData.Address.CountryId, "Name"); A.CallTo(() => dataAccess.FetchCountryAsync(schemeData.Address.CountryId)).Returns(country); var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService); // Act var result = await handler.HandleAsync(request); // Assert A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).MustHaveHappened(Repeated.Exactly.Once); Assert.Equal("FirstName", scheme.Contact.FirstName); Assert.Equal("LastName", scheme.Contact.LastName); Assert.Equal("Position", scheme.Contact.Position); Assert.Equal("Address1", scheme.Address.Address1); Assert.Equal("Address2", scheme.Address.Address2); Assert.Equal("Town", scheme.Address.TownOrCity); Assert.Equal("County", scheme.Address.CountyOrRegion); Assert.Equal("Postcode", scheme.Address.Postcode); Assert.Equal(schemeData.Address.CountryId, scheme.Address.Country.Id); Assert.Equal("012345678", scheme.Address.Telephone); Assert.Equal("*****@*****.**", scheme.Address.Email); A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened(Repeated.Exactly.Once); }
public async Task HandleAsync_WithNonInternalUserOrOrganisationUser_ThrowsSecurityException() { // Arrange var authorizationBuilder = new AuthorizationBuilder() .DenyInternalOrOrganisationAccess(); var authorization = authorizationBuilder.Build(); var dataAccess = A.Dummy <IOrganisationDetailsDataAccess>(); var weeeEmailService = A.Dummy <IWeeeEmailService>(); var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService); var request = new UpdateSchemeContactDetails(new SchemeData() { Id = Guid.NewGuid() }, false); // Act, Assert await Assert.ThrowsAsync <SecurityException>(() => handler.HandleAsync(request)); }