Skip to content

Commit

Permalink
Merge pull request dotnet#512 from jhendrixMSFT/v1.0
Browse files Browse the repository at this point in the history
Refactored resource writer test code per feedback.
  • Loading branch information
joshfree committed Jan 23, 2015
2 parents 6b26d11 + 45d7a65 commit 26423af
Showing 1 changed file with 54 additions and 109 deletions.
163 changes: 54 additions & 109 deletions src/System.Resources.ResourceWriter/tests/ResourceWriterUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,160 +24,105 @@ public class ResourceWriterTests
[Fact]
public static void ExceptionforResWriter01()
{
MemoryStream ms2 = null;

try
{
var rw = new ResourceWriter(ms2);
}
catch (Exception Ex)
{
if (Ex.GetType() != typeof(ArgumentNullException))
Assert.Throws<ArgumentNullException>(() =>
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(ArgumentNullException).ToString(), Ex.GetType().ToString()));
}
}
MemoryStream ms2 = null;
var rw = new ResourceWriter(ms2);
});
}

[Fact]
public static void ExceptionforResWriter02()
{
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, false))
{
try
Assert.Throws<ArgumentException>(() =>
{
var rw = new ResourceWriter(ms2);
}
catch (Exception Ex)
{
if (Ex.GetType() != typeof(ArgumentException))
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, false))
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(ArgumentException).ToString(), Ex.GetType().ToString()));
var rw = new ResourceWriter(ms2);
}
}
}
});
}

[Fact]
public static void ExceptionforResWriter03()
{
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
var rw1 = new ResourceWriter(ms2);
try
Assert.Throws<ArgumentNullException>(() =>
{
rw1.AddResource(null, "args");
}
catch (Exception Ex)
{
if (Ex.GetType() != typeof(ArgumentNullException))
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(ArgumentNullException).ToString(), Ex.GetType().ToString()));
}
}
finally
{
try
{
rw1.Dispose();
}
catch (Exception Ex)
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
if (Ex.GetType() != typeof(System.ArgumentOutOfRangeException))
var rw1 = new ResourceWriter(ms2);
try
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(System.ArgumentOutOfRangeException).ToString(), Ex.GetType().ToString()));
rw1.AddResource(null, "args");
}
finally
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
rw1.Dispose();
});
}
}
}
}
});
}

[Fact]
public static void ExceptionforResWriter04()
{
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
var rw1 = new ResourceWriter(ms2);
try
Assert.Throws<ArgumentException>(() =>
{
rw1.AddResource("key1", "args");
rw1.AddResource("key1", "args");
}
catch (Exception Ex)
{
if (Ex.GetType() != typeof(System.ArgumentException))
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(System.ArgumentException).ToString(), Ex.GetType().ToString()));
using (var rw1 = new ResourceWriter(ms2))
{
rw1.AddResource("key1", "args");
rw1.AddResource("key1", "args");
}
}
}
finally
{
rw1.Dispose();
}
}
});
}

[Fact]
public static void ExceptionforResWriter05()
{
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
var rw1 = new ResourceWriter(ms2);
try
{
rw1.AddResource("key2", "args");
}
catch (Exception Ex)
Assert.Throws<InvalidOperationException>(() =>
{
if (Ex.GetType() != typeof(InvalidOperationException))
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(InvalidOperationException).ToString(), Ex.GetType().ToString()));
var rw1 = new ResourceWriter(ms2);
rw1.AddResource("key2", "args");
rw1.Dispose();
rw1.AddResource("key2", "args");
}
}
finally
{
rw1.Dispose();
}
}
});
}

[Fact]
public static void ExceptionforResWriter06()
{
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
var rw1 = new ResourceWriter(ms2);
try
{
rw1.Generate();
}
catch (Exception Ex)
{
if (Ex.GetType() != typeof(ArgumentOutOfRangeException))
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(ArgumentOutOfRangeException).ToString(), Ex.GetType().ToString()));
}
}
finally
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
try
{
rw1.Dispose();
}
catch (Exception Ex)
byte[] buffer = new byte[_RefBuffer.Length];
using (var ms2 = new MemoryStream(buffer, true))
{
if (Ex.GetType() != typeof(System.NotSupportedException))
var rw1 = new ResourceWriter(ms2);
try
{
Assert.True(false, string.Format("Expected {0} but got {1}", typeof(System.NotSupportedException).ToString(), Ex.GetType().ToString()));
rw1.Generate();
}
finally
{
Assert.Throws<NotSupportedException>(() =>
{
rw1.Dispose();
});
}
}
}
}
});
}

[Fact]
Expand Down

0 comments on commit 26423af

Please sign in to comment.