Skip to content

Commit

Permalink
Fix issue with file permissions and include unit test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Oct 26, 2016
1 parent b4de709 commit 9ae40c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO/Modules/StaticFilesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private bool HandleGet(HttpListenerContext context, WebServer server, bool sendB

if (sendBuffer)
{
buffer = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.Read);
buffer = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

if (usingPartial == false)
{
Expand Down
24 changes: 24 additions & 0 deletions test/Unosquare.Labs.EmbedIO.Tests/StaticFilesModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,30 @@ public async Task HeadIndex()
}
}

[Test]
public async Task FileWritable()
{
var endpoint = Resources.GetServerAddress();
var root = Path.GetTempPath();
var file = Path.Combine(root, "index.html");
File.WriteAllText(file, Resources.Index);

using (var server = new WebServer(endpoint, Logger))
{
server.RegisterModule(new StaticFilesModule(root));
server.RunAsync();

var webClient = new HttpClient();
var remoteFile = await webClient.GetStringAsync(endpoint);
File.WriteAllText(file, Resources.SubIndex);
var remoteUpdatedFile = await webClient.GetStringAsync(endpoint);
File.WriteAllText(file, nameof(WebServer));

Assert.AreEqual(Resources.Index, remoteFile);
Assert.AreEqual(Resources.SubIndex, remoteUpdatedFile);
}
}

[TearDown]
public void Kill()
{
Expand Down
3 changes: 2 additions & 1 deletion test/Unosquare.Labs.EmbedIO.Tests/TestObjects/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Unosquare.Labs.EmbedIO.Tests.TestObjects
public static class Resources
{
private const string ServerAddress = "http://localhost:{0}/";
public static int Counter = 9699;
public static int Counter = 9699;

public static string GetServerAddress(){
Interlocked.Increment(ref Counter);
return string.Format(ServerAddress, Counter);
Expand Down

0 comments on commit 9ae40c9

Please sign in to comment.