예제 #1
0
 public void Setup()
 {
     _assembly = Substitute.For <IAssemblyInstance>();
     _assembly.GetManifestResourceNames().Returns(_resourceNames);
     _assembly.GetManifestResourceStream(Arg.Is <string>(x => _resourceNames[0].EndsWith(x))).Returns(BuildStream(_resourceData[0]));
     _assembly.GetManifestResourceStream(Arg.Is <string>(x => _resourceNames[1].EndsWith(x))).Returns(BuildStream(_resourceData[1]));
     _assembly.GetManifestResourceStream(Arg.Is <string>(x => _resourceNames[2].EndsWith(x))).Returns(BuildStream(_resourceData[2]));
 }
예제 #2
0
        public static string GetEmbeddedResource(IAssemblyInstance assembly, string resourceName)
        {
            var names    = GetEmbeddedResourceNames(assembly);
            var fullName = names.FirstOrDefault(x => x.EndsWith(resourceName, StringComparison.InvariantCultureIgnoreCase));

            if (fullName == null)
            {
                return(null);
            }

            string result = null;

            using (Stream stream = assembly.GetManifestResourceStream(fullName))
            {
                if (stream != null)
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }
            }

            return(result);
        }