Skip to content

Commit

Permalink
add coverage, fix bugs (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-epure-sonarsource committed Aug 21, 2023
1 parent 0a00bb9 commit e5b0398
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/ApplicationCore/FileSystem/ResourceHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@
namespace Microsoft.eShopWeb.ApplicationCore.FileSystem;
public class ResourceHolder
{
private FileStream fs; // Noncompliant: dispose or close are never called

public ResourceHolder(string path)
{
this.fs = new FileStream(path, FileMode.Open);
}

public void WriteToFile(string path, string text)
{
var fs = new FileStream(path, FileMode.Open); // Noncompliant: not disposed, returned or initialized with another disposable object
var fs = new FileStream(path, FileMode.OpenOrCreate);
var bytes = Encoding.UTF8.GetBytes(text);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
}
20 changes: 20 additions & 0 deletions tests/UnitTests/ApplicationCore/FileSystem/ResourceHolderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.FileSystem;
using Xunit;

namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.FileSystem;
public class ResourceHolderTests
{
[Fact]
public void WritesFileToDisk()
{
var underTest = new ResourceHolder();
underTest.WriteToFile("test", "foo");

Assert.True(File.Exists("test"));
}
}

0 comments on commit e5b0398

Please sign in to comment.