/// <summary> /// Creates a new RhinoTestCaseCollection under context. /// </summary> /// <param name="authentication">Authentication object by which to create RhinoTestCaseCollection.</param> /// <param name="data">RhinoTestCaseCollection data to create.</param> /// <returns>The <see cref="RhinoTestCaseCollection.Id"/> of the newly created entity.</returns> public string Post(Authentication authentication, RhinoTestCaseCollection data) { // validate CreateCollection(authentication); // get collection var collection = LiteDb.GetCollection <RhinoTestCaseCollection>(name: Collection); // insert collection.Insert(entity: data); // exit conditions if (data.Configurations == null || data.Configurations.Count == 0) { return($"{data.Id}"); } // cascade foreach (var configuration in data.Configurations) { ApplyToConfiguration(authentication, configuration, collection: data); } // response return($"{data.Id}"); }
private async Task <IActionResult> DoPost(string configuration) { // read test case from request body var requestBody = await Request.ReadAsync().ConfigureAwait(false); var documents = requestBody.Split(Seperator); // setup var collection = new RhinoTestCaseCollection(); // apply configuration var configurationResult = AddConfiguration(onCollection: collection, configuration); // validate if (configurationResult == HttpStatusCode.BadRequest) { return(await this.ErrorResultAsync("You must provide a configuration").ConfigureAwait(false)); } if (configurationResult == HttpStatusCode.NotFound) { return(await this .ErrorResultAsync($"Configuration [{configuration}] was not found.", HttpStatusCode.NotFound) .ConfigureAwait(false)); } // create id for this collection collection.Id = Guid.NewGuid(); // parse test cases collection.RhinoTestCaseDocuments = documents .Select(i => new RhinoTestCaseDocument { Collection = $"{collection.Id}", Id = Guid.NewGuid(), RhinoSpec = i }) .Where(i => !string.IsNullOrEmpty(i.RhinoSpec)) .ToList(); // get credentials var credentials = Request.GetAuthentication(); // response var data = new { Data = new { Id = rhinoTest.Post(credentials, collection) } }; return(this.ContentResult(responseBody: data, HttpStatusCode.Created)); }
private HttpStatusCode AddConfiguration(RhinoTestCaseCollection onCollection, string configuration) { // setup onCollection.Configurations ??= new List <string>(); // no configuration if (string.IsNullOrEmpty(configuration)) { return(HttpStatusCode.OK); } // check configuration var(statusCode, _) = rhinoConfiguration.Get(Request.GetAuthentication(), configuration); // not found if (statusCode == HttpStatusCode.NotFound) { return(HttpStatusCode.NotFound); } // put configuration onCollection.Configurations.Add(configuration); return(HttpStatusCode.OK); }
private IEnumerable <RhinoConfiguration> Get(RhinoTestCaseCollection collection, string configuration) => collection .Configurations .Select(i => GetConfiguration(i, allowNoTests: false)) .Where(i => i.statusCode == 200 && $"{i.configuration.Id}".Equals(configuration, Compare)) .Select(i => i.configuration);
private IEnumerable <RhinoConfiguration> Get(RhinoTestCaseCollection collection) => collection .Configurations .Select(i => GetConfiguration(i, allowNoTests: false)) .Where(i => i.statusCode == 200) .Select(i => i.configuration);