Example #1
0
        public void RepositoryNotSet_MissingConfigurationException()
        {
            var config = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithDataProvider(new DictionaryDataProvider(new List <EntityData>()));
            });

            Action act = () => config.CreateSeeder();

            act.Should().Throw <MissingConfigurationException>().WithMessage("Repository");
        }
Example #2
0
        public void DataProviderNotSet_MissingConfigurationException()
        {
            var config = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithRepository(new EmptyRepository());
            });

            Action act = () => config.CreateSeeder();

            act.Should().Throw <MissingConfigurationException>().WithMessage("DataProvider");
        }
Example #3
0
        public void InitializeCherrySeedDriver()
        {
            var cherrySeedConfig = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithSpecFlowConfiguration();
                cfg.WithRepository(new EmptyRepository());
                cfg.WithCountryAndProjectEntities();
            });
            var seeder = cherrySeedConfig.CreateSeeder();

            _objectContainer.RegisterInstanceAs(seeder);
        }
Example #4
0
        public void InitAndSeed(IDataProvider dataProvider, IRepository repository,
                                Action <ISeederConfigurationBuilder> entitySettings)
        {
            var config = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithDataProvider(dataProvider);
                cfg.WithRepository(repository);

                entitySettings(cfg);
            });

            _cherrySeeder = config.CreateSeeder();
            _cherrySeeder.Seed();
        }
Example #5
0
        public void RepositoryNotSet_MissingConfigurationException()
        {
            AssertHelper.TryCatch(tryAction: () =>
            {
                var config = new CherrySeedConfiguration(cfg =>
                {
                    cfg.WithDataProvider(new DictionaryDataProvider(new List <EntityData>()));
                });

                config.CreateSeeder();
            }, catchAction: ex =>
            {
                AssertHelper.AssertExceptionWithMessage(ex, typeof(MissingConfigurationException), "Repository");
            });
        }
Example #6
0
        public void DataProviderNotSet_MissingConfigurationException()
        {
            AssertHelper.TryCatch(tryAction: () =>
            {
                var config = new CherrySeedConfiguration(cfg =>
                {
                    cfg.WithRepository(new EmptyRepository());
                });

                config.CreateSeeder();
            }, catchAction: ex =>
            {
                AssertHelper.AssertExceptionWithMessage(ex, typeof(MissingConfigurationException), "DataProvider");
            });
        }
        public void DefaultTest()
        {
            var config = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithDataProvider(new GherkinDataProvider(new GherkinDataProviderConfiguration
                {
                    FilePaths = new List <string> {
                        @"Testfeature.feature"
                    }
                }));

                cfg.WithRepository(new EmptyRepository());
            });

            var seeder = config.CreateSeeder();

            seeder.Seed();
        }
Example #8
0
        public void SeedAndClear_ClearedSuccessfully()
        {
            // Arrange
            var countryTable = ObjectMother.CreateCountryTable(table =>
            {
                table.AddRow("C1", "Austria");
                table.AddRow("C2", "Germany");
            });

            var projectTable = ObjectMother.CreateProjectTable(table =>
            {
                table.AddRow("P1", "Project1", "C1");
                table.AddRow("P2", "Project2", "C2");
            });

            var repository = new InMemoryRepository();
            var cherrySeedConfiguration = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithSpecFlowConfiguration();
                cfg.WithRepository(repository);
                cfg.WithCountryAndProjectEntities();

                cfg.ForEntity <Country>()
                .WithPrimaryKeyIdGenerationInApplicationAsInteger();

                cfg.ForEntity <Project>()
                .WithPrimaryKeyIdGenerationInApplicationAsInteger();
            });

            var cherrySeeder = cherrySeedConfiguration.CreateSeeder();

            cherrySeeder.Seed("Country", countryTable);
            cherrySeeder.Seed("Project", projectTable);

            Assert.AreEqual(4, repository.CountSeededObjects());

            // Act - seeding countries
            cherrySeeder.Clear();
            Assert.AreEqual(0, repository.CountSeededObjects());
        }
Example #9
0
        public void SeedCountryAndProject_SeededSuccessfully()
        {
            // Arrange
            var countryTable = ObjectMother.CreateCountryTable(table =>
            {
                table.AddRow("C1", "Austria");
                table.AddRow("C2", "Germany");
            });

            var projectTable = ObjectMother.CreateProjectTable(table =>
            {
                table.AddRow("P1", "Project1", "C1");
                table.AddRow("P2", "Project2", "C2");
            });

            // Act - seeding countries
            var repository = new InMemoryRepository();
            var cherrySeedConfiguration = new CherrySeedConfiguration(cfg =>
            {
                cfg.WithSpecFlowConfiguration();
                cfg.WithRepository(repository);
                cfg.WithCountryAndProjectEntities();

                cfg.ForEntity <Country>()
                .WithPrimaryKeyIdGenerationInApplicationAsInteger();

                cfg.ForEntity <Project>()
                .WithPrimaryKeyIdGenerationInApplicationAsInteger();
            });

            var cherrySeeder = cherrySeedConfiguration.CreateSeeder();

            cherrySeeder.Seed("Country", countryTable);

            // Assert - countries
            Assert.AreEqual(2, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <Country>());
            EntityAsserts.AssertCountry(repository.GetEntities <Country>()[0], new Country
            {
                Id   = 1,
                Name = "Austria"
            });
            EntityAsserts.AssertCountry(repository.GetEntities <Country>()[1], new Country
            {
                Id   = 2,
                Name = "Germany"
            });

            // Act - seeding projects
            cherrySeeder.Seed("Project", projectTable);

            // Assert - projects
            Assert.AreEqual(4, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <Project>());
            EntityAsserts.AssertProject(repository.GetEntities <Project>()[0], new Project
            {
                Id        = 1,
                Name      = "Project1",
                CountryId = 1
            });
            EntityAsserts.AssertProject(repository.GetEntities <Project>()[1], new Project
            {
                Id        = 2,
                Name      = "Project2",
                CountryId = 2
            });
        }