Пример #1
0
        public void ShouldBeAbleToRemoveSpecificHandler()
        {
            // Arrange
            GlobalSetup.PerformDefaultConfiguration();
            var faultyQuery = new GenericSelectQuery <int>(
                "select count(*) from table_which_does_not_exist;"
                );
            var handler = new SuppressingMySqlExceptionHandler();

            // Act
            Fluently.Configure()
            .WithExceptionHandler(handler);
            Expect(() => QueryExecutor.Execute(faultyQuery))
            .Not.To.Throw();
            Fluently.Configure()
            .WithoutExceptionHandler(handler);
            Expect(() => QueryExecutor.Execute(faultyQuery))
            .To.Throw <MySqlException>();
            Fluently.Configure()
            .WithExceptionHandler(handler);
            // test handler caching
            Expect(() => QueryExecutor.Execute(faultyQuery))
            .Not.To.Throw();
            // Assert
        }
Пример #2
0
        public void ClearShouldClearAllConfig()
        {
            // Arrange
            using (new AutoResetter(() =>
            {
                GlobalSetup.PerformDefaultConfiguration();
                Fluently.Configure().Reset();
            }, GlobalSetup.PerformDefaultConfiguration))
            {
                // Act
                Fluently.Configure()
                .Reset();
                // Assert
                // should remove exception handlers
                Expect(BaseSqlExecutor.ExceptionHandlers)
                .To.Be.Empty();

                // should remove connection factory
                Expect(BaseSqlExecutor.ConnectionFactory)
                .To.Be.Null();

                // should turn off debug for EntityDoesNotExist
                Expect(EntityDoesNotExistException.DebugEnabled)
                .To.Be.False();
            }
        }
Пример #3
0
        public void ShouldRespectNoSnakeCaseOnRequest()
        {
            // Arrange
            GlobalSetup.PerformDefaultConfiguration();
            using var _    = new AutoResetter(DisableSnakeCase, EnableSnakeCase);
            using var conn = GlobalSetup.ConnectToTempDb();
            CreateCaseTestingTableOn(conn);
            var titleCaseValue = GetRandomString(4);
            var snakeCaseValue = GetAnother(titleCaseValue, () => GetRandomString(4));
            var id             = CommandExecutor.Execute(
                new CreateCaseTestingEntity(
                    titleCaseValue,
                    snakeCaseValue
                    )
                );
            var query = new FindCaseTestingEntity(id);

            // Act
            var whenSnakeCaseDisabled = QueryExecutor.Execute(query);

            EnableSnakeCase();
            var whenSnakeCaseEnabled = QueryExecutor.Execute(query);

            // Assert
            Expect(whenSnakeCaseDisabled)
            .Not.To.Be.Null("entity not found at all");
            Expect(whenSnakeCaseDisabled.TitleCased)
            .To.Equal(titleCaseValue, "TitleCased should always be mapped");
            Expect(whenSnakeCaseDisabled.SnakeCased)
            .To.Be.Null("snake_case is disabled -- should not map the property");

            Expect(whenSnakeCaseEnabled)
            .Not.To.Be.Null("entity not found at all");
            Expect(whenSnakeCaseEnabled.TitleCased)
            .To.Equal(titleCaseValue, "TitleCased should always be mapped");
            Expect(whenSnakeCaseEnabled.SnakeCased)
            .To.Equal(snakeCaseValue, "snake_case is enabled -- should be mapped");
        }
Пример #4
0
 public void OneTimeSetup()
 {
     GlobalSetup.OneTimeSetup();
 }
Пример #5
0
 public void TearDown()
 {
     // ensure that any subsequent tests get the default test configuration
     GlobalSetup.PerformDefaultConfiguration();
 }