Skip to content

Commit

Permalink
Merge pull request #41344 from dotnet/main
Browse files Browse the repository at this point in the history
Merge main into live
  • Loading branch information
dotnet-policy-service[bot] committed Jun 8, 2024
2 parents 11e8b44 + b55fd6d commit b17760b
Show file tree
Hide file tree
Showing 83 changed files with 1,269 additions and 1,295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public partial class Counter : System.Web.UI.UserControl
}
```

In Blazor, you can register handlers for DOM UI events directly using directive attributes of the form `@on{event}`. The `{event}` placeholder represents the name of the event. For example, you can listen for button clicks like this:
In Blazor, you can register handlers for DOM UI events directly `using` directive attributes of the form `@on{event}`. The `{event}` placeholder represents the name of the event. For example, you can listen for button clicks like this:

```razor
<button @onclick="OnClick">Click me!</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ builder.Services.AddDefaultIdentity<IdentityUser>(options =>
.AddEntityFrameworkStores<ApplicationDbContext>();
```

The `AddDefaultIdentity` extension method is used to configure Identity to use the default `ApplicationDbContext` and the framework's `IdentityUser` type. If you're using a custom `IdentityUser`, be sure to specify its type here. If these extension methods aren't working in your application, check that you have the appropriate using statements and that you have the necessary NuGet package references. For example, your project should have some version of the `Microsoft.AspNetCore.Identity.EntityFrameworkCore` and `Microsoft.AspNetCore.Identity.UI` packages referenced.
The `AddDefaultIdentity` extension method is used to configure Identity to use the default `ApplicationDbContext` and the framework's `IdentityUser` type. If you're using a custom `IdentityUser`, be sure to specify its type here. If these extension methods aren't working in your application, check that you have the appropriate `using` directives and that you have the necessary NuGet package references. For example, your project should have some version of the `Microsoft.AspNetCore.Identity.EntityFrameworkCore` and `Microsoft.AspNetCore.Identity.UI` packages referenced.

Also in *Program.cs* you should see the necessary middleware configured for the site. Specifically, `UseAuthentication` and `UseAuthorization` should be set up, and in the proper location.

Expand Down
48 changes: 24 additions & 24 deletions docs/architecture/maui/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ Testing models and view models from MVVM applications is identical to testing an

> [!TIP]
> Test one thing with each unit test. As the complexity of a test expands, it makes verification of that test more difficult. By limiting a unit test to a single concern, we can ensure that our tests are more repeatable, isolated, and have a smaller execution time. See
[Unit testing best practices with .NET Core and .NET Standard](../../core/testing/unit-testing-best-practices.md) for more best practices.
[Unit testing best practices with .NET](../../core/testing/unit-testing-best-practices.md) for more best practices.

Don't be tempted to make a unit test exercise more than one aspect of the unit's behavior. Doing so leads to tests that are difficult to read and update. It can also lead to confusion when interpreting a failure.

The eShop multi-platform app uses [xUnit](https://xunit.net/) to perform unit testing, which supports two different types of unit tests:
The eShop multi-platform app uses [MSTest](../../core/testing/unit-testing-with-mstest.md) to perform unit testing, which supports two different types of unit tests:

| Testing Type | Attribute | Description |
|--------------|-----------|--------------------------------------------------------------|
| Facts | `Fact` | Tests that are always true, which test invariant conditions. |
| Theories | `Theory` | Tests that are only true for a particular set of data. |
| Testing Type | Attribute | Description |
|-----------------|--------------|--------------------------------------------------------------|
| TestMethod | `TestMethod` | Defines the actual test method to run.. |
| DataSource | `DataSource` | Tests that are only true for a particular set of data. |

The unit tests included with the eShop multi-platform app are fact tests, so each unit test method is decorated with the `Fact` attribute.
The unit tests included with the eShop multi-platform app are TestMethod, so each unit test method is decorated with the `TestMethod` attribute. In addition to MSTest there are several other testing frameworks available including [NUnit](../../core/testing/unit-testing-with-nunit.md) and [xUnit](../../core/testing/unit-testing-with-dotnet-test.md).

## Testing asynchronous functionality

When implementing the MVVM pattern, view models usually invoke operations on services, often asynchronously. Tests for code that invokes these operations typically use mocks as replacements for the actual services. The following code example demonstrates testing asynchronous functionality by passing a mock service into a view model:

```csharp
[Fact]
[TestMethod]
public async Task OrderPropertyIsNotNullAfterViewModelInitializationTest()
{
// Arrange
Expand All @@ -88,7 +88,7 @@ public async Task OrderPropertyIsNotNullAfterViewModelInitializationTest()
await orderViewModel.InitializeAsync(order);

// Assert
Assert.NotNull(orderViewModel.Order);
Assert.IsNotNull(orderViewModel.Order);
}
```

Expand All @@ -103,7 +103,7 @@ Implementing the `INotifyPropertyChanged` interface allows views to react to cha
Properties that can be updated directly by the unit test can be tested by attaching an event handler to the `PropertyChanged` event and checking whether the event is raised after setting a new value for the property. The following code example shows such a test:

```csharp
[Fact]
[TestMethod]
public async Task SettingOrderPropertyShouldRaisePropertyChanged()
{
    var invoked = false;
Expand All @@ -118,7 +118,7 @@ public async Task SettingOrderPropertyShouldRaisePropertyChanged()
    var order = await orderService.GetOrderAsync(1GlobalSetting.Instance.AuthToken);
    await orderViewModel.InitializeAsync(order);

    Assert.True(invoked);
    Assert.IsTrue(invoked);
}
```

Expand All @@ -129,7 +129,7 @@ This unit test invokes the `InitializeAsync` method of the `OrderViewModel` clas
View models that use the `MessagingCenter` class to communicate between loosely coupled classes can be unit tested by subscribing to the message being sent by the code under test, as demonstrated in the following code example:

```csharp
[Fact]
[TestMethod]
public void AddCatalogItemCommandSendsAddProductMessageTest()
{
    var messageReceived = false;
Expand All @@ -143,7 +143,7 @@ public void AddCatalogItemCommandSendsAddProductMessageTest()
    });
    catalogViewModel.AddCatalogItemCommand.Execute(null);

    Assert.True(messageReceived);
    Assert.IsTrue(messageReceived);
}
```

Expand All @@ -154,7 +154,7 @@ This unit test checks that the `CatalogViewModel` publishes the `AddProduct` mes
Unit tests can also be written that check that specific exceptions are thrown for invalid actions or inputs, as demonstrated in the following code example:

```csharp
[Fact]
[TestMethod]
public void InvalidEventNameShouldThrowArgumentExceptionText()
{
    var behavior = new MockEventToCommandBehavior
Expand All @@ -179,7 +179,7 @@ There are two aspects to testing the validation implementation: testing that any
Validation logic is usually simple to test, because it is typically a self-contained process where the output depends on the input. There should be tests on the results of invoking the `Validate` method on each property that has at least one associated validation rule, as demonstrated in the following code example:

```csharp
[Fact]
[TestMethod]
public void CheckValidationPassesWhenBothPropertiesHaveDataTest()
{
    var mockViewModel = new MockViewModel();
Expand All @@ -188,7 +188,7 @@ public void CheckValidationPassesWhenBothPropertiesHaveDataTest()

    var isValid = mockViewModel.Validate();

    Assert.True(isValid);
    Assert.IsTrue(isValid);
}
```

Expand All @@ -197,21 +197,21 @@ This unit test checks that validation succeeds when the two `ValidatableObject<T
As well as checking that validation succeeds, validation unit tests should also check the values of the `Value`, `IsValid`, and `Errors` property of each `ValidatableObject<T>` instance, to verify that the class performs as expected. The following code example demonstrates a unit test that does this:

```csharp
[Fact]
[TestMethod]
public void CheckValidationFailsWhenOnlyForenameHasDataTest()
{
    var mockViewModel = new MockViewModel();
    mockViewModel.Forename.Value = "John";

    bool isValid = mockViewModel.Validate();

    Assert.False(isValid);
    Assert.NotNull(mockViewModel.Forename.Value);
    Assert.Null(mockViewModel.Surname.Value);
    Assert.True(mockViewModel.Forename.IsValid);
    Assert.False(mockViewModel.Surname.IsValid);
    Assert.Empty(mockViewModel.Forename.Errors);
    Assert.NotEmpty(mockViewModel.Surname.Errors);
    Assert.IsFalse(isValid);
    Assert.IsNotNull(mockViewModel.Forename.Value);
    Assert.IsNull(mockViewModel.Surname.Value);
    Assert.IsTrue(mockViewModel.Forename.IsValid);
    Assert.IsFalse(mockViewModel.Surname.IsValid);
    Assert.AreEqual(mockViewModel.Forename.Errors.Count(), 0);
Assert.AreNotEqual(mockViewModel.Surname.Errors.Count(), 0);
}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/azure/includes/dotnet-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
| Monitor Ingestion | NuGet [1.1.2](https://www.nuget.org/packages/Azure.Monitor.Ingestion/1.1.2) | [docs](/dotnet/api/overview/azure/Monitor.Ingestion-readme) | GitHub [1.1.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.Ingestion_1.1.2/sdk/monitor/Azure.Monitor.Ingestion/) |
| Monitor Query | NuGet [1.3.1](https://www.nuget.org/packages/Azure.Monitor.Query/1.3.1) | [docs](/dotnet/api/overview/azure/Monitor.Query-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.Query_1.3.1/sdk/monitor/Azure.Monitor.Query/) |
| OpenAI Assistants | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.AI.OpenAI.Assistants/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/AI.OpenAI.Assistants-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.OpenAI.Assistants_1.0.0-beta.4/sdk/openai/Azure.AI.OpenAI.Assistants/) |
| OpenAI Inference | NuGet [1.0.0-beta.17](https://www.nuget.org/packages/Azure.AI.OpenAI/1.0.0-beta.17) | [docs](/dotnet/api/overview/azure/AI.OpenAI-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.17](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.OpenAI_1.0.0-beta.17/sdk/openai/Azure.AI.OpenAI/) |
| OpenAI Inference | NuGet [2.0.0-beta.1](https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.1) | [docs](/dotnet/api/overview/azure/AI.OpenAI-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [2.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.OpenAI_2.0.0-beta.1/sdk/openai/Azure.AI.OpenAI/) |
| OpenTelemetry AspNetCore | NuGet [1.1.1](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.AspNetCore/1.1.1)<br>NuGet [1.2.0-beta.4](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.AspNetCore/1.2.0-beta.4) | [docs](/dotnet/api/overview/azure/Monitor.OpenTelemetry.AspNetCore-readme) | GitHub [1.1.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.OpenTelemetry.AspNetCore_1.1.1/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/)<br>GitHub [1.2.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.OpenTelemetry.AspNetCore_1.2.0-beta.4/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/) |
| OpenTelemetry Exporter | NuGet [1.2.0](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.Exporter/1.2.0)<br>NuGet [1.3.0-beta.2](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.Exporter/1.3.0-beta.2) | [docs](/dotnet/api/overview/azure/Monitor.OpenTelemetry.Exporter-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.OpenTelemetry.Exporter_1.2.0/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/)<br>GitHub [1.3.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Monitor.OpenTelemetry.Exporter_1.3.0-beta.2/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/) |
| Personalizer | NuGet [2.0.0-beta.2](https://www.nuget.org/packages/Azure.AI.Personalizer/2.0.0-beta.2) | [docs](/dotnet/api/overview/azure/AI.Personalizer-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [2.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.Personalizer_2.0.0-beta.2/sdk/personalizer/Azure.AI.Personalizer/) |
Expand Down Expand Up @@ -181,7 +181,7 @@
| Resource Management - Customer Insights | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.ResourceManager.CustomerInsights/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/ResourceManager.CustomerInsights-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CustomerInsights_1.0.0-beta.4/sdk/customer-insights/Azure.ResourceManager.CustomerInsights/) |
| Resource Management - Data Box | NuGet [1.0.3](https://www.nuget.org/packages/Azure.ResourceManager.DataBox/1.0.3) | [docs](/dotnet/api/overview/azure/ResourceManager.DataBox-readme) | GitHub [1.0.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataBox_1.0.3/sdk/databox/Azure.ResourceManager.DataBox/) |
| Resource Management - Data Box Edge | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.DataBoxEdge/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.DataBoxEdge-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataBoxEdge_1.1.0/sdk/databoxedge/Azure.ResourceManager.DataBoxEdge/) |
| Resource Management - Data Factory | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.DataFactory/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.DataFactory-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataFactory_1.0.0/sdk/datafactory/Azure.ResourceManager.DataFactory/) |
| Resource Management - Data Factory | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.DataFactory/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.DataFactory-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataFactory_1.1.0/sdk/datafactory/Azure.ResourceManager.DataFactory/) |
| Resource Management - Data Lake Analytics | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.DataLakeAnalytics/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.DataLakeAnalytics-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataLakeAnalytics_1.1.0/sdk/datalake-analytics/Azure.ResourceManager.DataLakeAnalytics/) |
| Resource Management - Data Lake Store | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.DataLakeStore/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.DataLakeStore-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataLakeStore_1.1.0/sdk/datalake-store/Azure.ResourceManager.DataLakeStore/) |
| Resource Management - Data Migration | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.ResourceManager.DataMigration/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/ResourceManager.DataMigration-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.DataMigration_1.0.0-beta.4/sdk/datamigration/Azure.ResourceManager.DataMigration/) |
Expand Down Expand Up @@ -219,7 +219,7 @@
| Resource Management - HDInsight Containers | NuGet [1.0.0-beta.3](https://www.nuget.org/packages/Azure.ResourceManager.HDInsight.Containers/1.0.0-beta.3) | [docs](/dotnet/api/overview/azure/ResourceManager.HDInsight.Containers-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HDInsight.Containers_1.0.0-beta.3/sdk/hdinsight/Azure.ResourceManager.HDInsight.Containers/) |
| Resource Management - Health Bot | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.HealthBot/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.HealthBot-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HealthBot_1.1.0/sdk/healthbot/Azure.ResourceManager.HealthBot/) |
| Resource Management - Healthcare APIs | NuGet [1.3.0](https://www.nuget.org/packages/Azure.ResourceManager.HealthcareApis/1.3.0) | [docs](/dotnet/api/overview/azure/ResourceManager.HealthcareApis-readme) | GitHub [1.3.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HealthcareApis_1.3.0/sdk/healthcareapis/Azure.ResourceManager.HealthcareApis/) |
| Resource Management - Hybrid Compute | NuGet [1.0.0-beta.8](https://www.nuget.org/packages/Azure.ResourceManager.HybridCompute/1.0.0-beta.8) | [docs](/dotnet/api/overview/azure/ResourceManager.HybridCompute-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.8](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HybridCompute_1.0.0-beta.8/sdk/hybridcompute/Azure.ResourceManager.HybridCompute/) |
| Resource Management - Hybrid Compute | NuGet [1.0.0-beta.9](https://www.nuget.org/packages/Azure.ResourceManager.HybridCompute/1.0.0-beta.9) | [docs](/dotnet/api/overview/azure/ResourceManager.HybridCompute-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.9](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HybridCompute_1.0.0-beta.9/sdk/hybridcompute/Azure.ResourceManager.HybridCompute/) |
| Resource Management - Hybrid Connectivity | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.ResourceManager.HybridConnectivity/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/ResourceManager.HybridConnectivity-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HybridConnectivity_1.0.0-beta.4/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/) |
| Resource Management - Hybrid Container Service | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.HybridContainerService/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.HybridContainerService-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.HybridContainerService_1.0.0/sdk/hybridaks/Azure.ResourceManager.HybridContainerService/) |
| Resource Management - Hybrid Kubernetes | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.ResourceManager.Kubernetes/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/ResourceManager.Kubernetes-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Kubernetes_1.0.0-beta.4/sdk/hybridkubernetes/Azure.ResourceManager.Kubernetes/) |
Expand Down
Loading

0 comments on commit b17760b

Please sign in to comment.