public void ProducersCanOnlyHaveOneSiteOfExport()
        {
            producerCollection.SetProducerAsSiteOfExport(anyProducer1.Id);

            var siteOfExportCount = producerCollection.Producers.Count(p => p.IsSiteOfExport);

            Assert.Equal(1, siteOfExportCount);
        }
Example #2
0
        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 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();
        }