private bool IsMatch( string expectedResourceKey, string actualMessage, bool isExactMatch, object[] stringParameters, out string messageFromResources) { ExceptionHelpers.CheckStringArgumentIsNotNullOrEmpty(expectedResourceKey, "expectedResourceKey"); ExceptionHelpers.CheckArgumentNotNull(actualMessage, "actualMessage"); messageFromResources = _lookup.LookupString(expectedResourceKey); if (stringParameters.Length == 0) { return(IsMatchWithAnyPlaceholderValues(messageFromResources, actualMessage, isExactMatch)); } else { Assert.True(stringParameters.Count(p => p is AnyValueParameter) <= 1, "Only one 'AnyValueParameter' allowed."); messageFromResources = string.Format(CultureInfo.CurrentCulture, messageFromResources, stringParameters); var anyValueParameter = stringParameters.OfType <AnyValueParameter>().SingleOrDefault(); if (anyValueParameter != null) { var parts = messageFromResources.Split(new[] { anyValueParameter.ToString() }, StringSplitOptions.None); Assert.Equal(2, parts.Length); return(parts.Length == 2 && actualMessage.StartsWith(parts[0]) && actualMessage.EndsWith(parts[1])); } return(isExactMatch ? actualMessage == messageFromResources : actualMessage.Contains(messageFromResources)); } }
private static void ValidateCommonArguments(string outputDirectory, Assembly assembly, string resourceName) { ExceptionHelpers.CheckArgumentNotNull(outputDirectory, "outputDirectory"); ExceptionHelpers.CheckArgumentNotNull(assembly, "assembly"); ExceptionHelpers.CheckArgumentNotNull(resourceName, "resourceName"); if (!Directory.Exists(outputDirectory)) { throw new IOException("Output directory '" + outputDirectory + "' does not exist."); } }
/// <summary> /// Copies contents of one stream into another. /// </summary> /// <param name="source"> Stream to read from. </param> /// <param name="destination"> Stream to write to. </param> /// <param name="copyBuffer"> The copy buffer. </param> /// <returns> The number of bytes copied from the source. </returns> public static int CopyStream(Stream source, Stream destination, byte[] copyBuffer) { ExceptionHelpers.CheckArgumentNotNull(source, "source"); ExceptionHelpers.CheckArgumentNotNull(destination, "destination"); ExceptionHelpers.CheckArgumentNotNull(copyBuffer, "copyBuffer"); var bytesCopied = 0; int bytesRead; do { bytesRead = source.Read(copyBuffer, 0, copyBuffer.Length); destination.Write(copyBuffer, 0, bytesRead); bytesCopied += bytesRead; }while (bytesRead != 0); return(bytesCopied); }
private bool IsMatch( string expectedResourceKey, string actualMessage, bool isExactMatch, object[] stringParameters, out string messageFromResources) { ExceptionHelpers.CheckStringArgumentIsNotNullOrEmpty(expectedResourceKey, "expectedResourceKey"); ExceptionHelpers.CheckArgumentNotNull(actualMessage, "actualMessage"); messageFromResources = _lookup.LookupString(expectedResourceKey); if (stringParameters.Length == 0) { return(IsMatchWithAnyPlaceholderValues(messageFromResources, actualMessage, isExactMatch)); } else { messageFromResources = string.Format(CultureInfo.InvariantCulture, messageFromResources, stringParameters); return(isExactMatch ? actualMessage == messageFromResources : actualMessage.Contains(messageFromResources)); } }
private AssemblyResourceLookup(Assembly assembly, ResourceManager manager) { ExceptionHelpers.CheckArgumentNotNull(assembly, "assembly"); _assembly = assembly; _resourceManager = manager; }
/// <summary> /// Builds a resource manager for the given assembly. /// </summary> /// <param name="assembly"> The assembly to build the resource manager for. </param> /// <returns> The resource manager. </returns> public static ResourceManager BuildResourceManager(Assembly assembly) { ExceptionHelpers.CheckArgumentNotNull(assembly, "assembly"); return(new ResourceManager(FindSingleResourceTable(assembly), assembly)); }