Represents the NuGet versions.
- Fixed: Updated
System.Text.Json
package depenedency to latest; resolve Microsoft Security Advisory CVE-2024-43485.
- Fixed: Updated all package depenedencies to latest.
- Enhancement: Added
ExpectJson
andExpectJsonFromResource
toIValueExpectations
to enable value comparison against the specified (expected) JSON.
- Fixed: Added
TraceRequestComparisons
support toMockHttpClient
to enable tracing for all requests.
- Fixed: Added
StringSyntaxAttribute
support to improve intellisense for JSON and URI specification.
- Enhancement: A new
MockHttpClient.WithRequestsFromResource
method enables the specification of the Request/Response configuration from a YAML/JSON embedded resource. Themock.unittestex.json
JSON schema defines content.
- Enhancement: Any configuration specified as part of registering the
HttpClient
services from a Dependency Injection (DI) perspective is ignored by default when creating anHttpClient
using theMockHttpClientFactory
. This default behavior is intended to potentially minimize any side-effect behavior that may occur that is not intended for the unit testing. SeeREADME
for more details on capabilities introduced; highlights are:- New
MockHttpClient.WithConfigurations
method indicates that theHttpMessageHandler
andHttpClient
configurations are to be used. - New
MockHttpClient.WithoutMocking
method indicates that the underlyingHttpClient
is not to be mocked; i.e. will result in an actual/real HTTP request to the specified endpoint. This will allow the mixing of real and mocked HTTP requests within the same test.
- New
- Fixed: The
AssertLocationHeader
has been corrected to also support the specification of theUri
as a string. Additionally, contains support has been added withAssertLocationHeaderContains
.
- Fixed: The
TypeTester
was not correctly capturing and outputting any of the logging, and also (as a result) theExpectLogContains
was not functioning as expected.
- Enhancement: Removed the
FunctionsStartup
constraint forTEntryPoint
to enable more generic usage. - Enhancement: Enable
Microsoft.Azure.Functions.Worker.HttpTriggerAttribute
(new isolated function support), in addition to existingMicrosoft.Azure.WebJobs.HttpTriggerAttribute
(existing in-process function support), withinHttpTriggerTester
. - Enhancement: Enable
Microsoft.Azure.Functions.Worker.ServiceBusTriggerAttribute
(new isolated function support), in addition to existingMicrosoft.Azure.WebJobs.ServiceBusTriggerAttribute
(existing in-process function support), withinServiceBusTriggerTester
.- Additionally,
CreateServiceBusMessageActions
is being renamed toCreateWebJobsServiceBusMessageActions
; a newCreateWorkerServiceBusMessageActions
has been introduced to support isolatedMicrosoft.Azure.Functions.Worker.ServiceBusTriggerAttribute
testing.
- Additionally,
- Enhancement: Upgraded
NUnit
dependency to4.0.1
; all unit tests now leverage theNUnit
constraint model testing approach.- Note: Also, as a result it is recommended prior to upgrading to
v4.1.0
, where usingNUnit
, that all existing unit tests are updated to use the new constraint model testing approach; see migration guide for details.
- Note: Also, as a result it is recommended prior to upgrading to
- Fixed: The
FunctionTesterBase
was updated to correctly load the configuration in the order similar to that performed by the Azure Functions runtime fabric. - Fixed: Removed all dependencies to
Newtonsoft.Json
; a developer will need to explicitly add this dependency andIJsonSerializer
implementation where applicable.
All internal dependecies to CoreEx
have been removed. This is intended to further generalize the capabilities of UnitTestEx
; but more importantly, break the circular dependency reference between the two repositories. New CoreEx.UnitTesting*
packages have been created to extend the UnitTestEx
capabilities for CoreEx
.
- Enhancement: All typed value assertions have been named
AssertValue
for consistency; otherwise,AssertContent
for a simple string comparison. - Enhancement: All JSON-related assertions have been named
AssertJson*
for consistency. - Enhancement: The
CreateServiceBusMessage
methods that accept a genericT
value have been renamed toCreateServiceBusMessageFromValue
. - Enhancement: The
Expectations
capabilities have been greatly improved to support new expectations to be added/extended. - Enhancement: A new
GenericTester
that explicitly supports aTValue
has been added; use newGenericTester.CreateFor<TValue>
to instantiate/use. - Enhancement: Removed
KellermanSoftware.CompareNetObjects
dependency; all comparisons use internalJsonElementComparer
which has proper/improved support for fully qualified paths, including optional array indexers. The relatedJsonElementComparerOptions
provides a means to control the comparison behaviour. - Enhancement: The
ObjectComparer
has been reinstated and now leverages theJsonElementComparer
internally. - Enhancement: Updated to only support
.NET6.0
and above; added.NET8.0
support.
The enhancements have been made in a manner to maximize backwards compatibility with previous versions of UnitTestEx
where possible; however, some breaking changes were unfortunately unavoidable (and made to improve overall). There may be an opportunity for the consuming developer to add extension methods to support the previous naming conventions if desired; note that the next CoreEx
version (v3.6.0
) will implement extensions in new CoreEx.UnitTesting
packages to support existing behaviors (where applicable).
- Enhancement: Updated all package depenedencies to latest.
- Enhancement: The
GenericTester
updated to supportIHostStartup
to enable shared host dependency injection configuration. - Enhancement: Added
IEventExpectations<TSelf>
andILoggerExpectations<TSelf>
support toGenericTester
andValidationTester
. - Enhancement: Moved the
CreateServiceBusMessage
and related methods fromFunctionTesterBase
up the inheritance hierarchy toTesterBase<TSelf>
to enable broader usage. - Enhancement: Added
ExpectEventFromJsonResource
andExpectDestinationEventFromJsonResource
expectations to simplify specification versus having to instantiateEventData
. - Enhancement: The
JsonElementComparer
now defaults to case-insensitive comparison. - Enhancement: All internal usage of the
ObjectComparer
replaced with usage of theJsonElementComparer
to break external dependency. AllMembersToIgnore
have been replaced withPathsToIgnore
(being the fully-qualified JSON path) as this is more explicit and less error prone. TheObjectComparer
has been flagged asObsolete
and will be removed in a later version.
- Enhancement: Updated
CoreEx
dependencies to3.0.0
as breaking changes were introduced. There are no breaking changes withinUnitTestEx
as a result; primarily related to the keyCoreEx
dependency.- Given the
CoreEx
dependency, explicitly the creation of the newCoreEx.AspNetCore
, thisUnitTextEx
version is not backwards compatible with previous versions ofCoreEx
(i.e.2.x.x
).
- Given the
- Enhancement: Updated all package dependencies to latest.
- Fixed: Corrected the log output to ensure they appear in sequence logged.
- Fixed: The
ServiceBusMessageActionsAssertor
logging now logs regardless of whether it is the last parameter in the method being executed. - Fixed: The loading of the
appsettings.unittest.json
has been moved after theFunctionsStartup.ConfigureAppConfiguration
to override correctly.
- Fixed: Extended the
FunctionTesterBase
to enableCreateServiceBusMessageActions
andCreateServiceBusSessionMessageActions
similar toCreateServiceBusMessage
to enable mocked, unit testable, assert enabled, actions.
- Fixed: The
MockHttpClientRequest
request Uri validation fixed.
- Fixed: The
MockHttpClientRequest
request validation predicate has been improved to handle URL encoding. - Enhancement: The
FunctionTesterBase
has been extended to support the creation of aServiceBusReceivedMessage
usingCreateServiceBusMessage(EventData)
,CreateServiceBusMessage(ServiceBusMessage)
andCreateServiceBusMessage(AmqpAnnotatedMessage)
. - Enhancement: Added
ExpectLogContains
expectation to confirm that the log output contains the specified text. - Enhancement: Updated all package dependencies to latest.
- Enhancement: Added
.NET7.0
support to allUnitTestEx
packages.
- Fixed: The
EventExpectations
internally assigned members to ignore updated to useClassName.MemberName
syntax to explicitly ignore. - Fixed: Added
ExpectEventValue
andExpectDestinationEventValue
expectations to simplify specification versus having to instantiateEventData
with expectedValue
. - Fixed: To remove any
EventData.Value
implementation (Type
) differences theEventData
is now serialized during runtime publish, then deserialized prior to expectation check within test.
- Issue 52:
UnitTestBase.TestServer
is nowpublic
(versus previousprotected
). - Issue 51: Anonymous types create read-only properties; these were by default ignored when comparing. Read-only properties are now included by default within the
ObjectComparer
; note that these defaults can be overridden where applicable.
- Fixed: Incorrect package deployment; corrected.
- Enhancement: Added
TestSetUp.RegisterAutoSetUp
that will automatically throw aTestSetUpException
where unsuccessful; otherwise, queues the successful output message. This is required as most testing frameworks do not allow for a log write during construction or fuxture set up. The underlying UnitTestEx test classes will automatically log write where entries are discovered in the queue. This will at least ensure one of the underlying tests will output the success output where applicable. Otherwise, to log write explicitly useTestSetUp.LogAutoSetUpOutputs
.
- Enhancement: Updated
CoreEx
dependencies to2.0.0
as breaking changes were introduced. There are no breaking changes withinUnitTestEx
as a result; primarily related to the keyCoreEx
dependency.
- Enhancement:
TestSetUp
cloned (fromTestSetUp.Default
) perTesterBase
instance to allow specific test changes. - Enhancement:
EventExpectations
now supportsHasEvents
which simply verifies that one or more events were sent (ignores contents). - Enhancement:
ValidationTester
extended to supportRunCode
methods that execute passed action/function then catch and validate any thrownValidationException
. - Enhancement: Added user identifier (
object
) support forUseUser
andWithUser
that leverages theTestSetUp.UserNameConverter
. - Enhancement: Underlying host created within the context of a
lock
to ensure thread-safety. Protections now in place to prohibit further changes once host has been created (ResetHost
added to explicitly enable further changes if/when needed). - Enhancement
HttpTesterBase
supports multi-threaded logging leveraging the newunit-test-ex-request-id
header to coordinate between test and api.
- Enhancement: Moved
username
from all constructors toUseUser(userName)
method. Additional,WithUser(userName)
added toApiTester
to override the user name for a specific test invocation. - Enhancement: All references to
Username
renamed toUserName
for consistency with the .NET framework naming convention. - Enhancement: Added
UsingApiTester
to provide a sharedApiTester
instance per test class; versus instantiating per test method. Be aware that using may result in cross-test contamination. - Enhancement: The
ILogger
test instances updated to useTestSharedState
as a means to pass between hosted process and test process. Be aware that when tests are executed asynchronously there is currently no guarantee that the logs will be attributed to the correct test. - Enhancement: Added
TestSetUp.Environment
to specify the .NET environment for the likes of configuration file loading; defaults toDevelopment
. - Enhancement: The mocked
Response.RequestMessage
property is now updated with the initiating request. - Enhancement: Support for mocked default (unnamed)
HttpClient
added viaMockHttpClientFactory.CreateDefaultClient
method.
- Fixed: Renamed
Expect
extensions methods to match convention consistently. - Enhancement: Added
SystemExtensionMethods
class to enable the likes ofint.ToGuid()
for setting test-orientedGuid
values. - Fixed:
ApiTester
updated such thatappsettings.unittest.json
is optional. - Enhancement: Added
ValidationTester
to support testing of anIValidator
directly. - Enhancement: Added
GenericTester
to support testing of any generic code directly. - Fixed: Handle
AggregateException
by using itsInnerException
as theException
.
- Enhancement: Updated the
ControllerTester
removing the HTTP request capabilies and moving into newHttpTester
; this creates a more logical split as the latter needs no knowledge of theController
. This new tester is available viaApiTester.Http().Run(...)
. - Enhancement: Added new
UnitTextEx.Expectations
namespace; when added will enableExpect*
andIgnore*
pre-execution assertions, that are then executed postRun
/RunAsync
. Some testers now also support the specification of aTResponse
genericType
to enable further response value-related expectations.
- Fixed: The mock verification was not correctly updating the counter where there was a timeout. This has been corrected.
- Enhancement: Update
CoreEx
dependencies to1.0.4
. - Fixed: Updated the Mock verification code and customized implementation to improve checking and error message.
- Enhancement: Update
CoreEx
dependencies to1.0.3
. - Enhancement: Improve precision of milliseconds logging.
- Fixed: Expression invocation was incorrectly being invoked twice (and within the same scope), one with an await and the other without, racing each other and referencing the same DI scoped instances.
- Fixed: Added extra validation to test methods that accept expressions to ensure only simple expressions (no method-chaining) are allowed. There are other non-expression methods that should be used to enable these more advanced scenarios. In doing so however, some validation and logging features may not work as well as the expression enabled functionalities.
- Fixed: Where using
MockHttpClientResponse.Delay
this was performing aThread.Sleep
internally which ignored the usage of theCancellationToken
passed into theSendAsync
. TheThread.Sleep
has been replaced with aTask.Delay
which is now passed theCancellationToken
from the caller. This has also been extended where usingWithSequence
.
- Fixed: Prior change for
ApiTester
related toappsettings.unittest.json
was not loading early enough and therefore not available forstartup
configuration activities. This has now been resolved by pre-reading and adding as in-process environment variables. - Enhancement: Added
TypeTester
support toApiTester
. - Enhancement:
TypeTester
updated toRun
synchronous methods as well as asynchronous. - Issue 30: Added support to specify the default JSON serializer via
appsettings.unittest.json
. The following JSON will set theCoreEx.Json.JsonSerializer.Default
to useCoreEx.Newtonsoft.Json.JsonSerializer
versus the defaultCoreEx.Text.Json.JsonSerializer
:{ "DefaultJsonSerializer": "Newtonsoft.Json" }
.
- Fixed:
ApiTester
was not finding theappsettings.json
from originating solution. Updated the content root explicitly with the current directory:UseSolutionRelativeContentRoot(Environment.CurrentDirectory)
. - Enhancement: Added support for finding
appsettings.unittest.json
file, always added last to override any other previous settings (including environment variables, etc.). - Fixed:
MockHttpClientRequest
was incorrectly comparing the URL with an unencoded version; will always compare the original URL which must match on encodings also.
- Enhancement: Added additional
FunctionTesterBase.CreateHttpRequest
overloads to specify theContent-Type
; defaults toMediaTypeNames.Text.Plain
. - Enhancement: Breaking change. Renamed
ControllerTester.RunWithRequest
toRunHttpRequest
to be more aligned toFunctionTesterBase
. Also updated to support same set of overloads for consistency. - Enhancement: Improved the test logging such that the pre-execution details, such as HTTP request content, is output prior to execution to aid debugging of any exceptions/failures.
- Enhancement: Added
ActionResultAssertor.GetValue
andAssertJson
to be consistent withHttpResponseMessageAssertor
. - Enhancement: Added
AssertLocationHeader
andAssertETagHeader
to bothHttpResponseMessageAssertor
andActionResultAssertor
(forValueContentResult
). - Enhancement: Updated
JsonElementComparer
to return/list the differences found. Also, supportsPathsToIgnore
functionality. - Enhancement: Added
MockHttpClientRequest.TraceRequestComparisons
that indicates whether the request content comparison differences should be trace logged to aid in debugging/troubleshooting.
- Enhancement: Added body value parameter to the
ControllerTester
to allow where not directly specified for the underlying run method. - Enhancement: Added
HttpRequestOptions
parameter to theControllerTester
to allow further control and configuration of theUri
for theRun
methods. - Enhancement: Added some additional HTTP status code assertors.
- Enhancement:
HttpResponseMessageAssertor.AssertJson
added to support JSON comparisons where noType
is known. - Enhancement:
HttpResponseMessageAssertor.GetValue<TCollResult, TColl, TItem>
added to supportICollectionResult
responses.
- Issue 27: The
TypeTester
has been updated to ensure the result is logged correctly regardless of underlyingType
. - Issue 28: The
FunctionTester
has been updated to be more resilient to the JSON withinlocal.settings.json
; i.e. ignore comments and trailing commas. - Enhancement:
ApiTester
andFunctionTester
updated to provide aGetLogger<TCategoryName>
method to simplify access to a typed logger.
- Enhancement: Breaking change. Integrate
CoreEx
package which primarily bringsIJsonSerializer
functionality to enable configuration of eitherCoreEx.Text.Json.JsonSerializer
(default) orCoreEx.Newtonsoft.Json.JsonSerializer
. TheMockHttpClientFactory
,ApiTester
andFunctionTester
have new methodUseJsonSerializer
to individually update from the default. To change the default for all tests then setCoreEx.Json.JsonSerializer.Default
to the desired serializer. - Enhancement: Improved the replacement of the
MockHttpClientFactory
with theApiTester
andFunctionTester
. Existing codetest.ConfigureServices(sc => mcf.Replace(sc))
can be replaced withtest.ReplaceHttpClientFactory(mcf)
. - Enhancement: Added
ReplaceSingleton
,ReplaceScoped
andReplaceTransient
methods directly toApiTester
andFunctionTester
. For example, existing codetest.ConfigureServices(sc => sc.ReplaceTransient<XXX>())
can be replaced withtest.ReplaceTransient<XXX>()
. - Enhancement: Added addtional
CreateHttpRequest
overloads to support additional parametersHttpRequestOptions? requestOptions = null, params IHttpArg[] args
as enabled byCoreEx
. These enable additional capabilities for theHttpRequest
query string and headers.
- Issue 24: Added additional
IServiceCollection.Replace
extension methods to supportReplaceXxx<T>()
andReplaceXxx<T, T>()
to match the standardAddXxx
methods.
- Issue 22:
TypeTester.Run
andRunAsync
methods updated to supportFunc
versusExpression<Func>
to simplify runtime usage.
- Issue 20: Enabled casting of a
ResultAssertor
to anActionResultAssertor
where the resultType
isIActionResult
via theResultAssertor.ToActionResultAssertor
method. - Enhancement: Enabled casting of a
ResultAssertor
to anHttpResponseMessageAssertor
where the resultType
isHttpResponseMessage
via theResultAssertor.HttpResponseMessageAssertor
method.
- Issue 18:
ActionResultAssertor.Assert
with object value was not performing correct comparison when result isContentResult
and the underlyingContentType
wasJson
. - Enhancement: Write the
Contents
to the test output where the result isContentResult
.
- Issue 12:
ObjectComparer.Assert
added for each test framework that compares two objects and will fail, and report, where there is not a match. - Issue 14: Re-introduced
ServiceBusTriggerTester
which manages execution and automatically logs the value associated with the trigger. - Issue 14: The
ServiceBusTriggerTester.Emulate
(ServiceBusEmulatorTester
) manages the execution of theServiceBusTriggerAttribue
function method by orchestrating Azure Service Bus integration in a similar manner as if the Azure function run-time proper had invoked. - PR 16: Support all media types in
MockHttpClientRequest
. - Enhancement: All
Run
methods now support aRunAsync
where appropriate.
- Issue 10: Breaking change. Changed the
ActionResultAssertor.AssertAccepted
andActionResultAssertor.AssertCreated
to assert status only; the existing value check should be performed using theActionResultAssertor.Assert
. Pattern now is to check status and value separately (no longer all inclusive). - Issue 10: Breaking change. Changed the
HttpResponseMessageAssertor.AssertAccepted
andHttpResponseMessageAssertor.AssertCreated
to assert status only; the existing value check should be performed using theActionResultAssertor.Assert
. Pattern now is to check status and value separately (no longer all inclusive). - Issue 10: Breaking change. Changed
ActionResultAssertor.AssertBadRequest
andHttpResponseMessageAssertor.AssertBadRequest
to assert status only; added newAssertErrors
to each for error message asserting. - Issue 9: Add
Services
property (IServicesCollection
) to bothApiTesterBase
andFunctionTesterBase
. This allows direct access to the underlyingServices
outside of the more typicalRun
.
- Issue 7: Added delay (sleep) option so response is not always immediate.
- Enhancement: Breaking change.
Functions.GenericTriggerTester
replaced withHosting.TypeTester
as agnostic to any function trigger.Functions.TriggerTesterBase
replaced withHosting.HostTesterBase
for same agnostic reasoning.FunctionTestBase.GenericTrigger
method renamed toFunctionTestBase.Type
so as to not imply a trigger requirement (i.e. can be any Type+Method that needs testing).
- Issue 3: Added support for MOQ
Times
struct to verify the number of times a request is made. - Issue 4: Added support for MOQ sequences; i.e. multiple different responses.
- Issue 5: Deleted
MockServiceBus
as the mocking failed to work as intended. This has been replaced byFunctionTesterBase
methods ofCreateServiceBusMessage
,CreateServiceBusMessageFromResource
andCreateServiceBusMessageFromJson
.
- Fixed:
MockHttpClientFactory.CreateClient
overloads were ambiquous, this has been corrected. - Fixed: Resolved logging output challenges between the various test frameworks and
ApiTester
(specifically) to achieve consistent output. - Enhancement: The logging output now includes scope details.
- Added: New
MockServiceBus.CreateReceivedMessage
which will mock theServiceBusReceivedMessage
and add the passed value as serialized JSON into theBody
(BinaryData
).
- Added: A new
GenericTestertrigger
has been enabled for non HTTP-triggered functions. - Added: Assert capabilities, where applicable, support runtime
Exception
capturing, and haveAssertSuccess
andAssertException
accordingly. There is a newVoidAsserter
to ensure success or exception where a function isvoid
.
- New: Initial publish to GitHub/NuGet.