예제 #1
0
        public void UpdatePackagingInfoReplacesItems()
        {
            var notification = new NotificationApplication(Guid.NewGuid(), NotificationType.Recovery,
                                                           UKCompetentAuthority.England, 0);

            var packagingInfos = new List <PackagingInfo>
            {
                PackagingInfo.CreateOtherPackagingInfo("package description"),
                PackagingInfo.CreatePackagingInfo(PackagingType.Bag)
            };

            var newPackagingInfos = new List <PackagingInfo>
            {
                PackagingInfo.CreatePackagingInfo(PackagingType.Box),
                PackagingInfo.CreatePackagingInfo(PackagingType.Bulk)
            };

            notification.SetPackagingInfo(packagingInfos);

            notification.SetPackagingInfo(newPackagingInfos);

            Assert.Collection(notification.PackagingInfos,
                              item => Assert.Equal(notification.PackagingInfos.ElementAt(0).PackagingType, PackagingType.Box),
                              item => Assert.Equal(notification.PackagingInfos.ElementAt(1).PackagingType, PackagingType.Bulk));
        }
예제 #2
0
        public void CantCreateOtherWithoutDescription()
        {
            Action createPackagingInfo =
                () => PackagingInfo.CreatePackagingInfo(PackagingType.Other);

            Assert.Throws <InvalidOperationException>(createPackagingInfo);
        }
예제 #3
0
        public async Task CanAddPackagingInfo()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            context.NotificationApplications.Add(notification);

            notification.SetPackagingInfo(new[] { PackagingInfo.CreatePackagingInfo(PackagingType.Bag) });

            await context.SaveChangesAsync();

            Assert.Equal(1, notification.PackagingInfos.Count());
        }
        public PrenotificationInvalidPackagingTypeRuleTests()
        {
            this.repo = A.Fake <INotificationApplicationRepository>();

            notificationApplication = new NotificationApplication(Guid.NewGuid(), Core.Shared.NotificationType.Disposal, Core.Notification.UKCompetentAuthority.England, 1);

            var packagingInfos = new List <PackagingInfo>()
            {
                PackagingInfo.CreatePackagingInfo(Core.PackagingType.PackagingType.Bag),
                PackagingInfo.CreatePackagingInfo(Core.PackagingType.PackagingType.Box)
            };

            notificationApplication.SetPackagingInfo(packagingInfos);

            A.CallTo(() => repo.GetById(notificationId)).Returns(notificationApplication);

            rule = new PrenotificationInvalidPackagingTypeRule(repo);
        }
예제 #5
0
        public async Task UpdatePackagingInfoReplacesItems()
        {
            var packagingInfo1 = PackagingInfo.CreatePackagingInfo(PackagingType.Bag);
            var packagingInfo2 = PackagingInfo.CreatePackagingInfo(PackagingType.Box);
            var packagingInfo3 = PackagingInfo.CreatePackagingInfo(PackagingType.Bulk);

            try
            {
                context.NotificationApplications.Add(notification);

                await context.SaveChangesAsync();

                notificationId = notification.Id;

                notification.SetPackagingInfo(new[]
                {
                    packagingInfo1
                });

                await context.SaveChangesAsync();

                var count =
                    await context.Database.SqlQuery <int>(
                        "select count(id) from notification.PackagingInfo where NotificationId = @id",
                        new SqlParameter("id", notificationId)).SingleAsync();

                Assert.Equal(1, count);

                notification.SetPackagingInfo(new[]
                {
                    packagingInfo2,
                    packagingInfo3
                });

                await context.SaveChangesAsync();

                count =
                    await context.Database.SqlQuery <int>(
                        "select count(id) from notification.PackagingInfo where NotificationId = @id",
                        new SqlParameter("id", notificationId)).SingleAsync();

                Assert.Equal(2, count);
            }
            finally
            {
                if (context.Entry(packagingInfo1).State != EntityState.Detached)
                {
                    context.Entry(packagingInfo1).State = EntityState.Deleted;
                }

                if (context.Entry(packagingInfo2).State != EntityState.Detached)
                {
                    context.Entry(packagingInfo2).State = EntityState.Deleted;
                }

                if (context.Entry(packagingInfo3).State != EntityState.Detached)
                {
                    context.Entry(packagingInfo3).State = EntityState.Deleted;
                }

                context.DeleteOnCommit(notification);

                context.SaveChanges();
            }
        }