Ejemplo n.º 1
0
        public void Setup()
        {
            var dbFactory = appHost.Resolve <IDbConnectionFactory>();

            using (var db = dbFactory.OpenDbConnection())
            {
                db.DropAndCreateTable <TechnologyStack>();
                db.DropAndCreateTable <Technology>();
                db.DropAndCreateTable <TechnologyChoice>();
                db.DropAndCreateTable <UserFavoriteTechnologyStack>();
                db.DropAndCreateTable <UserFavoriteTechnology>();
                db.DropAndCreateTable <TechnologyHistory>();
                db.DropAndCreateTable <TechnologyStackHistory>();
            }

            SeedTestHost();
            client = new JsonServiceClient(TestHostUrl);
            client.Post(new Authenticate {
                UserName = "******", Password = "******", provider = "credentials"
            });
            adminClient = new JsonServiceClient(TestHostUrl);
            adminClient.Post(new Authenticate {
                UserName = "******", Password = "******", provider = "credentials"
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化表结构
        /// </summary>
        public static void InitDataTable(ServiceStackHost appHost)
        {
            var dbFactory = appHost.Resolve <IDbConnectionFactory>();
            var schema    = appHost.Resolve <ISchemaManage>();

            using (var db = dbFactory.OpenDbConnection())
            {
                db.DropTable <Organization>();

                db.DropTable <UserAuthRole>();
                db.DropTable <UserAuthDetails>();
                db.DropTable <UserInfo>();

                //删除其它表
                Task.Run(async() =>
                {
                    var tables = await schema.GetTables(TestDatabaseName);
                    foreach (var table in tables)
                    {
                        await schema.DropTable(table, TestDatabaseName);
                    }
                }).Wait();

                ((OrmLiteAuthRepository <UserInfo, UserAuthDetails>)appHost.Resolve <IAuthRepository>())
                .InitSchema();

                db.CreateTable <Organization>();
            }
        }
Ejemplo n.º 3
0
        public void Can_send_multiple_single_HelloAllTransaction()
        {
            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                db.DropAndCreateTable <HelloAllTransaction>();
            }

            var client = CreateClient(Config.AbsoluteBaseUri);

            var names = new[] { "Foo", "Bar", "Baz" };

            try
            {
                foreach (var name in names)
                {
                    client.Send(new HelloAllTransaction {
                        Name = name
                    });
                }

                Assert.Fail("Should throw on Bar");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.ErrorCode, Is.EqualTo(typeof(ArgumentException).Name));
            }

            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                var allRequests = db.Select <HelloAllTransaction>();
                Assert.That(allRequests.Count, Is.EqualTo(1));
                Assert.That(allRequests[0].Name, Is.EqualTo("Foo"));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建初始数据
        /// </summary>
        public static void Create(ServiceStackHost appHost)
        {
            var dbFactory    = appHost.Resolve <IDbConnectionFactory>();
            var authRepo     = (OrmLiteAuthRepository <UserInfo, UserAuthDetails>)appHost.Resolve <IAuthRepository>();
            var schemaManage = appHost.Resolve <ISchemaManage>();

            var rand           = new Random(DateTime.Now.Millisecond);
            var parentOrgCount = rand.Next(5, 10);
            var childOrgIds    = new List <long>();

            using (var db = dbFactory.Open())
            {
                using (var trans = db.OpenTransaction())
                {
                    // 生成组织
                    for (var i = 0; i < parentOrgCount; i++)
                    {
                        var id = db.Insert(new Organization {
                            ParentId = 0, Name = $"父组织_{i}"
                        }, true);
                        var childOrgCount = rand.Next(5, 20);
                        for (var j = 0; j < childOrgCount; j++)
                        {
                            var childId = db.Insert(new Organization {
                                ParentId = id, Name = $"子组织_{i}"
                            }, true);
                            childOrgIds.Add(childId);
                        }
                    }

                    // 添加一些用户
                    var userCount = rand.Next(10, 50);
                    for (var i = 0; i < userCount; i++)
                    {
                        var user = new UserInfo
                        {
                            UserName       = $"username_{i}",
                            Email          = $"username_{i}@dayu.com",
                            OrganizationId = childOrgIds[rand.Next(0, childOrgIds.Count - 1)],
                            DisplayName    = $"用户_{i}",
                            Role           = i % 2 == 0 ? RoleConstants.Admin :
                                             i % 3 == 0 ? RoleConstants.Watcher : RoleConstants.Operator
                        };
                        if (i % 4 == 0)
                        {
                            user.LockedDate = DateTime.Now;
                        }

                        authRepo.CreateUserAuth(user, "123@qwe");
                    }

                    trans.Commit();
                }
            }
        }
Ejemplo n.º 5
0
    public void Setup()
    {
        var dbFactory = appHost.Resolve <IDbConnectionFactory>();

        using var db = dbFactory.OpenDbConnection();
        db.DropAndCreateTable <TechnologyStack>();
        db.DropAndCreateTable <Technology>();
        db.DropAndCreateTable <TechnologyChoice>();
        db.DropAndCreateTable <UserFavoriteTechnologyStack>();
        db.DropAndCreateTable <UserFavoriteTechnology>();

        SeedTestHost();
    }
Ejemplo n.º 6
0
        public void Can_query_Table_with_Byte_property()
        {
            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                db.DropAndCreateTable <CustomFields>();
                db.Insert(new CustomFields {
                    StringId = "1001", Byte = 1
                });
                db.Insert(new CustomFields {
                    StringId = "1002", Byte = 2
                });
            }

            var response = client.Get(new CustomFieldsQuery
            {
                StringIdIn = new[] { "1001", "1002" },
            });

            Assert.That(response.Results.Map(x => x.Byte), Is.EquivalentTo(new[] { 1, 2 }));

            response = client.Get(new CustomFieldsQuery
            {
                StringIdIn = new[] { "1001", "1002" },
                Byte       = 2
            });
            Assert.That(response.Results.Map(x => x.Byte), Is.EquivalentTo(new[] { (byte)2 }));

            response = client.Get(new CustomFieldsQuery
            {
                ByteIn = new byte[] { 1, 2 }
            });
            Assert.That(response.Results.Map(x => x.Byte), Is.EquivalentTo(new[] { 1, 2 }));
        }
Ejemplo n.º 7
0
        public StatelessAuthTests()
        {
            LogManager.LogFactory = new ConsoleLogFactory();
            appHost = new AppHost {
                EnableAuth = true
            }
            .Init()
            .Start("http://*:2337/");

            var client = GetClient();

            client.Post(new Register {
                UserName    = "******",
                Password    = "******",
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            using (var db = appHost.Resolve <IDbConnectionFactory>().OpenDbConnection())
            {
                ApiKey = db.Select <ApiKey>().First();
                ApiKey.PrintDump();
            }
        }
        public void BootStrap()
        {
            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                Customer = new Customer
                {
                    FirstName = "Joe",
                    LastName  = "Schmidt",
                };

                db.Save(Customer);

                Address = new Address
                {
                    Street          = "Lansdowne Road",
                    ProvinceOrState = "Leinster",
                    City            = "Dublin",
                    Country         = "Ireland",
                    CustomerId      = Customer.Id
                };

                db.Save(Address);

                Order = new CustomerOrder
                {
                    CustomerId = Customer.Id,
                    Details    = "Random Order"
                };

                db.Save(Order);
            }
        }
        protected StatelessAuthRazorTests()
        {
            appHost = CreateAppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = GetClient();
            var response = client.Post(new Register
            {
                UserName    = "******",
                Password    = "******",
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            var userId      = response.UserId;
            var apiRepo     = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            var user1Client = GetClientWithUserPassword(alwaysSend: true);

            ApiKey = user1Client.Get(new GetApiKeys {
                Environment = "live"
            }).Results[0].Key;
        }
Ejemplo n.º 10
0
 public void SetUp()
 {
     using (var db = appHost.Resolve <IDbConnectionFactory>().OpenDbConnection())
     {
         db.DropAndCreateTable <Message>();
     }
 }
Ejemplo n.º 11
0
        public ApiKeyAuthTests()
        {
            //System.Diagnostics.Debugger.Break();
            appHost = new AppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = new JsonServiceClient(ListeningOn);
            var response = client.Post(new Register
            {
                UserName    = Username,
                Password    = Password,
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            userId  = response.UserId;
            apiRepo = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            var apiKeys = apiRepo.GetUserApiKeys(userId);

            liveKey = apiKeys.First(x => x.Environment == "live");
            testKey = apiKeys.First(x => x.Environment == "test");
        }
        public void TestSuspendAndUnsuspendUser()
        {
            var discourseClient = appHost.Resolve <IDiscourseClient>();

            discourseClient.AdminSuspendUser(4, 1, "This is a test");
            var testUser = discourseClient.AdminGetUsers().Where(x => x.Username == "archiveuser").FirstNonDefault();

            Assert.That(testUser != null);
            Assert.That(testUser.Id == 4);
            Assert.That(testUser.Suspended == true);

            discourseClient.AdminUnsuspendUser(4);
            testUser = discourseClient.AdminGetUsers().Where(x => x.Username == "archiveuser").FirstNonDefault();
            Assert.That(testUser != null);
            Assert.That(testUser.Id == 4);
            Assert.That(testUser.Suspended == null || testUser.Suspended == false);
        }
Ejemplo n.º 13
0
        protected override void Configure(ServiceStackHost appHost)
        {
            var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            appHost.Register <IDbConnectionFactory>(dbFactory);
            appHost.Register <IAuthRepository>(new OrmLiteAuthRepository(dbFactory));
            appHost.Resolve <IAuthRepository>().InitSchema();
        }
Ejemplo n.º 14
0
        public void SetUp()
        {
            const string testDataFile =
                @"../../OrmMessageRepository_Performance_Test_Data.json";

            if (!File.Exists(testDataFile))
            {
                CreateTestFile(testDataFile, LargeMessageCount);
            }

            using (var db = appHost.Resolve <IDbConnectionFactory>().OpenDbConnection())
            {
                db.DropAndCreateTable <Message>();
                var wholeList = File.ReadAllText(testDataFile)
                                .FromJson <List <Message> >();
                db.InsertAll(wholeList);
            }
        }
Ejemplo n.º 15
0
        public StatelessAuthTests()
        {
            //LogManager.LogFactory = new ConsoleLogFactory();
            appHost = CreateAppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = GetClient();
            var response = client.Post(new Register
            {
                UserName    = "******",
                Password    = "******",
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            userId  = response.UserId;
            apiRepo = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            var user1Client = GetClientWithUserPassword(alwaysSend: true);

            ApiKey = user1Client.Get(new GetApiKeys {
                Environment = "live"
            }).Results[0].Key;

            apiProvider = (ApiKeyAuthProvider)AuthenticateService.GetAuthProvider(ApiKeyAuthProvider.Name);

            response = client.Post(new Register
            {
                UserName    = "******",
                Password    = "******",
                Email       = "as2@if{0}.com",
                DisplayName = "DisplayName2",
                FirstName   = "FirstName2",
                LastName    = "LastName2",
            });
            userIdWithRoles = response.UserId;
            var user2Client = GetClientWithUserPassword(alwaysSend: true, userName: "******");

            ApiKeyWithRole = user2Client.Get(new GetApiKeys {
                Environment = "live"
            }).Results[0].Key;

            ListeningOn.CombineWith("/assignroles").AddQueryParam("authsecret", "secret")
            .PostJsonToUrl(new AssignRoles
            {
                UserName = "******",
                Roles    = new List <string> {
                    "TheRole"
                },
                Permissions = new List <string> {
                    "ThePermission"
                }
            }.ToJson());
        }
Ejemplo n.º 16
0
        internal Mock <IServiceBase> MockAuthService(MockHttpRequest request = null)
        {
            request = request ?? new MockHttpRequest();
            var mockAuthService = new Mock <IServiceBase>();

            mockAuthService.SetupGet(s => s.Request).Returns(request);
            mockAuthService.Setup(s => s.TryResolve <IApplicationRegistryService>()).Returns(
                _appHost.Resolve <IApplicationRegistryService>());
            return(mockAuthService);
        }
        public void FixtureSetUp()
        {
            Host = ServiceStackHost.Instance;

            using (var db = Host.Resolve <IDbConnection>())
            {
                db.Insert(new Vendor {
                    Name = Constants.Vendors.JlcConcept
                });
            }
        }
Ejemplo n.º 18
0
        private object RegisterUser(string email = "*****@*****.**")
        {
            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                db.Delete <UserAuth>(q => q.Email == email);
            }

            var response = appHost.ExecuteService(new Register
            {
                Password    = "******",
                Email       = email,
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            Assert.That(response as RegisterResponse, Is.Not.Null, response.ToString());

            return(response);
        }
        public void FixtureSetUp()
        {
            //Start your AppHost on TestFixture SetUp
            Host = ServiceStackHost.Instance;

            using (var db = Host.Resolve <IDbConnection>())
            {
                db.Save(Product.Light);
                db.Save(Product.CatTree);
                db.Save(Location.TestRack);
            }
        }
        public void FixtureSetUp()
        {
            //Start your AppHost on TestFixture SetUp
            Host = ServiceStackHost.Instance;

            Host.Container.RegisterAutoWired <Api.Handlers.ProductHandler>();

            using (var db = Host.Resolve <IDbConnectionFactory>().Open())
            {
                db.InsertAll(Product.Basic);
            }
        }
Ejemplo n.º 21
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            AppHost = new GenericAppHost(typeof(MyService).Assembly)
            {
                ConfigureAppHost = host =>
                {
                    host.Register <IRedisClientsManager>(
                        new RedisManagerPool(hostContext.Configuration.GetConnectionString("RedisMq")));
                    var mqServer = new RedisMqServer(host.Resolve <IRedisClientsManager>())
                    {
                        DisablePublishingToOutq = true,
                    };
                    mqServer.RegisterHandler <Hello>(host.ExecuteMessage);
                    host.Register <IMessageService>(mqServer);
                }
            }.Init();

            services.AddSingleton(AppHost.Resolve <IRedisClientsManager>());
            services.AddSingleton(AppHost.Resolve <IMessageService>());
            services.AddHostedService <MqWorker>();
        });
Ejemplo n.º 22
0
        public void Can_ModifyValidationRules_suspend_and_delete()
        {
            (appHost.Resolve <IValidationSource>() as IClearable)?.Clear();

            var client = GetClient();

            var noRules = client.Get(new ValidationRulesTest());

            client.Post(new ModifyValidationRules {
                AuthSecret = AuthSecret,
                SaveRules  = new List <ValidationRule> {
                    new ValidationRule {
                        Type = nameof(ValidationRulesTest), Validator = nameof(ValidateScripts.IsAuthenticated)
                    },
                }
            });
Ejemplo n.º 23
0
        public void TestWebHookWithoutAccount()
        {
            var service = appHost.Container.Resolve <WebHookServices>();

            var req = new UserCreatedDiscourseWebHook {
                RequestStream = new MemoryStream(invalidEmailInput.ToUtf8Bytes())
            };

            service.Post(req);
            Thread.Sleep(3200);
            var discourseClient = appHost.Resolve <IDiscourseClient>() as MockDiscourseClient;

            Assert.That(discourseClient != null);
            Assert.That(discourseClient.ApproveCalledCount == 0);
        }
Ejemplo n.º 24
0
        public void BaseSetUp()
        {
            AppHost = new BasicAppHost(typeof(FileService).Assembly)
            {
                ConfigureAppHost = host =>
                {
                    OrmLiteConfig.ExecFilter = new LogExecFilter();

                    host.Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                                     new IAuthProvider[]
                    {
                        new CredentialsAuthProvider()
                    }));

                    host.AppSettings = new EnvironmentVariableSettings();
                },
                ConfigureContainer = container =>
                {
                    var dbFactory = new OrmLiteConnectionFactory(DataSeed.TestDbConnection, MySqlDialect.Provider);

                    container.Register <IDbConnectionFactory>(c => dbFactory);
                    container.Register <ICacheClient>(new MemoryCacheClient());
                    container.Register <IAuthRepository>(c =>
                                                         new OrmLiteAuthRepository <UserInfo, UserAuthDetails>(dbFactory)
                    {
                        UseDistinctRoleTables = true
                    });

                    container.RegisterAs <OrgManage, IOrgManage>();
                    container.Register <ISchemaManage>(c => new MysqlSchemaManage("MyApp_test_db"));
                }
            };

            AppHost.Init();

            OrgManage = AppHost.Resolve <IOrgManage>();
            Db        = AppHost.GetDbConnection();

            DataSeed.InitDataTable(AppHost);
            DataSeed.Create(AppHost);
        }
        protected StatelessAuthRazorTests()
        {
            appHost = CreateAppHost()
               .Init()
               .Start("http://*:2337/");

            var client = GetClient();
            var response = client.Post(new Register
            {
                UserName = "******",
                Password = "******",
                Email = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName = "FirstName",
                LastName = "LastName",
            });

            var userId = response.UserId;
            var apiRepo = (IManageApiKeys)appHost.Resolve<IAuthRepository>();
            var user1Client = GetClientWithUserPassword(alwaysSend: true);
            ApiKey = user1Client.Get(new GetApiKeys { Environment = "live" }).Results[0].Key;
        }
Ejemplo n.º 26
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            AppHost = new GenericAppHost(typeof(MyService).Assembly)
            {
                ConfigureAppHost = host =>
                {
                    var mqServer = new SqsMqServer(
                        hostContext.Configuration.GetConnectionString("AwsAccessKey"),
                        hostContext.Configuration.GetConnectionString("AwsSecretKey"),
                        RegionEndpoint.USEast1)
                    {
                        DisablePublishingToOutq = true,
                        DisableBuffering        = true,  // Trade-off latency vs efficiency
                    };
                    mqServer.RegisterHandler <Hello>(host.ExecuteMessage);
                    host.Register <IMessageService>(mqServer);
                }
            }.Init();

            services.AddSingleton(AppHost.Resolve <IMessageService>());
            services.AddHostedService <MqWorker>();
        });
Ejemplo n.º 27
0
        public StatelessAuthTests()
        {
            //LogManager.LogFactory = new ConsoleLogFactory();
            appHost = CreateAppHost()
                      .Init()
                      .Start("http://*:2337/");

            var client   = GetClient();
            var response = client.Post(new Register
            {
                UserName    = "******",
                Password    = "******",
                Email       = "as@if{0}.com",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            });

            userId  = response.UserId;
            apiRepo = (IManageApiKeys)appHost.Resolve <IAuthRepository>();
            ApiKey  = apiRepo.GetUserApiKeys(userId).First(x => x.Environment == "test");

            apiProvider = (ApiKeyAuthProvider)AuthenticateService.GetAuthProvider(ApiKeyAuthProvider.Name);
        }
Ejemplo n.º 28
0
        public virtual void OneTimeSetup()
        {
            Sut = appHost.Resolve <T>();

            Mappers.Register();
        }
Ejemplo n.º 29
0
 public void Setup()
 {
     Sut = appHost.Resolve <IUserAuthRepository>();
     ((IClearable)Sut).Clear();
 }
Ejemplo n.º 30
0
        public void Verify_Password_IHashProvider()
        {
            var isMatch = appHost.Resolve <IHashProvider>().VerifyHashString("123456", passwordHash, salt);

            Assert.That(isMatch);
        }
        public void Does_now_allow_registering_invalid_validators()
        {
            (appHost.Resolve <IValidationSource>() as IClearable)?.Clear();

            var client = GetClient();

            void saveRules(params ValidationRule[] rules) => client.Post(new ModifyValidationRules {
                AuthSecret = AuthSecret,
                SaveRules  = new List <ValidationRule>(rules)
            });

            void assertThrows(Action fn, Action <WebServiceException> onError)
            {
                try
                {
                    fn();
                    Assert.Fail($"Should throw {nameof(WebServiceException)}");
                }
                catch (WebServiceException e)
                {
                    onError(e);
                }
            }

            assertThrows(() => saveRules(new ValidationRule {
                Validator = nameof(ValidateScripts.IsAuthenticated),
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Type)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest) + "NotExists",
                Validator = nameof(ValidateScripts.IsAuthenticated),
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Type)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Field     = "NotExists",
                Validator = nameof(ValidateScripts.IsAuthenticated),
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Field)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Validator = nameof(ValidateScripts.IsAuthenticated) + "NotExists",
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Field     = nameof(ValidationRulesTest.AuthSecret),
                Validator = nameof(ValidateScripts.IsAuthenticated), //should be IPropertyValidator
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Validator = nameof(ValidateScripts.Null), //should be ITypeValidator
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Field     = nameof(ValidationRulesTest.AuthSecret),
                Validator = $"[{nameof(ValidateScripts.Null)},{nameof(ValidateScripts.IsAuthenticated)}]", //validate all
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Validator = $"[{nameof(ValidateScripts.IsAuthenticated)},{nameof(ValidateScripts.Null)}]", //validate all
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Validator = nameof(ValidateScripts.IsAuthenticated),
                Condition = "true",
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Condition)));

            assertThrows(() => saveRules(new ValidationRule {
                Type = nameof(ValidationRulesTest),
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Validator)));

            assertThrows(() => saveRules(new ValidationRule {
                Type      = nameof(ValidationRulesTest),
                Condition = "Invalid (ode"
            }), e => Assert.That(e.StatusCode == 400 &&
                                 e.GetFieldErrors()[0].FieldName == nameof(ValidationRule.Condition)));
        }