Skip to content
Draft
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
2 changes: 2 additions & 0 deletions FluentAssertions/Assembly-CSharp.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests_005Ceditor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests_005Ceditor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Ctests_005Ceditor_005Cmathematics/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption_005Cmathematics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption_005Cmathematics_005Cextensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption_005Cassertions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packages_005Ccom_002Eboundfoxstudios_002Efluentassertions_005Cruntime_005Cunityadoption_005Cextensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BoundfoxStudios.FluentAssertions",
"rootNamespace": "",
"rootNamespace": "BoundfoxStudios.FluentAssertions",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// ReSharper disable once CheckNamespace

namespace FluentAssertions.Common
{
internal class AppSettingsConfigurationStore : IConfigurationStore
{
public string GetSetting(string name)
{
return ""; // TODO: This is basically the same as the NullConfigurationProvider. Let's see, if we need to wire this up in Unity somehow.
}
public string GetSetting(string name) => ""; // TODO: This is basically the same as the NullConfigurationProvider. Let's see, if we need to wire this up in Unity somehow.
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using FluentAssertions;
using FluentAssertions.Execution;
using JetBrains.Annotations;

namespace BoundfoxStudios.FluentAssertions
{
public abstract class MathematicsAssertions<TSubject> : MathematicsAssertions<TSubject, MathematicsAssertions<TSubject>>
where TSubject : struct, IEquatable<TSubject>, IFormattable
{
protected MathematicsAssertions(TSubject subject) : base(subject) { }
}

[DebuggerNonUserCode]
public abstract class MathematicsAssertions<TSubject, TAssertions>
where TSubject : struct, IEquatable<TSubject>, IFormattable
where TAssertions : MathematicsAssertions<TSubject, TAssertions>
{
public MathematicsAssertions(TSubject subject) : this((TSubject?)subject) { }

private protected MathematicsAssertions(TSubject? subject) => Subject = subject;

/// <summary>
/// Gets the object which value is being asserted.
/// </summary>
public TSubject? Subject { get; }

public AndConstraint<TAssertions> Be(TSubject expected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(expected) == true)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to be {0}{reason}, but found {1}" + GenerateDifferenceMessage(expected), expected, Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> Be(TSubject? expected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(expected is { } value ? Subject?.Equals(value) == true : !Subject.HasValue)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to be {0}{reason}, but found {1}" + GenerateDifferenceMessage(expected), expected, Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> NotBe(TSubject unexpected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(unexpected) == false)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to be {0}{reason}, but found {1}" + GenerateDifferenceMessage(unexpected), unexpected, Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> NotBe(TSubject? unexpected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(unexpected is { } value ? Subject?.Equals(value) == false : Subject.HasValue)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to be {0}{reason}, but found {1}" + GenerateDifferenceMessage(unexpected), unexpected, Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> BeOneOf(params TSubject[] validValues) => BeOneOf(validValues, string.Empty);

public AndConstraint<TAssertions> BeOneOf(IEnumerable<TSubject> validValues, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject is { } value && validValues.Contains(value))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to be one of {0}{reason}, but found {1}.", validValues, Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> BeOfType(Type expectedType, string because = "", params object[] becauseArgs)
{
Guard.AgainstNull(expectedType, nameof(expectedType));

var subjectType = Subject?.GetType();
if (expectedType.IsGenericTypeDefinition && subjectType?.IsGenericType == true)
{
subjectType.GetGenericTypeDefinition().Should().Be(expectedType, because, becauseArgs);
}
else
{
subjectType.Should().Be(expectedType, because, becauseArgs);
}

return new((TAssertions)this);
}

public AndConstraint<TAssertions> NotBeOfType(Type unexpectedType, string because = "", params object[] becauseArgs)
{
Guard.AgainstNull(unexpectedType, nameof(unexpectedType));

Execute.Assertion
.ForCondition(Subject.HasValue)
.BecauseOf(because, becauseArgs)
.FailWith("Expected type not to be " + unexpectedType + "{reason}, but found <null>.");

Subject.GetType().Should().NotBe(unexpectedType, because, becauseArgs);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> Match(Expression<Func<TSubject, bool>> predicate,
string because = "",
params object[] becauseArgs)
{
Guard.AgainstNull(predicate, nameof(predicate));

Execute.Assertion
.ForCondition(predicate.Compile()((TSubject)Subject))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:value} to match {0}{reason}, but found {1}.", predicate.Body, Subject);

return new((TAssertions)this);
}

[CanBeNull]
private protected virtual string CalculateDifferenceForFailureMessage(TSubject subject, TSubject expected) => null;

private string GenerateDifferenceMessage(TSubject? expected)
{
const string noDifferenceMessage = ".";

if (Subject is not { } subject || expected is not { } expectedValue)
{
return noDifferenceMessage;
}

var difference = CalculateDifferenceForFailureMessage(subject, expectedValue);
return difference is null ? noDifferenceMessage : $" (difference of {difference}";
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Diagnostics;
using System.Linq.Expressions;
using FluentAssertions;
using FluentAssertions.Execution;

namespace BoundfoxStudios.FluentAssertions
{
[DebuggerNonUserCode]
public abstract class NullableMathematicsAssertions<TSubject> : MathematicsAssertions<TSubject, NullableMathematicsAssertions<TSubject>>
where TSubject : struct, IEquatable<TSubject>, IFormattable
{
public NullableMathematicsAssertions(TSubject? subject) : base(subject) { }
}

[DebuggerNonUserCode]
public abstract class NullableMathematicsAssertions<TSubject, TAssertions> : MathematicsAssertions<TSubject, TAssertions>
where TSubject : struct, IEquatable<TSubject>, IFormattable
where TAssertions : NullableMathematicsAssertions<TSubject, TAssertions>
{
public NullableMathematicsAssertions(TSubject? subject) : base(subject) { }

public AndConstraint<TAssertions> HaveValue(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject.HasValue)
.BecauseOf(because, becauseArgs)
.FailWith("Expected a value{reason}.");

return new((TAssertions)this);
}

public AndConstraint<TAssertions> NotBeNull(string because = "", params object[] becauseArgs) => HaveValue(because, becauseArgs);

public AndConstraint<TAssertions> NotHaveValue(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(!Subject.HasValue)
.BecauseOf(because, becauseArgs)
.FailWith("Did not expect a value{reason}, but found {0}.", Subject);

return new((TAssertions)this);
}

public AndConstraint<TAssertions> BeNull(string because = "", params object[] becauseArgs) => NotHaveValue(because, becauseArgs);

public AndConstraint<TAssertions> Match(Expression<Func<TSubject?, bool>> predicate,
string because = "",
params object[] becauseArgs)
{
Guard.AgainstNull(predicate, nameof(predicate));

Execute.Assertion
.ForCondition(predicate.Compile()(Subject))
.BecauseOf(because, becauseArgs)
.FailWith("Expected value to match {0}{reason}, but found {1}.", predicate, Subject);

return new((TAssertions)this);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading