public void UpdatePersonLists_2Changes_NonInSubscription_NothingAddedInSubscription_And_NoNotificationCreated(string municipalityCode)
        {
            var dce = new DataChangeEvent[] {
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                },
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                }
            };

            var sub = Utils.CreateCriteriaSubscription(municipalityCode);

            using (var dataContext = new EventBrokerDataContext())
            {
                dataContext.DataChangeEvents.InsertAllOnSubmit(dce);
                dataContext.Subscriptions.InsertOnSubmit(sub);
                dataContext.SubmitChanges();
            }
            using (var dataContext = new EventBrokerDataContext())
            {
                int records            = dataContext.UpdatePersonLists(DateTime.Now, (int)Data.SubscriptionType.SubscriptionTypes.DataChange);
                var subscriptionPerson = dataContext.SubscriptionPersons.Where(sp => sp.SubscriptionId == sub.SubscriptionId).SingleOrDefault();
                Assert.Null(subscriptionPerson);

                var notif = dataContext.EventNotifications.Where(en => en.SubscriptionId == sub.SubscriptionId).SingleOrDefault();
                Assert.Null(notif);
            }
        }
        public void UpdatePersonLists_2Changes_1MovingIn_PersonAdded(string municipalityCode)
        {
            var dce = new DataChangeEvent[] {
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                },
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                }
            };

            var sub = Utils.CreateCriteriaSubscription(municipalityCode);

            sub.SubscriptionCriteriaMatches.Add(new SubscriptionCriteriaMatch()
            {
                SubscriptionCriteriaMatchId = Guid.NewGuid(), DataChangeEvent = dce[0]
            });

            using (var dataContext = new EventBrokerDataContext())
            {
                dataContext.DataChangeEvents.InsertAllOnSubmit(dce);
                dataContext.Subscriptions.InsertOnSubmit(sub);
                dataContext.SubmitChanges();
            }
            using (var dataContext = new EventBrokerDataContext())
            {
                int records             = dataContext.UpdatePersonLists(DateTime.Now, (int)Data.SubscriptionType.SubscriptionTypes.DataChange);
                var subscriptionPersons = dataContext.SubscriptionPersons.Where(sp => sp.SubscriptionId == sub.SubscriptionId && sp.Removed == null).ToArray();
                Assert.AreEqual(1, subscriptionPersons.Length);
                Assert.Null(subscriptionPersons[0].Removed);

                var notif = dataContext.EventNotifications.Where(en => en.SubscriptionId == sub.SubscriptionId).SingleOrDefault();
                Assert.Null(notif);
            }
        }
        public void UpdatePersonLists_2Changes_1MovingOut_PersonRemovedAndNotoficationAdded(string municipalityCode)
        {
            var dce = new DataChangeEvent[] {
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                },
                new DataChangeEvent()
                {
                    PersonRegistrationId = Guid.NewGuid(), DueDate = DateTime.Now, ReceivedDate = DateTime.Now, PersonUuid = Guid.NewGuid(), DataChangeEventId = Guid.NewGuid()
                }
            };

            var sub = Utils.CreateCriteriaSubscription(municipalityCode);

            sub.SubscriptionPersons.Add(new SubscriptionPerson()
            {
                SubscriptionPersonId = Guid.NewGuid(), PersonUuid = dce[0].PersonUuid, Created = DateTime.Now, Removed = null
            });

            using (var dataContext = new EventBrokerDataContext())
            {
                dataContext.DataChangeEvents.InsertAllOnSubmit(dce);
                dataContext.Subscriptions.InsertOnSubmit(sub);
                dataContext.SubmitChanges();
            }
            using (var dataContext = new EventBrokerDataContext())
            {
                int records            = dataContext.UpdatePersonLists(DateTime.Now, (int)Data.SubscriptionType.SubscriptionTypes.DataChange);
                var subscriptionPerson = dataContext.SubscriptionPersons.Where(sp => sp.SubscriptionId == sub.SubscriptionId).Single();
                Assert.NotNull(subscriptionPerson.Removed);

                var notif = dataContext.EventNotifications.Where(en => en.SubscriptionId == sub.SubscriptionId).Single();
                Assert.NotNull(notif.IsLastNotification);
                Assert.True(notif.IsLastNotification.Value);
            }
        }