Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renumbered Chapter 18 and added missing listing #557

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading