public async Task CopyAsync(IwsContext context, Guid notificationSourceId, Guid notificationDestinationId) { var originalProducers = await context.Producers .AsNoTracking() .Include("ProducersCollection") .SingleOrDefaultAsync(p => p.NotificationId == notificationSourceId); var newProducers = new ProducerCollection(notificationDestinationId); if (originalProducers != null) { foreach (var producer in originalProducers.Producers) { var newProducer = newProducers.AddProducer(producer.Business, producer.Address, producer.Contact); if (producer.IsSiteOfExport) { typeof(Producer).GetProperty("IsSiteOfExport") .SetValue(newProducer, true, null); } } } context.Producers.Add(newProducers); }
public async Task CanModifyProducer() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country"); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = new Contact(string.Empty, String.Empty, String.Empty, String.Empty); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); var producer = producerCollection.AddProducer(business, address, contact); context.Producers.Add(producerCollection); await context.SaveChangesAsync(); var updateProducer = producerCollection.GetProducer(producer.Id); var newAddress = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country"); updateProducer.Address = newAddress; await context.SaveChangesAsync(); var newAddress1 = await context.Database.SqlQuery <string>("SELECT [Address1] FROM [Notification].[Producer] WHERE Id = @id", new SqlParameter("id", producer.Id)).SingleAsync(); Assert.Equal("address1", newAddress1); }
public async Task CanRemoveProducerOtherThanSiteOfExporter() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = ObjectFactory.CreateDefaultAddress(); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = ObjectFactory.CreateEmptyContact(); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); var producer = producerCollection.AddProducer(business, address, contact); var anotherProducer = producerCollection.AddProducer(business, address, contact); context.NotificationApplications.Add(notification); context.Producers.Add(producerCollection); await context.SaveChangesAsync(); Assert.True(producerCollection.Producers.Count() == 2); producerCollection.SetProducerAsSiteOfExport(producer.Id); await context.SaveChangesAsync(); producerCollection.RemoveProducer(anotherProducer.Id); await context.SaveChangesAsync(); Assert.True(producerCollection.Producers.Count() == 1); }
public async Task CanAddMultipleProducers() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = ObjectFactory.CreateDefaultAddress(); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = ObjectFactory.CreateEmptyContact(); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); for (int i = 0; i < 5; i++) { producerCollection.AddProducer(business, address, contact); } context.Producers.Add(producerCollection); await context.SaveChangesAsync(); var dbProducerCollection = context.Producers.Single(p => p.NotificationId == notification.Id); Assert.True(producerCollection.Producers.Count() == dbProducerCollection.Producers.Count()); }
public async Task GetNotificationProducerByIdChecksAuthorization() { var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery, UKCompetentAuthority.England, 20181); context.NotificationApplications.Add(notification); context.SaveChanges(); var notificationId = notification.Id; var producerCollection = new ProducerCollection(notificationId); producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(), ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact()); context.Producers.Add(producerCollection); context.SaveChanges(); var repository = new ProducerRepository(context, notificationApplicationAuthorization); await repository.GetByNotificationId(notificationId); A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened(); context.DeleteOnCommit(producerCollection); await context.SaveChangesAsync(); context.DeleteOnCommit(notification); await context.SaveChangesAsync(); }
public async Task CopyAsync(IwsContext context, Guid notificationSourceId, Guid notificationDestinationId) { var originalProducers = await context.Producers .AsNoTracking() .Include("ProducersCollection") .SingleOrDefaultAsync(p => p.NotificationId == notificationSourceId); var newProducers = new ProducerCollection(notificationDestinationId); if (originalProducers != null) { foreach (var producer in originalProducers.Producers) { var newProducer = newProducers.AddProducer(producer.Business, producer.Address, producer.Contact); if (producer.IsSiteOfExport) { typeof(Producer).GetProperty("IsSiteOfExport") .SetValue(newProducer, true, null); } } } context.Producers.Add(newProducers); }
public async Task <Guid> HandleAsync(CreateLegacyNotificationApplication message) { var notification = await notificationApplicationFactory.CreateLegacy( message.NotificationType, message.CompetentAuthority, message.Number); notificationApplicationRepository.Add(notification); await context.SaveChangesAsync(); var facilityCollection = new FacilityCollection(notification.Id); var carrierCollection = new CarrierCollection(notification.Id); var producerCollection = new ProducerCollection(notification.Id); facilityRepository.Add(facilityCollection); carrierRepository.Add(carrierCollection); producerRepository.Add(producerCollection); await context.SaveChangesAsync(); return(notification.Id); }
public async Task CanAddMultipleProducers() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = ObjectFactory.CreateDefaultAddress(); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = ObjectFactory.CreateEmptyContact(); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); for (int i = 0; i < 5; i++) { producerCollection.AddProducer(business, address, contact); } Assert.True(producerCollection.Producers.Count() == 5); context.DeleteOnCommit(notification); context.DeleteOnCommit(producerCollection); await context.SaveChangesAsync(); }
private void AddProducers(Guid sourceId, Guid destinationId) { var sourceProducers = new ProducerCollection(sourceId); var destinationProducers = new ProducerCollection(destinationId); context.Producers.Add(sourceProducers); context.Producers.Add(destinationProducers); }
public NotificationProducerTests() { producerCollection = new ProducerCollection(new Guid("784C0850-7FBA-401D-BA0F-64600B36583C")); anyProducer1 = producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(), ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact()); anyProducer2 = producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(), ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact()); EntityHelper.SetEntityId(anyProducer1, new Guid("18C7F135-AE7F-4F1E-B6F9-076C12224292")); EntityHelper.SetEntityId(anyProducer2, new Guid("58318441-922C-4453-8A96-D5AA2E3D9B5A")); }
public NotificationProducerTests() { producerCollection = new ProducerCollection(new Guid("784C0850-7FBA-401D-BA0F-64600B36583C")); anyProducer1 = producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(), ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact()); anyProducer2 = producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(), ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact()); EntityHelper.SetEntityId(anyProducer1, new Guid("18C7F135-AE7F-4F1E-B6F9-076C12224292")); EntityHelper.SetEntityId(anyProducer2, new Guid("58318441-922C-4453-8A96-D5AA2E3D9B5A")); }
public ProducerBlock(IList<MergeField> mergeFields, NotificationApplication notification, ProducerCollection producerCollection) { CorrespondingMergeFields = MergeFieldLocator.GetCorrespondingFieldsForBlock(mergeFields, TypeName); var numberOfProducers = producerCollection.Producers.Count(); var processText = notification.WasteGenerationProcess; var isProcessAnnexAttached = notification.IsWasteGenerationProcessAttached; data = producerCollection.Producers.Select(p => new ProducerViewModel(p, numberOfProducers, processText, isProcessAnnexAttached)).ToList(); // The producers annex contains a set of different merge fields for producer marked as Site of Export. AnnexMergeFields = MergeFieldLocator.GetAnnexMergeFields(mergeFields, TypeName); ((List<MergeField>)AnnexMergeFields).AddRange(MergeFieldLocator.GetAnnexMergeFields(mergeFields, SiteOfExport)); ((List<MergeField>)AnnexMergeFields).AddRange(MergeFieldLocator.GetAnnexMergeFields(mergeFields, PoGtext)); }
public async Task <Guid> HandleAsync(CreateNotificationApplication command) { var authority = command.CompetentAuthority; var notification = await notificationApplicationFactory.CreateNew(command.NotificationType, authority); notificationApplicationRepository.Add(notification); await context.SaveChangesAsync(); var facilityCollection = new FacilityCollection(notification.Id); var carrierCollection = new CarrierCollection(notification.Id); var producerCollection = new ProducerCollection(notification.Id); facilityRepository.Add(facilityCollection); carrierRepository.Add(carrierCollection); producerRepository.Add(producerCollection); await context.SaveChangesAsync(); return(notification.Id); }
public async Task CanModifyProducer() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country"); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = new Contact(string.Empty, String.Empty, String.Empty, String.Empty); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); var producer = producerCollection.AddProducer(business, address, contact); context.Producers.Add(producerCollection); await context.SaveChangesAsync(); var updateProducer = producerCollection.GetProducer(producer.Id); var newAddress = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country"); updateProducer.Address = newAddress; await context.SaveChangesAsync(); var newAddress1 = await context.Database.SqlQuery<string>("SELECT [Address1] FROM [Notification].[Producer] WHERE Id = @id", new SqlParameter("id", producer.Id)).SingleAsync(); Assert.Equal("address1", newAddress1); context.DeleteOnCommit(producer); context.DeleteOnCommit(producerCollection); context.DeleteOnCommit(notification); await context.SaveChangesAsync(); }
public void Add(ProducerCollection producerCollection) { context.Producers.Add(producerCollection); }
public void Add(ProducerCollection producerCollection) { context.Producers.Add(producerCollection); }
public async Task CanRemoveProducerOtherThanSiteOfExporter() { var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0); var address = ObjectFactory.CreateDefaultAddress(); var business = ObjectFactory.CreateEmptyProducerBusiness(); var contact = ObjectFactory.CreateEmptyContact(); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); var producerCollection = new ProducerCollection(notification.Id); var producer = producerCollection.AddProducer(business, address, contact); var anotherProducer = producerCollection.AddProducer(business, address, contact); context.NotificationApplications.Add(notification); await context.SaveChangesAsync(); Assert.True(producerCollection.Producers.Count() == 2); producerCollection.SetProducerAsSiteOfExport(producer.Id); await context.SaveChangesAsync(); producerCollection.RemoveProducer(anotherProducer.Id); await context.SaveChangesAsync(); Assert.True(producerCollection.Producers.Count() == 1); context.DeleteOnCommit(notification); context.DeleteOnCommit(producerCollection); await context.SaveChangesAsync(); }
public ProducerBlock(IList <MergeField> mergeFields, NotificationApplication notification, ProducerCollection producerCollection) { CorrespondingMergeFields = MergeFieldLocator.GetCorrespondingFieldsForBlock(mergeFields, TypeName); var numberOfProducers = producerCollection.Producers.Count(); var processText = notification.WasteGenerationProcess; var isProcessAnnexAttached = notification.IsWasteGenerationProcessAttached; data = producerCollection.Producers.Select(p => new ProducerViewModel(p, numberOfProducers, processText, isProcessAnnexAttached)).ToList(); // The producers annex contains a set of different merge fields for producer marked as Site of Export. AnnexMergeFields = MergeFieldLocator.GetAnnexMergeFields(mergeFields, TypeName); ((List <MergeField>)AnnexMergeFields).AddRange(MergeFieldLocator.GetAnnexMergeFields(mergeFields, SiteOfExport)); ((List <MergeField>)AnnexMergeFields).AddRange(MergeFieldLocator.GetAnnexMergeFields(mergeFields, PoGtext)); }
public MovementProducerBlock(IList<MergeField> mergeFields, NotificationApplication notification, ProducerCollection producerCollection) : base(mergeFields, notification, producerCollection) { properties = PropertyHelper.GetPropertiesForViewModel(typeof(ProducerViewModel)); }
public MovementProducerBlock(IList <MergeField> mergeFields, NotificationApplication notification, ProducerCollection producerCollection) : base(mergeFields, notification, producerCollection) { properties = PropertyHelper.GetPropertiesForViewModel(typeof(ProducerViewModel)); }