public void TestResetKeysSingleEntityAlternativeNotReset()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <OwnedWithKeyDbContext>();

            using (var context = new OwnedWithKeyDbContext(options))
            {
                var entity = new User
                {
                    UserId = 123,
                    Email  = "Hello"
                };

                //ATTEMPT
                var config = new DataResetterConfig {
                    DoNotResetAlternativeKey = true
                };
                var resetter = new DataResetter(context, config);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.UserId.ShouldEqual(0);
                entity.Email.ShouldEqual("Hello");
            }
        }
        public void TestResetKeysSingleEntityAnonymiseOwnAnonymiser()
        {
            //SETUP
            string MyAnonymiser(AnonymiserData data, object objectInstance)
            {
                return("My Replacement text");
            }

            var options = SqliteInMemory.CreateOptions <BookContext>();

            using (var context = new BookContext(options))
            {
                var entity = new Author {
                    Name = "Test"
                };

                //ATTEMPT
                var config = new DataResetterConfig
                {
                    AnonymiserFunc = MyAnonymiser
                };
                config.AddToAnonymiseList <Author>(x => x.Name, "Name");
                var resetter = new DataResetter(context, config);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.Name.ShouldEqual("My Replacement text");
            }
        }
        public void TestResetKeysSingleEntityNonEntityClassBad()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <BookContext>();

            using (var context = new BookContext(options))
            {
                var entity = new User();

                //ATTEMPT
                var resetter = new DataResetter(context);
                var ex       = Assert.Throws <InvalidOperationException>(() => resetter.ResetKeysSingleEntity(entity));

                //VERIFY
                ex.Message.ShouldEqual("The class User is not a class that the provided DbContext knows about.");
            }
        }
        public void TestResetKeysSingleEntityPrivateSetter()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SpecializedDbContext>();

            using (var context = new SpecializedDbContext(options))
            {
                var entity = new AllTypesEntity();
                entity.SetId(123);

                //ATTEMPT
                var resetter = new DataResetter(context);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.Id.ShouldEqual(0);
            }
        }
        public void TestResetKeysSingleEntityPkOnly()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <BookContext>();

            using (var context = new BookContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
                var entity = context.Books.First();

                //ATTEMPT
                var resetter = new DataResetter(context);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.BookId.ShouldEqual(0);
            }
        }
        public void TestResetKeysSingleEntityAnonymiseNameAsEmail()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <BookContext>();

            using (var context = new BookContext(options))
            {
                var entity = new Author {
                    Name = "Test"
                };

                //ATTEMPT
                var config = new DataResetterConfig();
                config.AddToAnonymiseList <Author>(x => x.Name, "Email");
                var resetter = new DataResetter(context, config);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.Name.ShouldEndWith(DataResetterConfig.EmailSuffix);
            }
        }
        public void TestResetKeysSingleEntityAnonymiseNameMinLength()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <BookContext>();

            using (var context = new BookContext(options))
            {
                var entity = new Author {
                    Name = "Test"
                };

                //ATTEMPT
                var config = new DataResetterConfig();
                config.AddToAnonymiseList <Author>(x => x.Name, "Name:Min=100");
                var resetter = new DataResetter(context, config);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.Name.Length.ShouldBeInRange(100, 140);
            }
        }