public static Response CreateFromEmbeddedResource(string resourceName, HttpStatusCode httpStatusCode, string contentType) { var responseValue = EmbeddedResource.GetAsString(Assembly.GetExecutingAssembly(), resourceName); Response response = ((Response)responseValue).WithStatusCode(httpStatusCode); response.ContentType = contentType; return(response); }
public void WhenTheObjectWithADefaultXMLRootAttributeIsSerialisedWithNoSerialisationOverrides() { this.expectedXml = EmbeddedResource.GetAsString(Assembly.GetExecutingAssembly(), "ChannelAdam.Core.BehaviourSpecs.TestData.ExpectedXmlWithDefaultRoot.xml"); Logger.Log($"Expected XML: {Environment.NewLine}" + this.expectedXml); this.actualXml = this.testXmlObject.SerialiseToXml(); Logger.Log($"Actual XML: {Environment.NewLine}" + this.actualXml); }
public void WhenTheObjectWithADefaultXMLRootAttributeIsSerialisedWithAnOverrideOfTheXMLRootAttribute() { this.expectedXml = EmbeddedResource.GetAsString(Assembly.GetExecutingAssembly(), "ChannelAdam.Core.BehaviourSpecs.TestData.ExpectedXmlWithNewRoot.xml"); Logger.Log($"Expected XML: {Environment.NewLine}" + this.expectedXml); var newXmlRoot = new XmlRootAttribute("NewRoot"); newXmlRoot.Namespace = "uri:new:namespace"; this.actualXml = this.testXmlObject.SerialiseToXml(newXmlRoot); Logger.Log($"Actual XML: {Environment.NewLine}" + this.actualXml); }
public async Task Drop() { var sql = EmbeddedResource.GetAsString("DropDatabase.sql", SqlPath); await using var conn = new SqlConnection(_connectionString); await using SqlCommand command = new SqlCommand(sql, conn); await conn.OpenAsync(); await command.ExecuteScalarAsync(); await conn.CloseAsync(); }
public void WhenTheObjectWithADefaultXMLRootAttributeIsSerialisedWithAnOverrideOfTheXMLAttributes() { this.expectedXml = EmbeddedResource.GetAsString(Assembly.GetExecutingAssembly(), "ChannelAdam.Core.BehaviourSpecs.TestData.ExpectedXmlWithNewRoot.xml"); Logger.Log($"Expected XML: {Environment.NewLine}" + this.expectedXml); XmlRootAttribute newXmlRoot = CreateNewXmlRootAttribute(); var xmlAttributes = new XmlAttributes(); xmlAttributes.XmlRoot = newXmlRoot; var attributeOverrides = new XmlAttributeOverrides(); attributeOverrides.Add(typeof(TestObjectForXmlStuff), xmlAttributes); this.actualXml = this.testXmlObject.SerialiseToXml(attributeOverrides); Logger.Log($"Actual XML: {Environment.NewLine}" + this.actualXml); }
private async Task CreateDatabase() { await using var conn = new SqlConnection(_connectionString); string sql = EmbeddedResource.GetAsString("CreateDatabase.sql", SqlPath); await using SqlCommand command = new SqlCommand(sql, conn); try { await conn.OpenAsync(); await command.ExecuteScalarAsync(); await conn.CloseAsync(); } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } }
public async Task <bool> DatabaseExists() { await using var conn = new SqlConnection(_connectionString); string sql = EmbeddedResource.GetAsString("CheckDatabaseExists.sql", SqlPath); await using var command = new SqlCommand(sql, conn); try { await conn.OpenAsync(); object?result = await command.ExecuteScalarAsync(); await conn.CloseAsync(); return(result != null && result.Equals("soundmastery")); } catch (Exception e) { // TODO: add proper logging https://github.com/arublevsky/SoundMastery/issues/14 Console.WriteLine(e.ToString()); return(false); } }
/// <summary> /// Arrange the input flat file contents from an embedded resource in the given assembly. /// </summary> /// <param name="assembly">The assembly that contains the resource.</param> /// <param name="resourceName">The name of the resource.</param> public void ArrangeInputFlatFileContents(Assembly assembly, string resourceName) { this.ArrangeInputFlatFileContents(EmbeddedResource.GetAsString(assembly, resourceName)); }
/// <summary> /// Arrange the expected XML from an embedded resource in the given assembly. /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="resourceName">Name of the resource.</param> public void ArrangeExpectedXml(Assembly assembly, string resourceName) { this.ArrangeExpectedXml(EmbeddedResource.GetAsString(assembly, resourceName)); }
/// <summary> /// Arrange the actual text from an embedded resource in the given assembly. /// </summary> /// <param name="assembly">The assembly that contains the resource.</param> /// <param name="resourceName">The name of the resource.</param> public void ArrangeActualText(Assembly assembly, string resourceName) { this.ArrangeActualText(EmbeddedResource.GetAsString(assembly, resourceName)); }
public string GetSqlPath(string name, string nestedPath, bool useEngineSpecificPath = false) { string path = useEngineSpecificPath ? GetDatabaseEngine().ToString() : "Generic"; return(EmbeddedResource.GetAsString(name, $"Sql.{path}.{nestedPath}")); }
public void GivenAnXMLStringWithARootAttributeThatIsDifferentFromTheDefaultXMLRootAttribute() { this.expectedXml = EmbeddedResource.GetAsString(Assembly.GetExecutingAssembly(), "ChannelAdam.Core.BehaviourSpecs.TestData.ExpectedXmlWithNewRoot.xml"); Logger.Log($"XML string to deserialise: {Environment.NewLine}" + this.expectedXml); }