示例#1
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 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 void RemoveExistingProducerByProducerId()
        {
            Producer tempProducer = producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(),
                                                                   ObjectFactory.CreateDefaultAddress(),
                                                                   ObjectFactory.CreateEmptyContact());

            EntityHelper.SetEntityId(tempProducer, ProducerId);

            int beforeProducersCount = producerCollection.Producers.Count();

            producerCollection.RemoveProducer(ProducerId);
            int afterProducersCount = producerCollection.Producers.Count();

            Assert.True(afterProducersCount == beforeProducersCount - 1);
        }
示例#5
0
        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);
        }
示例#6
0
        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 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();
        }
示例#8
0
        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);
        }
示例#9
0
        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 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);

            context.DeleteOnCommit(producer);
            context.DeleteOnCommit(producerCollection);
            context.DeleteOnCommit(notification);

            await context.SaveChangesAsync();
        }
        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();
        }