Beispiel #1
0
        public async Task CanRemoveFacilityOtherThanActualSiteOfTreatment()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);

            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            var facility        = facilityCollection.AddFacility(business, address, contact);
            var anotherFacility = facilityCollection.AddFacility(business, address, contact);

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 2);

            facilityCollection.SetFacilityAsSiteOfTreatment(facility.Id);
            await context.SaveChangesAsync();

            facilityCollection.RemoveFacility(anotherFacility.Id);
            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 1);
        }
Beispiel #2
0
        private FacilityCollection GetFacilityCollection()
        {
            var facilityCollection = new FacilityCollection(notificationId);

            facilityCollection.AddFacility(new TestableBusiness(), new TestableAddress(), new TestableContact());
            facilityCollection.AddFacility(new TestableBusiness(), new TestableAddress(), new TestableContact());
            return(facilityCollection);
        }
        public NotificationFacilityTests()
        {
            notification = new NotificationApplication(Guid.NewGuid(), NotificationType.Recovery,
                           UKCompetentAuthority.England, 0);

            facilityCollection = new FacilityCollection(notification.Id);

            facility1 = facilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(),
                        ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());
            facility2 = facilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(),
                        ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());
        }
Beispiel #4
0
        public NotificationFacilityTests()
        {
            notification = new NotificationApplication(Guid.NewGuid(), NotificationType.Recovery,
                                                       UKCompetentAuthority.England, 0);

            facilityCollection = new FacilityCollection(notification.Id);

            facility1 = facilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(),
                                                       ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());
            facility2 = facilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(),
                                                       ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());
        }
        public async Task CopyAsync(IwsContext context, Guid notificationSourceId, Guid notificationDestinationId)
        {
            var originalFacilities = await context.Facilities
                .AsNoTracking()
                .Include("FacilitiesCollection")
                .SingleOrDefaultAsync(f => f.NotificationId == notificationSourceId);

            var newFacilities = new FacilityCollection(notificationDestinationId);

            if (originalFacilities != null)
            {
                foreach (var facility in originalFacilities.Facilities)
                {
                    var newFacility = newFacilities.AddFacility(facility.Business, facility.Address, facility.Contact);

                    if (facility.IsActualSiteOfTreatment)
                    {
                        typeof(Facility).GetProperty("IsActualSiteOfTreatment")
                            .SetValue(newFacility, true, null);
                    }
                }

                typeof(FacilityCollection).GetProperty("AllFacilitiesPreconsented")
                    .SetValue(newFacilities, originalFacilities.AllFacilitiesPreconsented, null);
            }

            context.Facilities.Add(newFacilities);
        }
Beispiel #6
0
        public async Task CopyAsync(IwsContext context, Guid notificationSourceId, Guid notificationDestinationId)
        {
            var originalFacilities = await context.Facilities
                                     .AsNoTracking()
                                     .Include("FacilitiesCollection")
                                     .SingleOrDefaultAsync(f => f.NotificationId == notificationSourceId);

            var newFacilities = new FacilityCollection(notificationDestinationId);

            if (originalFacilities != null)
            {
                foreach (var facility in originalFacilities.Facilities)
                {
                    var newFacility = newFacilities.AddFacility(facility.Business, facility.Address, facility.Contact);

                    if (facility.IsActualSiteOfTreatment)
                    {
                        typeof(Facility).GetProperty("IsActualSiteOfTreatment")
                        .SetValue(newFacility, true, null);
                    }
                }

                typeof(FacilityCollection).GetProperty("AllFacilitiesPreconsented")
                .SetValue(newFacilities, originalFacilities.AllFacilitiesPreconsented, null);
            }

            context.Facilities.Add(newFacilities);
        }
Beispiel #7
0
        public async Task CanAddMultipleFacilities()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);

            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            for (int i = 0; i < 5; i++)
            {
                facilityCollection.AddFacility(business, address, contact);
            }

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 5);
        }
Beispiel #8
0
        public void HasMultipleFacilities_SingleFacility_IsFalse()
        {
            var newFacilityCollection = new FacilityCollection(notification.Id);

            newFacilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(), ObjectFactory.CreateDefaultAddress(),
                                              ObjectFactory.CreateEmptyContact());

            Assert.False(newFacilityCollection.HasMultipleFacilities);
        }
Beispiel #9
0
        public async Task GetNotificationShipmentInfoByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var shipmentsInfo = new ShipmentInfo(notificationId, new ShipmentPeriod(DateTime.Now, DateTime.Now.AddDays(10), true), 10, new ShipmentQuantity(1.0m, ShipmentQuantityUnits.Tonnes));
            var assessment    = new NotificationAssessment(notificationId);

            ObjectInstantiator <NotificationAssessment> .SetProperty(x => x.Status, NotificationStatus.NotificationReceived, assessment);

            var facilityCollection = new FacilityCollection(notificationId);

            facilityCollection.AddFacility(ObjectFactory.CreateEmptyProducerBusiness(),
                                           ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());

            context.ShipmentInfos.Add(shipmentsInfo);
            context.NotificationAssessments.Add(assessment);
            context.Facilities.Add(facilityCollection);
            context.SaveChanges();

            var repository = new ShipmentInfoRepository(context,
                                                        notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            await repository.GetIntendedShipmentDataByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened(Repeated.Exactly.Times(2));

            context.DeleteOnCommit(shipmentsInfo);
            context.DeleteOnCommit(assessment);
            context.DeleteOnCommit(facilityCollection);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Beispiel #10
0
        public void RemoveExistingFacilityByFacilityId()
        {
            Facility tempFacility = facilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(),
                                                                   ObjectFactory.CreateDefaultAddress(),
                                                                   ObjectFactory.CreateEmptyContact());

            EntityHelper.SetEntityId(tempFacility, FacilityId);

            int beforeFacilitiesCount = facilityCollection.Facilities.Count();

            facilityCollection.RemoveFacility(FacilityId);
            int afterFacilitiesCount = facilityCollection.Facilities.Count();

            Assert.True(afterFacilitiesCount == beforeFacilitiesCount - 1);
        }
 private FacilityCollection GetFacilityCollection()
 {
     var facilityCollection = new FacilityCollection(notificationId);
     facilityCollection.AddFacility(new TestableBusiness(), new TestableAddress(), new TestableContact());
     facilityCollection.AddFacility(new TestableBusiness(), new TestableAddress(), new TestableContact());
     return facilityCollection;
 }
        public async Task CanRemoveFacilityOtherThanActualSiteOfTreatment()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0);

            var address = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);
            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            var facility = facilityCollection.AddFacility(business, address, contact);
            var anotherFacility = facilityCollection.AddFacility(business, address, contact);

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 2);

            facilityCollection.SetFacilityAsSiteOfTreatment(facility.Id);
            await context.SaveChangesAsync();

            facilityCollection.RemoveFacility(anotherFacility.Id);
            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 1);

            context.DeleteOnCommit(facilityCollection);
            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public async Task CanAddMultipleFacilities()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                UKCompetentAuthority.England, 0);

            var address = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);
            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            for (int i = 0; i < 5; i++)
            {
                facilityCollection.AddFacility(business, address, contact);
            }

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 5);

            context.DeleteOnCommit(facilityCollection);
            context.DeleteOnCommit(notification);

            await context.SaveChangesAsync();
        }
        public void HasMultipleFacilities_SingleFacility_IsFalse()
        {
            var newFacilityCollection = new FacilityCollection(notification.Id);
            newFacilityCollection.AddFacility(ObjectFactory.CreateEmptyBusiness(), ObjectFactory.CreateDefaultAddress(),
                ObjectFactory.CreateEmptyContact());

            Assert.False(newFacilityCollection.HasMultipleFacilities);
        }