ProvisionData.Testing.Integration
4.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ProvisionData.Testing.Integration --version 4.0.1
NuGet\Install-Package ProvisionData.Testing.Integration -Version 4.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProvisionData.Testing.Integration" Version="4.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProvisionData.Testing.Integration" Version="4.0.1" />
<PackageReference Include="ProvisionData.Testing.Integration" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ProvisionData.Testing.Integration --version 4.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ProvisionData.Testing.Integration, 4.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ProvisionData.Testing.Integration@4.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ProvisionData.Testing.Integration&version=4.0.1
#tool nuget:?package=ProvisionData.Testing.Integration&version=4.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ProvisionData.Common
A selection of useful classes and utilities commonly used in software by Provision Data Systems Inc.
Installation
You can install the ProvisionData.Common package via NuGet Package Manager Console:
Install-Package ProvisionData.Common
Or via .NET CLI:
dotnet add package ProvisionData.Common
Features
Result Pattern
The Result class provides a way to represent the outcome of operations,
encapsulating success and failure states along with relevant data or error messages.
Basic Usage
public class UserService
{
private readonly IUserRepository _repository;
public Result<User> GetById(int id)
{
var user = _repository.Find(id);
if (user is null)
return Error.NotFound("User.NotFound", $"User with ID {id} was not found");
return user; // Implicit conversion to Result<User>.Success
}
public Result<User> Create(CreateUserRequest request)
{
// Validation
if (string.IsNullOrWhiteSpace(request.Email))
return Error.Validation("User.EmailRequired", "Email is required");
if (_repository.ExistsByEmail(request.Email))
return Error.Conflict("User.EmailExists", "A user with this email already exists");
// Create user
var user = new User(request.Name, request.Email);
_repository.Add(user);
return user;
}
}```
#### Chaining Operations
```csharp
public Result<OrderConfirmation> ProcessOrder(CreateOrderRequest request)
{
return ValidateOrder(request)
.Bind(order => CheckInventory(order))
.Bind(order => ProcessPayment(order))
.Bind(order => CreateShipment(order))
.Map(shipment => new OrderConfirmation(shipment.TrackingNumber));
}
private Result<Order> ValidateOrder(CreateOrderRequest request)
{
if (request.Items.Count == 0)
return Error.Validation("Order.NoItems", "Order must contain at least one item");
return new Order(request.CustomerId, request.Items);
}
private Result<Order> CheckInventory(Order order)
{
foreach (var item in order.Items)
{
if (!_inventory.IsAvailable(item.ProductId, item.Quantity))
return Error.Conflict("Order.OutOfStock", $"Product {item.ProductId} is out of stock");
}
return order;
}
Using Match
var message = userService.GetById(userId).Match(
onSuccess: user => $"Welcome, {user.Name}!",
onFailure: error => $"Error: {error.Description}"
);
Domain Errors
public static class DomainErrors
{
public static class User
{
public static Error NotFound(int id) =>
Error.NotFound("User.NotFound", $"User with ID {id} was not found");
public static Error EmailAlreadyExists(string email) =>
Error.Conflict("User.EmailExists", $"Email {email} is already registered");
public static Error InvalidEmail =>
Error.Validation("User.InvalidEmail", "The email format is invalid");
public static Error PasswordTooWeak =>
Error.Validation("User.PasswordTooWeak",
"Password must be at least 8 characters with uppercase, lowercase, and digits");
}
public static class Order
{
public static Error NotFound(Guid id) =>
Error.NotFound("Order.NotFound", $"Order {id} was not found");
public static Error EmptyCart =>
Error.Validation("Order.EmptyCart", "Cannot create order with empty cart");
public static Error InsufficientStock(string productId) =>
Error.Conflict("Order.InsufficientStock", $"Insufficient stock for product {productId}");
public static Error PaymentFailed(string reason) =>
Error.Failure("Order.PaymentFailed", $"Payment failed: {reason}");
}
}
Web API Integration
var app = builder.Build();
app.MapGet("/api/users/{id}", (int id, UserService userService) =>
{
return userService.GetById(id).ToApiResult();
});
app.MapPost("/api/users", (CreateUserRequest request, UserService userService) =>
{
return userService.Create(request)
.ToCreatedResult($"/api/users/{request.Email}");
});
app.MapPost("/api/orders", (CreateOrderRequest request, OrderService orderService) =>
{
return orderService.ProcessOrder(request).Match(
onSuccess: confirmation => Results.Ok(confirmation),
onFailure: error => error switch
{
ValidationError => Results.BadRequest(new { error.Code, error.Description }),
ConflictError => Results.Conflict(new { error.Code, error.Description }),
_ => Results.Problem(error.Description)
}
);
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- coverlet.collector (>= 6.0.4)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.Hosting (>= 10.0.2)
- xunit.v3.extensibility.core (>= 3.2.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ProvisionData.Testing.Integration:
| Package | Downloads |
|---|---|
|
ProvisionData.Testing.Integration.Examples
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.