public void GetItems_Single() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UpsertOnPut = true }); var dsSettings = Options.Create(new DataStoreSettings()); var controller = new DynamicController(ds, apiSettings, dsSettings); var itemResult = controller.GetItems("configuration"); Assert.IsType <OkObjectResult>(itemResult); var okObjectResult = itemResult as OkObjectResult; dynamic item = okObjectResult.Value as ExpandoObject; Assert.Equal("abba", item.password); UTHelpers.Down(filePath); }
public void Mutation_Add_User_With_Child() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var muation = @" mutation { addUsers ( input: { users: { name: Newton age: 45 work: { name: ACME } } }) { users { id name age work { name } } } }"; var results = GraphQL.GraphQL.HandleQuery(muation, ds, _idFieldName); var id = ((dynamic)results.Data["users"]).id; var item = ds.GetCollection("users").AsQueryable().First(e => e.id == id); Assert.Equal("Newton", item.name); Assert.Equal(45, item.age); Assert.Equal("ACME", item.work.name); UTHelpers.Down(filePath); }
public void StartServer(string authenticationType = "") { var path = Path.GetDirectoryName(typeof(IntegrationFixture).GetTypeInfo().Assembly.Location); var fileName = Guid.NewGuid().ToString(); _newFilePath = UTHelpers.Up(fileName); var mainConfiguration = new Dictionary <string, string> { { "currentPath", path }, { "file", _newFilePath }, { "DataStore:IdField", "id" }, { "Caching:ETag:Enabled", "true" } }; if (!string.IsNullOrEmpty(authenticationType)) { mainConfiguration.Add("Authentication:Enabled", "true"); mainConfiguration.Add("Authentication:AuthenticationType", authenticationType); mainConfiguration.Add("Authentication:Users:0:Username", "admin"); mainConfiguration.Add("Authentication:Users:0:Password", "root"); } _factory = new WebApplicationFactory <Startup>() .WithWebHostBuilder(builder => { builder.UseEnvironment("IntegrationTest") .ConfigureAppConfiguration((ctx, b) => { b.SetBasePath(path) .Add(new MemoryConfigurationSource { InitialData = mainConfiguration }); }); }); Client = _factory.CreateClient(); }
public async Task PutItem_Upsert_Id_String() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UpsertOnPut = true }); var controller = new DynamicController(ds, apiSettings); var result = await controller.ReplaceItem("my_test_string", "acdc", JToken.Parse("{ 'id': 2, 'text': 'Hello' }")) as NoContentResult; Assert.Equal(204, result.StatusCode); var itemResult = controller.GetItem("my_test_string", "acdc") as OkObjectResult; dynamic item = itemResult.Value as ExpandoObject; Assert.Equal("acdc", item.id); Assert.Equal("Hello", item.text); UTHelpers.Down(filePath); }
public void StartServer(string authenticationType = "") { if (_serverTask != null) { return; } var dir = Path.GetDirectoryName(typeof(IntegrationFixture).GetTypeInfo().Assembly.Location); var fileName = Guid.NewGuid().ToString(); _newFilePath = UTHelpers.Up(fileName); Port = 5001; BaseUrl = $"http://localhost:{Port}"; _serverTask = Task.Run(() => { TestServer.Run(BaseUrl, dir, $"{fileName}.json", authenticationType); }); var success = Task.Run(() => WaitForServer()).GetAwaiter().GetResult(); }