Skip to content

Commit

Permalink
Renumbered Chapter 18 and added missing listing (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMichaelis committed Sep 21, 2023
1 parent 3c1817c commit 77f4edd
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17.Tests;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16.Tests;

[TestClass]
public class ProgramTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25.Tests;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24.Tests;

[TestClass]
public class ProgramTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27.Tests;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26.Tests;

#if NET7_0_OR_GREATER
[TestClass]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28.Tests;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27.Tests;

#if NET7_0_OR_GREATER
[TestClass]
Expand All @@ -27,29 +27,6 @@ public void VerifyExpectedExceptionMessage()
}
}

[TestMethod]
public void Method()
{
try
{
SampleTests.Method();
}
catch (InvalidOperationException exception)
{
Assert.IsTrue(
exception.Message.Contains("'() => { }'") &&
exception.Message.Contains("'Method'") &&
exception.Message.Contains("'./FileName.cs'"));
// The expected exception, System.DivideByZeroException,
// was not thrown by the expression, 'Method' in the method, './FileName.cs', and file 'C:\Git\EssentialCSharp\src\Chapter18\Listing18.25b.CallerArgumentExpression.cs'.
}
}

private object PassingMethodNameAndFileName()
{
throw new NotImplementedException();
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void ExpectedExceptionIsNotThrown()
Expand Down
27 changes: 27 additions & 0 deletions src/Chapter18.Tests/Listing18.28a.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28.Tests;

#if NET7_0_OR_GREATER
[TestClass]
public class GenericExceptionTests
{
[TestMethod]
public void Method()
{
try
{
Program.Main();
}
catch (InvalidOperationException exception)
{
Assert.IsTrue(
exception.Message.Contains("'() => { }'") &&
exception.Message.Contains("'Method'") &&
exception.Message.Contains("'./FileName.cs'"));
// The expected exception, System.DivideByZeroException,
// was not thrown by the expression, 'Method' in the method, './FileName.cs', and file 'C:\Git\EssentialCSharp\src\Chapter18\Listing18.25b.CallerArgumentExpression.cs'.
}
}
}
#endif // NET7_0_OR_GREATER
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_14;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_13;

#region INCLUDE
public class CommandLineSwitchRequiredAttribute : Attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_14;

#region INCLUDE
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15;

#region INCLUDE
public class CommandLineSwitchAliasAttribute : Attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16;

using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16;
using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15;
using System.Reflection;

public class Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_18;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17;

#region INCLUDE
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_19;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_18;

using Listing18_18;
using Listing18_17;
#region INCLUDE
using System.Reflection;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_20;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_19;

#region INCLUDE
[AttributeUsage(AttributeTargets.Property)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_21;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_20;

// Will not compile if uncommented
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_22;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_21;

#region INCLUDE
// Restrict the attribute to properties and methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_23;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_22;

#region INCLUDE
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_23;

#region INCLUDE
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region INCLUDE
#define CONDITION_A
#region EXCLUDE
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24;

#endregion EXCLUDE
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25;

#region INCLUDE
public class Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26;

#if NET7_0_OR_GREATER
#region INCLUDE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27;

#if NET7_0_OR_GREATER
#region INCLUDE
Expand All @@ -13,12 +13,6 @@ public static void ThrowArgumentNullExceptionTest()
{
var result = 1/"".Length;
}

public static void Method()
{
ExpectedException<DivideByZeroException>.AssertExceptionThrown(
() => throw new DivideByZeroException());
}
}

[AttributeUsage(AttributeTargets.Method)]
Expand Down
16 changes: 16 additions & 0 deletions src/Chapter18/Listing18.28.InvokingCallerAttributesMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28;

#if NET7_0_OR_GREATER
public class Program
{
public static void Main()
{
#region INCLUDE
ExpectedException<DivideByZeroException>.AssertExceptionThrown(
() => throw new DivideByZeroException());
#endregion INCLUDE
}
}
#endif // NET7_0_OR_GREATER

0 comments on commit 77f4edd

Please sign in to comment.