public void NotSupportedPropertyType_PropertyMappingExceptionWithNotSupportedException()
        {
            AssertHelper.TryCatch(tryAction: () =>
            {
                // Arrange
                var entityData = new List <EntityData>
                {
                    new EntityData
                    {
                        EntityName = "CherrySeed.Test.Models.EntityWithNotSupportedTypeProperty",
                        Objects    = new List <Dictionary <string, string> >
                        {
                            new Dictionary <string, string>
                            {
                                { "UintProperty", "123" }
                            }
                        }
                    }
                };

                // Act
                _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), new EmptyRepository(), cfg =>
                {
                    cfg.ForEntity <EntityWithNotSupportedTypeProperty>();
                });
            }, catchAction: ex =>
            {
                // Assert
                AssertHelper.AssertExceptionWithMessage(ex, typeof(PropertyTransformationException), "Transformation of Property 'UintProperty' of type 'CherrySeed.Test.Models.EntityWithNotSupportedTypeProperty' to value '123' failed");
                AssertHelper.AssertExceptionWithMessage(ex.InnerException, typeof(NotSupportedException), "Transformation of type 'System.UInt32' is currently not supported");
            });
        }
        public void IncorrectPropertyType_PropertyMappingExceptionWithFormatException()
        {
            AssertHelper.TryCatch(tryAction: () =>
            {
                // Arrange
                var entityData = new List <EntityData>
                {
                    new EntityData
                    {
                        EntityName = "CherrySeed.Test.Models.EntityWithSimpleProperties",
                        Objects    = new List <Dictionary <string, string> >
                        {
                            new Dictionary <string, string>
                            {
                                { "MyInteger", "NotANumber" }
                            }
                        }
                    }
                };

                // Act
                _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), new EmptyRepository(), cfg =>
                {
                    cfg.ForEntity <EntityWithSimpleProperties>();
                });
            }, catchAction: ex =>
            {
                // Assert
                AssertHelper.AssertExceptionWithMessage(ex, typeof(PropertyTransformationException), "Transformation of Property 'MyInteger' of type 'CherrySeed.Test.Models.EntityWithSimpleProperties' to value 'NotANumber' failed");
                AssertHelper.AssertException(ex.InnerException, typeof(FormatException));
            });
        }
        public void TransformSimplePropertyTypesWithCustomEmptyStringBeforeAddingCustomStringTransformation()
        {
            AssertHelper.TryCatch(() =>
            {
                // Arrange
                var entityData = new List <EntityData>
                {
                    new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties",
                                          "MyString")
                    .WithEntity("Sample text")
                    .Build()
                };

                // Act
                var repository = new InMemoryRepository();
                _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
                {
                    cfg.WithEmptyStringMarker("%%");
                    cfg.AddTypeTransformation(typeof(string), new CustomTypeTransformation <string>("Other sample text"));
                    cfg.ForEntity <EntityWithSimpleProperties>();
                });
            }, ex =>
            {
                // Assert
                AssertHelper.AssertExceptionWithMessage(ex, typeof(ConfigurationException), "EmptyString marker can not be set, because the string transformation logic is overriden from you.");
            });
        }
Beispiel #4
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");
            });
        }
Beispiel #5
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");
            });
        }