├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── ci-cd.yml ├── .gitignore ├── LICENSE ├── README.RUS.md ├── README.md ├── code ├── Directory.Build.props ├── MvvmNavigation.sln ├── MvvmNavigation.sln.DotSettings ├── src │ ├── Directory.Build.props │ ├── Directory.Build.targets │ ├── MvvmNavigation.Abstractions │ │ ├── IAsyncNavigatedToAware.cs │ │ ├── IAsyncNavigatingFromAware.cs │ │ ├── INavigatedToAware.cs │ │ ├── INavigatingFromAware.cs │ │ ├── INavigationManager.cs │ │ ├── MvvmNavigation.Abstractions.csproj │ │ ├── NavigationData.cs │ │ ├── NavigationEventArgs.cs │ │ └── NavigationManagerExtensions.cs │ ├── MvvmNavigation.Avalonia │ │ ├── MvvmNavigation.Avalonia.csproj │ │ ├── NavigationManager.cs │ │ └── ViewInteractionStrategy.cs │ ├── MvvmNavigation.Core │ │ ├── IDataStorage.cs │ │ ├── IViewInteractionStrategy.cs │ │ ├── Internal │ │ │ ├── DataStorage.cs │ │ │ ├── ExceptionMessages.cs │ │ │ └── Navigator.cs │ │ ├── MvvmNavigation.Core.csproj │ │ ├── NavigationManagerBase.cs │ │ ├── NavigationManagerBaseExtensions.cs │ │ └── RegistrationData.cs │ ├── MvvmNavigation.Internal │ │ ├── FrameControlTypeAttribute.cs │ │ ├── FrameControlTypeProvider.cs │ │ ├── IFrameControlTypeProvider.cs │ │ ├── INavigationManagerTypeProvider.cs │ │ ├── MvvmNavigation.Internal.csproj │ │ └── NavigationManagerTypeProvider.cs │ ├── MvvmNavigation.Unity │ │ ├── Internal │ │ │ ├── ExceptionMessages.cs │ │ │ └── NavigationManagerCtorInfo.cs │ │ ├── MvvmNavigation.Unity.csproj │ │ ├── UnityContainerExtensions.cs │ │ └── UnityDataStorage.cs │ ├── MvvmNavigation.Wpf │ │ ├── Internal │ │ │ └── ExceptionMessages.cs │ │ ├── MvvmNavigation.Wpf.csproj │ │ ├── NavigationManager.cs │ │ └── ViewInteractionStrategy.cs │ └── System.Runtime.CompilerServices │ │ ├── CompilerFeatureRequiredAttribute.cs │ │ ├── IsExternalInit.cs │ │ ├── Readme.md │ │ ├── RequiredMemberAttribute.cs │ │ └── SetsRequiredMembersAttribute.cs └── test │ ├── Directory.Build.props │ ├── MvvmNavigation.Abstractions.ContractTests │ ├── MvvmNavigation.Abstractions.ContractTests.csproj │ └── NavigationManagerContractTests.cs │ ├── MvvmNavigation.Abstractions.UnitTests │ ├── MvvmNavigation.Abstractions.UnitTests.csproj │ └── NavigationManagerExtensionsTests.cs │ ├── MvvmNavigation.Avalonia.UnitTests │ ├── MvvmNavigation.Avalonia.UnitTests.csproj │ ├── NavigationManagerTests.cs │ ├── NavigationManagerTypeProviderTests.cs │ └── ViewInteractionStrategyTests.cs │ ├── MvvmNavigation.Avalonia.Unity.IntegrationTests │ ├── Internal │ │ ├── ThrowsException.cs │ │ └── Types │ │ │ ├── View.cs │ │ │ └── ViewModel.cs │ ├── MvvmNavigation.Avalonia.Unity.IntegrationTests.csproj │ └── ScenarioTests.cs │ ├── MvvmNavigation.Core.ContractTests │ ├── Internal │ │ ├── ArgumentNames.cs │ │ └── ThrowsException.cs │ ├── InternalTests │ │ └── DataStorageTestsBase.cs │ ├── MvvmNavigation.Core.ContractTests.csproj │ ├── NavigationManagerBaseContractTests.cs │ └── ViewInteractionStrategyContractTests.cs │ ├── MvvmNavigation.Core.UnitTests │ ├── InternalTests │ │ ├── DataStorageTests.cs │ │ └── RegistrationDataTests.cs │ ├── MvvmNavigation.Core.UnitTests.csproj │ └── NavigationManagerBaseTests.cs │ ├── MvvmNavigation.Internal.ContractTests │ ├── MvvmNavigation.Internal.ContractTests.csproj │ └── NavigationManagerTypeProviderContractTests.cs │ ├── MvvmNavigation.Internal.UnitTests │ ├── FrameControlTypeProviderTests.cs │ ├── Internal │ │ ├── ArgumentNames.cs │ │ └── ClassBuilder.cs │ └── MvvmNavigation.Internal.UnitTests.csproj │ ├── MvvmNavigation.Tests.Common.Unity │ ├── MvvmNavigation.Tests.Common.Unity.csproj │ └── UnityAssert.cs │ ├── MvvmNavigation.Tests.Common │ ├── MvvmNavigation.Tests.Common.csproj │ ├── TaskHelper.cs │ ├── TestCaseDataBuilder.cs │ └── ThrowsException.cs │ ├── MvvmNavigation.Unity.UnitTests │ ├── Internal │ │ ├── ArgumentNames.cs │ │ ├── ThrowsException.cs │ │ └── Types │ │ │ ├── AbstractClass.cs │ │ │ ├── ContentControl.cs │ │ │ ├── ISomeInterface.cs │ │ │ ├── InstanceClass.cs │ │ │ └── NavigationManager.cs │ ├── MvvmNavigation.Unity.UnitTests.csproj │ ├── UnityContainerExtensionsTests.cs │ └── UnityDataStorageTests.cs │ ├── MvvmNavigation.Wpf.UnitTests │ ├── MvvmNavigation.Wpf.UnitTests.csproj │ ├── NavigationManagerTests.cs │ ├── NavigationManagerTypeProviderTests.cs │ └── ViewInteractionStrategyTests.cs │ └── MvvmNavigation.Wpf.Unity.IntegrationTests │ ├── Internal │ ├── ThrowsException.cs │ └── Types │ │ ├── View.cs │ │ └── ViewModel.cs │ ├── MvvmNavigation.Wpf.Unity.IntegrationTests.csproj │ └── ScenarioTests.cs ├── samples ├── Directory.Build.props ├── MvvmNavigation.Samples.Dev.sln ├── MvvmNavigation.Samples.sln ├── RestaurantApp │ ├── App.xaml │ ├── App.xaml.cs │ ├── Constants │ │ └── NavigationKeys.cs │ ├── FodyWeavers.xml │ ├── FodyWeavers.xsd │ ├── Infrastructure │ │ ├── Abstractions │ │ │ └── IDialogManager.cs │ │ └── Implementations │ │ │ └── DialogManager.cs │ ├── Models │ │ └── Food.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── RestaurantApp.csproj │ ├── ViewModels │ │ ├── FoodCookingViewModel.cs │ │ ├── FoodSelectionViewModel.cs │ │ └── MainWindowViewModel.cs │ ├── Views │ │ ├── FoodCookingView.xaml │ │ ├── FoodCookingView.xaml.cs │ │ ├── FoodSelectionView.xaml │ │ ├── FoodSelectionView.xaml.cs │ │ ├── MainWindow.xaml │ │ └── MainWindow.xaml.cs │ └── app.config ├── SampleWithUnity │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Converters │ │ └── StringToBrushConverter.cs │ ├── FodyWeavers.xml │ ├── FodyWeavers.xsd │ ├── NavigationKeys.cs │ ├── RandomViewSelector.cs │ ├── SampleWithUnity.csproj │ ├── ViewModels │ │ ├── DonatelloViewModel.cs │ │ ├── LeonardoViewModel.cs │ │ ├── MichelangeloViewModel.cs │ │ ├── RaphaelViewModel.cs │ │ └── TurtleViewModel.cs │ └── Views │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── TurtleView.xaml │ │ └── TurtleView.xaml.cs └── SinglePageApp │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Constants │ └── NavigationKeys.cs │ ├── FodyWeavers.xml │ ├── FodyWeavers.xsd │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ ├── SinglePageApp.csproj │ ├── ViewModels │ ├── ParameterDisplayViewModel.cs │ ├── ParameterSelectionViewModel.cs │ └── WelcomeViewModel.cs │ └── Views │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── ParameterDisplayView.xaml │ ├── ParameterDisplayView.xaml.cs │ ├── ParameterSelectionView.xaml │ ├── ParameterSelectionView.xaml.cs │ ├── WelcomeView.xaml │ └── WelcomeView.xaml.cs └── version.txt /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at novikov.ea@mail.ru. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 17 | do not have permission to do that, you may request the second reviewer to merge it for you. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: Egor92 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Version of library** 14 | Version of NuGet package that a bug is detected in 15 | 16 | **To Reproduce** 17 | Steps to reproduce the behavior: 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci-cd.yml: -------------------------------------------------------------------------------- 1 | name: CI/CD Pipeline 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' # Запускаем для всех веток 7 | pull_request: 8 | branches: 9 | - '**' # Запускаем для pull request'ов в любую ветку 10 | 11 | jobs: 12 | build: 13 | runs-on: windows-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v3 18 | with: 19 | fetch-depth: 0 # Получаем всю историю коммитов для создания тега 20 | 21 | - name: Setup .NET 22 | uses: actions/setup-dotnet@v3 23 | with: 24 | dotnet-version: '3.1.x' # Укажите нужную версию .NET SDK 25 | 26 | - name: Restore dependencies 27 | working-directory: ./code # Указываем папку с решением 28 | run: dotnet restore 29 | 30 | - name: Calculate versions 31 | id: calculate_versions 32 | shell: bash 33 | run: | 34 | # Читаем версию из файла version.txt 35 | ASSEMBLY_VERSION=$(cat version.txt | tr -d '\n' | tr -d '\r') 36 | echo "Assembly Version: $ASSEMBLY_VERSION" 37 | 38 | # Вычисляем AssemblyFileVersion и AssemblyInformationalVersion 39 | BUILD_NUMBER=${{ github.run_number }} 40 | ASSEMBLY_FILE_VERSION="$ASSEMBLY_VERSION.$BUILD_NUMBER" 41 | ASSEMBLY_INFORMATIONAL_VERSION="$ASSEMBLY_VERSION.$BUILD_NUMBER" 42 | 43 | # Сохраняем значения в выходные переменные 44 | echo "::set-output name=assembly_version::$ASSEMBLY_VERSION" 45 | echo "::set-output name=assembly_file_version::$ASSEMBLY_FILE_VERSION" 46 | echo "::set-output name=assembly_informational_version::$ASSEMBLY_INFORMATIONAL_VERSION" 47 | 48 | - name: Build project 49 | working-directory: ./code # Указываем папку с решением 50 | shell: bash 51 | run: | 52 | ASSEMBLY_VERSION=${{ steps.calculate_versions.outputs.assembly_version }} 53 | ASSEMBLY_FILE_VERSION=${{ steps.calculate_versions.outputs.assembly_file_version }} 54 | ASSEMBLY_INFORMATIONAL_VERSION=${{ steps.calculate_versions.outputs.assembly_informational_version }} 55 | 56 | echo "Building with AssemblyVersion=$ASSEMBLY_VERSION" 57 | echo "Building with AssemblyFileVersion=$ASSEMBLY_FILE_VERSION" 58 | echo "Building with AssemblyInformationalVersion=$ASSEMBLY_INFORMATIONAL_VERSION" 59 | 60 | dotnet build --configuration Release --no-restore //p:AssemblyVersion=$ASSEMBLY_VERSION //p:AssemblyFileVersion=$ASSEMBLY_FILE_VERSION //p:AssemblyInformationalVersion=$ASSEMBLY_INFORMATIONAL_VERSION 61 | 62 | #- name: Run tests 63 | # working-directory: ./code # Указываем папку с решением 64 | # run: dotnet test --no-restore --verbosity normal 65 | 66 | - name: Pack NuGet package 67 | working-directory: ./code # Указываем папку с решением 68 | shell: bash 69 | run: | 70 | ASSEMBLY_VERSION=${{ steps.calculate_versions.outputs.assembly_version }} 71 | ASSEMBLY_FILE_VERSION=${{ steps.calculate_versions.outputs.assembly_file_version }} 72 | ASSEMBLY_INFORMATIONAL_VERSION=${{ steps.calculate_versions.outputs.assembly_informational_version }} 73 | 74 | echo "Packing with AssemblyVersion=$ASSEMBLY_VERSION" 75 | echo "Packing with AssemblyFileVersion=$ASSEMBLY_FILE_VERSION" 76 | echo "Packing with AssemblyInformationalVersion=$ASSEMBLY_INFORMATIONAL_VERSION" 77 | 78 | dotnet pack --configuration Release --output ./artifacts //p:AssemblyVersion=$ASSEMBLY_VERSION //p:AssemblyFileVersion=$ASSEMBLY_FILE_VERSION //p:AssemblyInformationalVersion=$ASSEMBLY_INFORMATIONAL_VERSION //p:PackageVersion=$ASSEMBLY_VERSION 79 | 80 | - name: Upload NuGet packages as artifacts 81 | uses: actions/upload-artifact@v4 82 | with: 83 | name: nuget-packages 84 | path: ./code/artifacts/*.nupkg 85 | 86 | - name: Publish NuGet package 87 | if: github.ref == 'refs/heads/master' # Публикуем только для ветки master 88 | working-directory: ./code # Указываем папку с решением 89 | shell: bash 90 | run: | 91 | dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json 92 | 93 | - name: Create Git Tag 94 | if: github.ref == 'refs/heads/master' # Создаём тег только для ветки master 95 | shell: bash 96 | run: | 97 | # Получаем ASSEMBLY_VERSION из шага calculate_versions 98 | ASSEMBLY_VERSION=${{ steps.calculate_versions.outputs.assembly_version }} 99 | echo "Assembly Version: $ASSEMBLY_VERSION" 100 | 101 | git config --global user.email "actions@github.com" 102 | git config --global user.name "Github Actions" 103 | 104 | # Формируем имя тега 105 | TAG_NAME="release-$ASSEMBLY_VERSION" 106 | echo "Creating tag: $TAG_NAME" 107 | 108 | # Создаём тег 109 | git tag -a $TAG_NAME -m "Release $TAG_NAME" 110 | 111 | # Отправляем тег в репозиторий 112 | git push origin $TAG_NAME 113 | env: 114 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Используем встроенный токен для отправки тега -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Novikov Egor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.RUS.md: -------------------------------------------------------------------------------- 1 | # MvvmNavigation 2 | 3 | [![Build status](https://img.shields.io/appveyor/ci/Egor92/MvvmNavigation/master)](https://ci.appveyor.com/project/Egor92/MvvmNavigation/branch/master) 4 | [![Version](https://img.shields.io/nuget/vpre/MvvmNavigation.Wpf.svg)](https://www.nuget.org/packages/MvvmNavigation.Wpf) 5 | [![Downloads](https://img.shields.io/nuget/dt/MvvmNavigation.Wpf.svg)](https://www.nuget.org/packages/MvvmNavigation.Wpf) 6 | [![CodeFactor](https://www.codefactor.io/repository/github/egor92/MvvmNavigation/badge/master)](https://www.codefactor.io/repository/github/egor92/MvvmNavigation/overview/master) 7 | [![GitHub contributors](https://img.shields.io/github/contributors/Egor92/MvvmNavigation.svg)](https://github.com/Egor92/MvvmNavigation/graphs/contributors) 8 | [![License](https://img.shields.io/github/license/Egor92/MvvmNavigation.svg)](https://github.com/Egor92/MvvmNavigation/blob/master/LICENSE) 9 | [![Join the Gitter chat!](https://badges.gitter.im/Egor92/MvvmNavigation.svg)](https://gitter.im/MvvmNavigation/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 10 | 11 | Go to [english page](https://github.com/Egor92/MvvmNavigation/blob/master/README.md) 12 | 13 | Данная библиотека позволяет настраивать навигацию для ваших приложений WPF и Avalinia и реализовывать навигацию на уровне слоя ViewModel. Библиотека полностью придерживается паттерна MVVM. 14 | 15 | ## Содерание 16 | 17 | - [Как использовать](#Как-использовать) 18 | 19 | - [Как использовать с Unity](#Как-использовать-с-Unity) 20 | 21 | - [Nuget пакет для проекта слоя ViewModel](#Nuget-пакет-для-проекта-слоя-ViewModel) 22 | 23 | - [Примеры](#Примеры) 24 | 25 | ## Как использовать 26 | 27 | 1. Установите один из этих NuGet пакетов 28 | - [MvvmNavigation.Wpf](https://www.nuget.org/packages/MvvmNavigation.Wpf/) для приложения WPF 29 | - [MvvmNavigation.Avalonia](https://www.nuget.org/packages/MvvmNavigation.Avalonia/) для приложения Avalonia 30 | 31 | 1. Определите привала навигации: 32 | ```csharp 33 | public partial class App : Application 34 | { 35 | protected override void OnStartup(StartupEventArgs e) 36 | { 37 | var window = new MainWindow(); 38 | 39 | //1. Создайте менеджер навигации 40 | var navigationManager = new NavigationManager(window); 41 | 42 | //2. Определите правила навигации: зарегистрируйте ключ (строку) с соответствующими View и ViewModel для него 43 | navigationManager.Register("FirstKey", () => new FirstViewModel(navigationManager)); 44 | navigationManager.Register("SecondKey", () => new SecondViewModel(navigationManager)); 45 | 46 | //3. Отобразите стартовый UI 47 | navigationManager.Navigate("FirstKey"); 48 | 49 | window.Show(); 50 | } 51 | } 52 | ``` 53 | 54 | 1. Вызовите метод *Navigate* в вашей ViewModel, чтобы сменить UI 55 | ```csharp 56 | public class FirstViewModel : ViewModelBase 57 | { 58 | private readonly INavigationManager _navigationManager; 59 | 60 | public FirstViewModel(INavigationManager navigationManager) 61 | { 62 | _navigationManager = navigationManager; 63 | } 64 | 65 | private void GoToSecondPage() 66 | { 67 | // Сменить интерфейс 68 | _navigationManager.Navigate("SecondKey"); 69 | } 70 | } 71 | ``` 72 | 73 | Пример доступен [здесь](https://github.com/Egor92/MvvmNavigation/blob/master/samples/RestaurantApp/App.xaml.cs) 74 | 75 | ## Как использовать с Unity 76 | 77 | MvvmNavigation поддерживает Unity из коробки. 78 | 79 | 1. Установите 2 NuGet пакета: 80 | - [MvvmNavigation.Wpf](https://www.nuget.org/packages/MvvmNavigation.Wpf/) или [MvvmNavigation.Avalonia](https://www.nuget.org/packages/MvvmNavigation.Avalonia/) 81 | - [MvvmNavigation.Unity](https://www.nuget.org/packages/MvvmNavigation.Unity/) 82 | 83 | 2. Определите привала навигации через UnityContainer: 84 | 85 | ```csharp 86 | public partial class App : Application 87 | { 88 | protected override void OnStartup(StartupEventArgs e) 89 | { 90 | //1. Создайте Window и UnityContainer 91 | var mainWindow = new MainWindow(); 92 | var unityContainer = new UnityContainer(); 93 | 94 | //2. Зарегистрируйте менеджер навигации 95 | unityContainer.RegisterNavigationManager(mainWindow); 96 | 97 | //3. Определите правила навигации 98 | unityContainer.RegisterNavigationRule("FirstKey"); 99 | unityContainer.RegisterNavigationRule("SecondKey"); 100 | 101 | //4. Отобразите стартовый UI 102 | var navigationManager = unityContainer.Resolve(); 103 | navigationManager.Navigate("FirstKey"); 104 | 105 | window.Show(); 106 | } 107 | } 108 | ``` 109 | 110 | 3. Вызовите метод *Navigate* в вашей ViewModel, чтобы сменить UI 111 | ```csharp 112 | public class FirstViewModel : ViewModelBase 113 | { 114 | private readonly INavigationManager _navigationManager; 115 | 116 | public FirstViewModel(INavigationManager navigationManager) 117 | { 118 | _navigationManager = navigationManager; 119 | } 120 | 121 | private void GoToSecondPage() 122 | { 123 | // Сменить интерфейс 124 | _navigationManager.Navigate("SecondKey"); 125 | } 126 | } 127 | ``` 128 | 129 | ## Nuget пакет для проекта слоя ViewModel 130 | 131 | Если у вас есть отдельный проект для слоя ViewModel, используйте для него [MvvmNavigation.Abstractions](https://www.nuget.org/packages/MvvmNavigation.Abstractions/). Он содержит необходимые интерфейсы для управления навигацией, такие как INavigationManager. 132 | 133 | ## Примеры 134 | 135 | Все примеры доступны [здесь](https://github.com/Egor92/MvvmNavigation/tree/master/samples). 136 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MvvmNavigation 2 | 3 | [![Build status](https://img.shields.io/appveyor/ci/Egor92/MvvmNavigation/master)](https://ci.appveyor.com/project/Egor92/MvvmNavigation/branch/master) 4 | [![Version](https://img.shields.io/nuget/vpre/MvvmNavigation.Wpf.svg)](https://www.nuget.org/packages/MvvmNavigation.Wpf) 5 | [![Downloads](https://img.shields.io/nuget/dt/MvvmNavigation.Wpf.svg)](https://www.nuget.org/packages/MvvmNavigation.Wpf) 6 | [![CodeFactor](https://www.codefactor.io/repository/github/egor92/MvvmNavigation/badge/master)](https://www.codefactor.io/repository/github/egor92/MvvmNavigation/overview/master) 7 | [![GitHub contributors](https://img.shields.io/github/contributors/Egor92/MvvmNavigation.svg)](https://github.com/Egor92/MvvmNavigation/graphs/contributors) 8 | [![License](https://img.shields.io/github/license/Egor92/MvvmNavigation.svg)](https://github.com/Egor92/MvvmNavigation/blob/master/LICENSE) 9 | [![Join the Gitter chat!](https://badges.gitter.im/Egor92/MvvmNavigation.svg)](https://gitter.im/MvvmNavigation/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 10 | 11 | Перейти на [русскую страницу](https://github.com/Egor92/MvvmNavigation/blob/master/README.RUS.md) 12 | 13 | This library allows you to adjust navigation behavior in your WPF and Avalonia applications and implement ViewModel-based navigation. This library completely adhere to MVVM pattern. 14 | 15 | ## Contents 16 | 17 | - [Usage](#Usage) 18 | 19 | - [Usage with Unity](#Usage-with-Unity) 20 | 21 | - [Nuget package for ViewModel layer project](#Nuget-package-for-ViewModel-layer-project) 22 | 23 | - [Samples](#Samples) 24 | 25 | ## Usage 26 | 27 | 1. Install one of these NuGet packages: 28 | - [MvvmNavigation.Wpf](https://www.nuget.org/packages/MvvmNavigation.Wpf/) for WPF application 29 | - [MvvmNavigation.Avalonia](https://www.nuget.org/packages/MvvmNavigation.Avalonia/) for Avalonia application 30 | 31 | 1. Define navigation rules: 32 | ```csharp 33 | public partial class App : Application 34 | { 35 | protected override void OnStartup(StartupEventArgs e) 36 | { 37 | var window = new MainWindow(); 38 | 39 | //1. Create navigation manager 40 | var navigationManager = new NavigationManager(window); 41 | 42 | //2. Define navigation rules: register key and corresponding view and viewmodel for it 43 | navigationManager.Register("FirstKey", () => new FirstViewModel(navigationManager)); 44 | navigationManager.Register("SecondKey", () => new SecondViewModel(navigationManager)); 45 | 46 | //3. Display start UI 47 | navigationManager.Navigate("FirstKey"); 48 | 49 | window.Show(); 50 | } 51 | } 52 | ``` 53 | 54 | 1. Сall *Navigate* method in your ViewModel in order to switch UI 55 | ```csharp 56 | public class FirstViewModel : ViewModelBase 57 | { 58 | private readonly INavigationManager _navigationManager; 59 | 60 | public FirstViewModel(INavigationManager navigationManager) 61 | { 62 | _navigationManager = navigationManager; 63 | } 64 | 65 | private void GoToSecondPage() 66 | { 67 | // Switch UI 68 | _navigationManager.Navigate("SecondKey"); 69 | } 70 | } 71 | ``` 72 | 73 | Look it in [a sample](https://github.com/Egor92/MvvmNavigation/blob/master/samples/RestaurantApp/App.xaml.cs) 74 | 75 | ## Usage with Unity 76 | 77 | MvvmNavigation supports Unity out of the box. 78 | 79 | 1. Install two NuGet packages 80 | - [MvvmNavigation.Wpf](https://www.nuget.org/packages/MvvmNavigation.Wpf/) or [MvvmNavigation.Avalonia](https://www.nuget.org/packages/MvvmNavigation.Avalonia/) 81 | - [MvvmNavigation.Unity](https://www.nuget.org/packages/MvvmNavigation.Unity/) 82 | 83 | 1. Define navigation rules via UnityContainer: 84 | 85 | ```csharp 86 | public partial class App : Application 87 | { 88 | protected override void OnStartup(StartupEventArgs e) 89 | { 90 | //1. Create Window and UnityContainer 91 | var mainWindow = new MainWindow(); 92 | var unityContainer = new UnityContainer(); 93 | 94 | //2. Register navigation manager 95 | unityContainer.RegisterNavigationManager(mainWindow); 96 | 97 | //3. Register navigation rules 98 | unityContainer.RegisterNavigationRule("FirstKey"); 99 | unityContainer.RegisterNavigationRule("SecondKey"); 100 | 101 | //4. Display start UI 102 | var navigationManager = unityContainer.Resolve(); 103 | navigationManager.Navigate("FirstKey"); 104 | 105 | window.Show(); 106 | } 107 | } 108 | ``` 109 | 110 | 1. Сall *Navigate* method in your ViewModel in order to switch UI 111 | ```csharp 112 | public class FirstViewModel : ViewModelBase 113 | { 114 | private readonly INavigationManager _navigationManager; 115 | 116 | public FirstViewModel(INavigationManager navigationManager) 117 | { 118 | _navigationManager = navigationManager; 119 | } 120 | 121 | private void GoToSecondPage() 122 | { 123 | // Switch UI 124 | _navigationManager.Navigate("SecondKey"); 125 | } 126 | } 127 | ``` 128 | 129 | ## Nuget package for ViewModel layer project 130 | 131 | If you have separated project for ViewModel layer, use [MvvmNavigation.Abstractions](https://www.nuget.org/packages/MvvmNavigation.Abstractions/) for it. It contains nessasary interfaces for navigation management such as INavigationManager. 132 | 133 | ## Samples 134 | 135 | See all samples [here](https://github.com/Egor92/MvvmNavigation/tree/master/samples). 136 | -------------------------------------------------------------------------------- /code/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Egor92 4 | Egor92 5 | MVVM friendly library for easy navigation management in WPF and Avalonia applications 6 | $(Company)™ 7 | Copyright © $(Company) $([System.DateTime]::Now.Year) 8 | https://github.com/Egor92/MvvmNavigation 9 | https://github.com/Egor92/MvvmNavigation/blob/master/LICENSE 10 | https://github.com/Egor92/MvvmNavigation 11 | mvvm;navigation;page;wpf;avalonia;avalonia-ui;unity 12 | 13 | 14 | 15 | $(Company).$(MSBuildProjectName) 16 | disable 17 | 13 18 | 19 | 20 | 21 | false 22 | none 23 | true 24 | 25 | 26 | 27 | true 28 | full 29 | false 30 | DEBUG;TRACE 31 | 32 | -------------------------------------------------------------------------------- /code/MvvmNavigation.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | 140 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | -------------------------------------------------------------------------------- /code/src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <_Parameter1>$(MSBuildProjectName).UnitTests 7 | 8 | 9 | <_Parameter1>$(MSBuildProjectName).ContractTests 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /code/src/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/IAsyncNavigatedToAware.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace Egor92.MvvmNavigation.Abstractions 5 | { 6 | public interface IAsyncNavigatedToAware 7 | { 8 | Task OnNavigatedToAsync(object arg, CancellationToken token = default); 9 | } 10 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/IAsyncNavigatingFromAware.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace Egor92.MvvmNavigation.Abstractions 5 | { 6 | public interface IAsyncNavigatingFromAware 7 | { 8 | Task OnNavigatingFromAsync(object arg, CancellationToken token = default); 9 | } 10 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/INavigatedToAware.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Abstractions 2 | { 3 | public interface INavigatedToAware 4 | { 5 | void OnNavigatedTo(object arg); 6 | } 7 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/INavigatingFromAware.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Abstractions 2 | { 3 | public interface INavigatingFromAware 4 | { 5 | void OnNavigatingFrom(object arg); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/INavigationManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using JetBrains.Annotations; 5 | 6 | namespace Egor92.MvvmNavigation.Abstractions 7 | { 8 | public interface INavigationManager 9 | { 10 | bool CanNavigate(string navigationKey); 11 | 12 | NavigationData Navigate([NotNull] string navigationKey, object arg); 13 | 14 | Task NavigateAsync([NotNull] string navigationKey, object arg, CancellationToken token = default); 15 | 16 | NavigationData NavigateBack(); 17 | 18 | Task NavigateBackAsync(CancellationToken token = default); 19 | 20 | event EventHandler Navigated; 21 | } 22 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/MvvmNavigation.Abstractions.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/NavigationData.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Abstractions 2 | { 3 | public record NavigationData 4 | { 5 | public void Deconstruct(out object view, out object viewModel) 6 | { 7 | view = View; 8 | viewModel = ViewModel; 9 | } 10 | 11 | public required object View { get; init; } 12 | 13 | public required object ViewModel { get; init; } 14 | } 15 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/NavigationEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Egor92.MvvmNavigation.Abstractions 4 | { 5 | public class NavigationEventArgs : EventArgs 6 | { 7 | public NavigationEventArgs(object view, object viewModel, string navigationKey, object navigationArg) 8 | { 9 | View = view; 10 | ViewModel = viewModel; 11 | NavigationKey = navigationKey; 12 | NavigationArg = navigationArg; 13 | } 14 | 15 | public object View { get; } 16 | 17 | public object ViewModel { get; } 18 | 19 | public string NavigationKey { get; } 20 | 21 | public object NavigationArg { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Abstractions/NavigationManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using JetBrains.Annotations; 4 | 5 | namespace Egor92.MvvmNavigation.Abstractions 6 | { 7 | public static class NavigationManagerExtensions 8 | { 9 | public static NavigationData Navigate(this INavigationManager navigationManager, [NotNull] string navigationKey) 10 | { 11 | return navigationManager.Navigate(navigationKey, null); 12 | } 13 | 14 | public static Task NavigateAsync( 15 | this INavigationManager navigationManager, 16 | [NotNull] string navigationKey, 17 | CancellationToken token = default) 18 | { 19 | return navigationManager.NavigateAsync(navigationKey, null, token); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Avalonia/MvvmNavigation.Avalonia.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | true 6 | $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage 7 | Egor92.MvvmNavigation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Avalonia/NavigationManager.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | using Egor92.MvvmNavigation.Internal; 3 | using JetBrains.Annotations; 4 | 5 | namespace Egor92.MvvmNavigation 6 | { 7 | [FrameControlType(typeof(ContentControl))] 8 | public class NavigationManager : NavigationManagerBase 9 | { 10 | public NavigationManager([NotNull] ContentControl frameControl) 11 | : base(frameControl, new ViewInteractionStrategy()) 12 | { 13 | } 14 | 15 | public NavigationManager([NotNull] ContentControl frameControl, [NotNull] IDataStorage dataStorage) 16 | : base(frameControl, new ViewInteractionStrategy(), dataStorage) 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Avalonia/ViewInteractionStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Avalonia; 5 | using Avalonia.Controls; 6 | using Avalonia.Threading; 7 | using JetBrains.Annotations; 8 | 9 | namespace Egor92.MvvmNavigation 10 | { 11 | public class ViewInteractionStrategy : IViewInteractionStrategy 12 | { 13 | public object GetContent(object control) 14 | { 15 | if (control == null) 16 | { 17 | throw new ArgumentNullException(nameof(control)); 18 | } 19 | 20 | if (!(control is IContentControl contentControl)) 21 | { 22 | return null; 23 | } 24 | 25 | return contentControl.Content; 26 | } 27 | 28 | public void SetContent(object control, [NotNull] object content) 29 | { 30 | if (control == null) 31 | { 32 | throw new ArgumentNullException(nameof(control)); 33 | } 34 | 35 | if (control is IContentControl contentControl) 36 | { 37 | contentControl.Content = content; 38 | } 39 | } 40 | 41 | public object GetDataContext(object control) 42 | { 43 | if (control == null) 44 | { 45 | throw new ArgumentNullException(nameof(control)); 46 | } 47 | 48 | if (control is IDataContextProvider dataContextProvider) 49 | { 50 | return dataContextProvider.DataContext; 51 | } 52 | 53 | return null; 54 | } 55 | 56 | public void SetDataContext(object control, object dataContext) 57 | { 58 | if (control == null) 59 | { 60 | throw new ArgumentNullException(nameof(control)); 61 | } 62 | 63 | if (control is IDataContextProvider dataContextProvider) 64 | { 65 | dataContextProvider.DataContext = dataContext; 66 | } 67 | } 68 | 69 | public void InvokeInUIThread(object control, Action action) 70 | { 71 | if (control == null) 72 | { 73 | throw new ArgumentNullException(nameof(control)); 74 | } 75 | 76 | if (action == null) 77 | { 78 | throw new ArgumentNullException(nameof(action)); 79 | } 80 | 81 | var dispatcher = Dispatcher.UIThread; 82 | if (dispatcher == null || dispatcher.CheckAccess()) 83 | { 84 | action(); 85 | } 86 | else 87 | { 88 | dispatcher.InvokeAsync(action).GetAwaiter().GetResult(); 89 | } 90 | } 91 | 92 | public T InvokeInUiThread(object control, Func action) 93 | { 94 | var task = InvokeInUiThreadAsync(control, async () => action(), default); 95 | return task.GetAwaiter().GetResult(); 96 | } 97 | 98 | public async Task InvokeInUiThreadAsync(object control, Func> action, CancellationToken token) 99 | { 100 | if (control == null) 101 | { 102 | throw new ArgumentNullException(nameof(control)); 103 | } 104 | 105 | if (action == null) 106 | { 107 | throw new ArgumentNullException(nameof(action)); 108 | } 109 | 110 | var dispatcher = Dispatcher.UIThread; 111 | if (dispatcher == null || dispatcher.CheckAccess()) 112 | { 113 | return await action().ConfigureAwait(false); 114 | } 115 | else 116 | { 117 | return await dispatcher.InvokeAsync(action).ConfigureAwait(false); 118 | } 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/IDataStorage.cs: -------------------------------------------------------------------------------- 1 | using JetBrains.Annotations; 2 | 3 | namespace Egor92.MvvmNavigation 4 | { 5 | public interface IDataStorage 6 | { 7 | void Add([NotNull] string key, [NotNull] RegistrationData registrationData); 8 | 9 | bool IsExist([NotNull] string key); 10 | 11 | RegistrationData Get([NotNull] string key); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/IViewInteractionStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using JetBrains.Annotations; 5 | 6 | namespace Egor92.MvvmNavigation 7 | { 8 | public interface IViewInteractionStrategy 9 | { 10 | object GetContent(object control); 11 | 12 | void SetContent([NotNull] object control, object content); 13 | 14 | object GetDataContext([NotNull] object control); 15 | 16 | void SetDataContext([NotNull] object control, object dataContext); 17 | 18 | void InvokeInUIThread([NotNull] object control, [NotNull] Action action); 19 | 20 | T InvokeInUiThread([NotNull] object control, [NotNull] Func action); 21 | 22 | Task InvokeInUiThreadAsync([NotNull] object control, [NotNull] Func> action, CancellationToken token); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/Internal/DataStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Egor92.MvvmNavigation.Internal 5 | { 6 | internal class DataStorage : IDataStorage 7 | { 8 | private readonly IDictionary _navigationDataByKey = new Dictionary(); 9 | 10 | public void Add(string key, RegistrationData registrationData) 11 | { 12 | if (key == null) 13 | { 14 | throw new ArgumentNullException(nameof(key)); 15 | } 16 | 17 | if (registrationData == null) 18 | { 19 | throw new ArgumentNullException(nameof(registrationData)); 20 | } 21 | 22 | _navigationDataByKey[key] = registrationData; 23 | } 24 | 25 | public bool IsExist(string key) 26 | { 27 | if (key == null) 28 | { 29 | throw new ArgumentNullException(nameof(key)); 30 | } 31 | 32 | return _navigationDataByKey.ContainsKey(key); 33 | } 34 | 35 | public RegistrationData Get(string key) 36 | { 37 | if (key == null) 38 | { 39 | throw new ArgumentNullException(nameof(key)); 40 | } 41 | 42 | return _navigationDataByKey[key]; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/Internal/ExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Internal 2 | { 3 | public static class ExceptionMessages 4 | { 5 | public const string CanNotRegisterKeyTwice = "Can't register navigation key twice"; 6 | 7 | public static string KeyIsNotRegistered(string navigationKey) 8 | { 9 | return $"Key '{navigationKey}' is not registered for navigation"; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/MvvmNavigation.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | Egor92.MvvmNavigation 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/NavigationManagerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Egor92.MvvmNavigation.Abstractions; 6 | using Egor92.MvvmNavigation.Internal; 7 | using JetBrains.Annotations; 8 | 9 | namespace Egor92.MvvmNavigation 10 | { 11 | public abstract class NavigationManagerBase : INavigationManager 12 | { 13 | #region Fields 14 | 15 | private readonly Stack _navigationHistory = new(); 16 | private readonly Navigator _navigator; 17 | 18 | #endregion 19 | 20 | #region Ctor 21 | 22 | protected NavigationManagerBase([NotNull] object frameControl, IViewInteractionStrategy viewInteractionStrategy) 23 | : this(frameControl, viewInteractionStrategy, new DataStorage()) 24 | { 25 | } 26 | 27 | protected NavigationManagerBase([NotNull] object frameControl, 28 | IViewInteractionStrategy viewInteractionStrategy, 29 | [NotNull] IDataStorage dataStorage) 30 | { 31 | _navigator = new Navigator(frameControl, viewInteractionStrategy, dataStorage); 32 | } 33 | 34 | #endregion 35 | 36 | #region Navigated 37 | 38 | public event EventHandler Navigated; 39 | 40 | private void RaiseNavigated(NavigationEventArgs e) 41 | { 42 | Navigated?.Invoke(this, e); 43 | } 44 | 45 | #endregion 46 | 47 | public void Register([NotNull] string navigationKey, [NotNull] Func getViewModel, [NotNull] Func getView) 48 | { 49 | _navigator.Register(navigationKey, getViewModel, getView); 50 | } 51 | 52 | public bool CanNavigate(string navigationKey) 53 | { 54 | return _navigator.CanNavigate(navigationKey); 55 | } 56 | 57 | public NavigationData Navigate(string navigationKey, object arg) 58 | { 59 | var navigationData = _navigator.Navigate(navigationKey, arg); 60 | var navigationEventArgs = new NavigationEventArgs(navigationData.View, navigationData.ViewModel, navigationKey, arg); 61 | SaveNavigationHistory(navigationData.ViewModel, navigationData.View); 62 | RaiseNavigated(navigationEventArgs); 63 | return navigationData; 64 | } 65 | 66 | public async Task NavigateAsync(string navigationKey, object arg, CancellationToken token = default) 67 | { 68 | var navigationData = await _navigator.NavigateAsync(navigationKey, arg, token).ConfigureAwait(false); 69 | var navigationEventArgs = new NavigationEventArgs(navigationData.View, navigationData.ViewModel, navigationKey, arg); 70 | SaveNavigationHistory(navigationData.ViewModel, navigationData.View); 71 | RaiseNavigated(navigationEventArgs); 72 | return navigationData; 73 | } 74 | 75 | private void SaveNavigationHistory(object viewModel, object view) 76 | { 77 | _navigationHistory.Push(new NavigationData 78 | { 79 | ViewModel = viewModel, 80 | View = view, 81 | }); 82 | } 83 | 84 | public NavigationData NavigateBack() 85 | { 86 | var navigationData = _navigationHistory.Pop(); 87 | return _navigator.Navigate(navigationData.View); 88 | } 89 | 90 | public Task NavigateBackAsync(CancellationToken token = default) 91 | { 92 | var navigationData = _navigationHistory.Pop(); 93 | return _navigator.NavigateAsync(navigationData.View, token); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/NavigationManagerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JetBrains.Annotations; 3 | 4 | namespace Egor92.MvvmNavigation 5 | { 6 | public static class NavigationManagerBaseExtensions 7 | { 8 | public static void Register([NotNull] this NavigationManagerBase navigationManager, 9 | [NotNull] string navigationKey, 10 | [NotNull] Func getViewModel) 11 | where TView : class, new() 12 | { 13 | navigationManager.Register(navigationKey, getViewModel, () => new TView()); 14 | } 15 | 16 | public static void Register([NotNull] this NavigationManagerBase navigationManager, 17 | [NotNull] string navigationKey, 18 | object viewModel) 19 | where TView : class, new() 20 | { 21 | Func getView = Activator.CreateInstance; 22 | navigationManager.Register(navigationKey, () => viewModel, () => new TView()); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Core/RegistrationData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JetBrains.Annotations; 3 | 4 | namespace Egor92.MvvmNavigation 5 | { 6 | public sealed class RegistrationData 7 | { 8 | public RegistrationData([NotNull] Func viewModelFunc, [NotNull] Func viewFunc) 9 | { 10 | ViewModelFunc = viewModelFunc ?? throw new ArgumentNullException(nameof(viewModelFunc)); 11 | ViewFunc = viewFunc ?? throw new ArgumentNullException(nameof(viewFunc)); 12 | } 13 | 14 | public Func ViewModelFunc { get; } 15 | 16 | public Func ViewFunc { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/FrameControlTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Egor92.MvvmNavigation.Internal 4 | { 5 | internal class FrameControlTypeAttribute : Attribute 6 | { 7 | internal FrameControlTypeAttribute(Type frameControlType) 8 | { 9 | FrameControlType = frameControlType; 10 | } 11 | 12 | internal Type FrameControlType { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/FrameControlTypeProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Egor92.MvvmNavigation.Internal 5 | { 6 | internal class FrameControlTypeProvider : IFrameControlTypeProvider 7 | { 8 | public Type GetFrameControlType(Type navigationManagerType) 9 | { 10 | var attributeData = navigationManagerType.GetCustomAttributesData() 11 | .FirstOrDefault(a => a.AttributeType == typeof(FrameControlTypeAttribute)); 12 | 13 | if (attributeData?.ConstructorArguments.Count != 1) 14 | { 15 | return null; 16 | } 17 | 18 | var argument = attributeData.ConstructorArguments[0]; 19 | return (Type) argument.Value; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/IFrameControlTypeProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Egor92.MvvmNavigation.Internal 4 | { 5 | internal interface IFrameControlTypeProvider 6 | { 7 | Type GetFrameControlType(Type navigationManagerType); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/INavigationManagerTypeProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Egor92.MvvmNavigation.Internal 4 | { 5 | internal interface INavigationManagerTypeProvider 6 | { 7 | Type GetNavigationManagerType(); 8 | } 9 | } -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/MvvmNavigation.Internal.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | false 6 | 7 | 8 | 9 | 10 | <_Parameter1>MvvmNavigation.Unity 11 | 12 | 13 | <_Parameter1>MvvmNavigation.Wpf 14 | 15 | 16 | <_Parameter1>MvvmNavigation.Avalonia 17 | 18 | 19 | <_Parameter1>MvvmNavigation.Unity.UnitTests 20 | 21 | 22 | <_Parameter1>DynamicProxyGenAssembly2 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Internal/NavigationManagerTypeProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Egor92.MvvmNavigation.Internal 5 | { 6 | internal class NavigationManagerTypeProvider : INavigationManagerTypeProvider 7 | { 8 | private static readonly string[] AssemblyNames = 9 | { 10 | "MvvmNavigation.Avalonia", 11 | "MvvmNavigation.Wpf" 12 | }; 13 | 14 | public Type GetNavigationManagerType() 15 | { 16 | return AssemblyNames.Select(assemblyName => $"Egor92.MvvmNavigation.NavigationManager, {assemblyName}") 17 | .Select(Type.GetType) 18 | .FirstOrDefault(x => x != null); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Unity/Internal/ExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Abstractions; 3 | 4 | namespace Egor92.MvvmNavigation.Unity.Internal 5 | { 6 | internal static class ExceptionMessages 7 | { 8 | internal static string CanNotRegisterInterfaceAsViewModel() 9 | { 10 | return $"Can't register interface {typeof(TViewModel).FullName} as ViewModel. Type of ViewModel must be instance class"; 11 | } 12 | 13 | internal static string CanNotRegisterAbstractClassAsViewModel() 14 | { 15 | return $"Can't register abstract class {typeof(TViewModel).FullName} as ViewModel. Type of ViewModel must be instance class"; 16 | } 17 | 18 | internal static string CanNotRegisterInterfaceAsView() 19 | { 20 | return $"Can't register interface {typeof(TView).FullName} as View. Type of View must be instance class"; 21 | } 22 | 23 | internal static string CanNotRegisterAbstractClassAsView() 24 | { 25 | return $"Can't register abstract class {typeof(TView).FullName} as View. Type of View must be instance class"; 26 | } 27 | 28 | internal static string CanNotRegisterTypeAsNavigationManager(Type navigationManagerType) 29 | { 30 | return 31 | $"Can't register type {navigationManagerType.FullName} as NavigationManager. NavigationManager type must implement {typeof(INavigationManager).FullName} interface"; 32 | } 33 | 34 | internal static string FailedToRegisterNavigationManager() 35 | { 36 | return "It's failed to register NavigationManager"; 37 | } 38 | 39 | internal static string CanNotRegisterAbstractNavigationManagerType(Type navigationManagerType) 40 | { 41 | return $"Can't register abstract NavigationManager type {navigationManagerType.FullName}"; 42 | } 43 | 44 | internal static string FrameControlIsNotOfFrameControlType(object frameControl, Type frameControlType) 45 | { 46 | return $"FrameControl ({frameControl.GetType().FullName}) is not of FrameControlType ({frameControlType.FullName})"; 47 | } 48 | 49 | internal static string FrameControlTypeIsNotFound() 50 | { 51 | return "FrameControlType isn't found"; 52 | } 53 | 54 | internal static string NavigationManagerTypeIsNotFound() 55 | { 56 | return "NavigationManagerType isn't found"; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Unity/Internal/NavigationManagerCtorInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Injection; 3 | 4 | namespace Egor92.MvvmNavigation.Unity.Internal 5 | { 6 | internal static class NavigationManagerCtorInfo 7 | { 8 | internal static InjectionConstructor GetInjectionConstructor(Type frameControlType) 9 | { 10 | object[] resolvedParameters = 11 | { 12 | new ResolvedParameter(frameControlType, Args.FrameControl.Name), 13 | new ResolvedParameter() 14 | }; 15 | return new InjectionConstructor(resolvedParameters); 16 | } 17 | 18 | internal static class Args 19 | { 20 | internal static class FrameControl 21 | { 22 | internal const string Name = "frameControl"; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Unity/MvvmNavigation.Unity.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | <_Parameter1>MvvmNavigation.Wpf.Unity.IntegrationTests 22 | 23 | 24 | <_Parameter1>MvvmNavigation.Avalonia.Unity.IntegrationTests 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Unity/UnityDataStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JetBrains.Annotations; 3 | using Unity; 4 | 5 | namespace Egor92.MvvmNavigation.Unity 6 | { 7 | public class UnityDataStorage : IDataStorage 8 | { 9 | private readonly IUnityContainer _unityContainer; 10 | 11 | public UnityDataStorage([NotNull] IUnityContainer unityContainer) 12 | { 13 | _unityContainer = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer)); 14 | } 15 | 16 | public void Add(string key, RegistrationData registrationData) 17 | { 18 | if (key == null) 19 | { 20 | throw new ArgumentNullException(nameof(key)); 21 | } 22 | 23 | if (registrationData == null) 24 | { 25 | throw new ArgumentNullException(nameof(registrationData)); 26 | } 27 | 28 | _unityContainer.RegisterInstance(key, registrationData); 29 | } 30 | 31 | public bool IsExist(string key) 32 | { 33 | if (key == null) 34 | { 35 | throw new ArgumentNullException(nameof(key)); 36 | } 37 | 38 | return _unityContainer.IsRegistered(key); 39 | } 40 | 41 | public RegistrationData Get(string key) 42 | { 43 | if (key == null) 44 | { 45 | throw new ArgumentNullException(nameof(key)); 46 | } 47 | 48 | return _unityContainer.Resolve(key); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Wpf/Internal/ExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Internal 2 | { 3 | public static class ExceptionMessages 4 | { 5 | public const string ControlIsNotOfTypeDispatcherObject = "Control isn't of type 'DispatcherObject'"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Wpf/MvvmNavigation.Wpf.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | true 6 | true 7 | $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage 8 | Egor92.MvvmNavigation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Wpf/NavigationManager.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | using Egor92.MvvmNavigation.Internal; 3 | using JetBrains.Annotations; 4 | 5 | namespace Egor92.MvvmNavigation 6 | { 7 | [FrameControlType(typeof(ContentControl))] 8 | public class NavigationManager : NavigationManagerBase 9 | { 10 | public NavigationManager([NotNull] ContentControl frameControl) 11 | : base(frameControl, new ViewInteractionStrategy()) 12 | { 13 | } 14 | 15 | public NavigationManager([NotNull] ContentControl frameControl, [NotNull] IDataStorage dataStorage) 16 | : base(frameControl, new ViewInteractionStrategy(), dataStorage) 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /code/src/MvvmNavigation.Wpf/ViewInteractionStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Threading; 7 | using Egor92.MvvmNavigation.Internal; 8 | using JetBrains.Annotations; 9 | 10 | namespace Egor92.MvvmNavigation 11 | { 12 | public class ViewInteractionStrategy : IViewInteractionStrategy 13 | { 14 | public object GetContent(object control) 15 | { 16 | if (control == null) 17 | { 18 | throw new ArgumentNullException(nameof(control)); 19 | } 20 | 21 | if (!(control is ContentControl contentControl)) 22 | { 23 | return null; 24 | } 25 | 26 | return contentControl.Content; 27 | } 28 | 29 | public void SetContent(object control, [NotNull] object content) 30 | { 31 | if (control == null) 32 | { 33 | throw new ArgumentNullException(nameof(control)); 34 | } 35 | 36 | if (control is ContentControl contentControl) 37 | { 38 | contentControl.Content = content; 39 | } 40 | } 41 | 42 | public object GetDataContext(object control) 43 | { 44 | if (control == null) 45 | { 46 | throw new ArgumentNullException(nameof(control)); 47 | } 48 | 49 | if (control is FrameworkElement frameworkElement) 50 | { 51 | return frameworkElement.DataContext; 52 | } 53 | 54 | return null; 55 | } 56 | 57 | public void SetDataContext(object control, object dataContext) 58 | { 59 | if (control == null) 60 | { 61 | throw new ArgumentNullException(nameof(control)); 62 | } 63 | 64 | if (control is FrameworkElement frameworkElement) 65 | { 66 | frameworkElement.DataContext = dataContext; 67 | } 68 | } 69 | 70 | [Obsolete] 71 | public void InvokeInUIThread(object control, Action action) 72 | { 73 | if (control == null) 74 | { 75 | throw new ArgumentNullException(nameof(control)); 76 | } 77 | 78 | if (action == null) 79 | { 80 | throw new ArgumentNullException(nameof(action)); 81 | } 82 | 83 | if (!(control is DispatcherObject dispatcherObject)) 84 | { 85 | return; 86 | } 87 | 88 | var dispatcher = dispatcherObject.Dispatcher; 89 | if (dispatcher == null || dispatcher.CheckAccess()) 90 | { 91 | action(); 92 | } 93 | else 94 | { 95 | dispatcher.Invoke(action, DispatcherPriority.Normal); 96 | } 97 | } 98 | 99 | public T InvokeInUiThread(object control, Func action) 100 | { 101 | if (control == null) 102 | { 103 | throw new ArgumentNullException(nameof(control)); 104 | } 105 | 106 | if (action == null) 107 | { 108 | throw new ArgumentNullException(nameof(action)); 109 | } 110 | 111 | if (!(control is DispatcherObject dispatcherObject)) 112 | { 113 | throw new ArgumentException(ExceptionMessages.ControlIsNotOfTypeDispatcherObject); 114 | } 115 | 116 | var dispatcher = dispatcherObject.Dispatcher; 117 | if (dispatcher == null || dispatcher.CheckAccess()) 118 | { 119 | return action(); 120 | } 121 | else 122 | { 123 | return dispatcher.Invoke(action, DispatcherPriority.Normal); 124 | } 125 | } 126 | 127 | public async Task InvokeInUiThreadAsync(object control, Func> action, CancellationToken token) 128 | { 129 | if (control == null) 130 | { 131 | throw new ArgumentNullException(nameof(control)); 132 | } 133 | 134 | if (action == null) 135 | { 136 | throw new ArgumentNullException(nameof(action)); 137 | } 138 | 139 | if (!(control is DispatcherObject dispatcherObject)) 140 | { 141 | throw new ArgumentException(ExceptionMessages.ControlIsNotOfTypeDispatcherObject); 142 | } 143 | 144 | var dispatcher = dispatcherObject.Dispatcher; 145 | if (dispatcher == null || dispatcher.CheckAccess()) 146 | { 147 | return await action().ConfigureAwait(false); 148 | } 149 | else 150 | { 151 | var task = await dispatcher.InvokeAsync(action, DispatcherPriority.Normal).Task.ConfigureAwait(false); 152 | return await task.ConfigureAwait(false); 153 | } 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /code/src/System.Runtime.CompilerServices/CompilerFeatureRequiredAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Runtime.CompilerServices; 2 | 3 | /// 4 | /// Indicates that compiler support for a particular feature is required for the location where this attribute is applied. 5 | /// 6 | [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] 7 | public sealed class CompilerFeatureRequiredAttribute : Attribute 8 | { 9 | public CompilerFeatureRequiredAttribute(string featureName) 10 | { 11 | FeatureName = featureName; 12 | } 13 | 14 | /// 15 | /// The name of the compiler feature. 16 | /// 17 | public string FeatureName { get; } 18 | 19 | /// 20 | /// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand . 21 | /// 22 | public bool IsOptional { get; init; } 23 | 24 | /// 25 | /// The used for the ref structs C# feature. 26 | /// 27 | public const string RefStructs = nameof(RefStructs); 28 | 29 | /// 30 | /// The used for the required members C# feature. 31 | /// 32 | public const string RequiredMembers = nameof(RequiredMembers); 33 | } -------------------------------------------------------------------------------- /code/src/System.Runtime.CompilerServices/IsExternalInit.cs: -------------------------------------------------------------------------------- 1 | namespace System.Runtime.CompilerServices; 2 | 3 | internal static class IsExternalInit; -------------------------------------------------------------------------------- /code/src/System.Runtime.CompilerServices/Readme.md: -------------------------------------------------------------------------------- 1 | Folder 'System.Runtime.CompilerServices' contains classes that are reqiured to be added to projects with target framework netcore3.0 and netstandart2.0. 2 | These classes are required to use features of C# 9.0 and higher -------------------------------------------------------------------------------- /code/src/System.Runtime.CompilerServices/RequiredMemberAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Runtime.CompilerServices; 2 | 3 | /// Specifies that a type has required members or that a member is required. 4 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] 5 | #if SYSTEM_PRIVATE_CORELIB 6 | public 7 | #else 8 | internal 9 | #endif 10 | sealed class RequiredMemberAttribute : Attribute 11 | { 12 | 13 | } -------------------------------------------------------------------------------- /code/src/System.Runtime.CompilerServices/SetsRequiredMembersAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Diagnostics.CodeAnalysis; 2 | 3 | /// 4 | /// Specifies that this constructor sets all required members for the current type, and callers 5 | /// do not need to set any required members themselves. 6 | /// 7 | [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] 8 | #if SYSTEM_PRIVATE_CORELIB 9 | public 10 | #else 11 | internal 12 | #endif 13 | sealed class SetsRequiredMembersAttribute : Attribute 14 | { 15 | } -------------------------------------------------------------------------------- /code/test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Abstractions.ContractTests/MvvmNavigation.Abstractions.ContractTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Abstractions.ContractTests/NavigationManagerContractTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Egor92.MvvmNavigation.Tests.Common; 3 | using NUnit.Framework; 4 | using NUnit.Framework.Constraints; 5 | 6 | namespace Egor92.MvvmNavigation.Abstractions.ContractTests 7 | { 8 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 9 | [SuppressMessage("ReSharper", "InconsistentNaming")] 10 | [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] 11 | public abstract class NavigationManagerContractTests 12 | where TNavigationManager : INavigationManager 13 | { 14 | #region Fields 15 | 16 | private string _navigationKey; 17 | protected TNavigationManager _navigationManager; 18 | 19 | #endregion 20 | 21 | #region Setup 22 | 23 | public virtual void SetUp() 24 | { 25 | _navigationKey = "navigationKey"; 26 | _navigationManager = CreateNavigationManager(); 27 | } 28 | 29 | protected abstract TNavigationManager CreateNavigationManager(); 30 | 31 | #endregion 32 | 33 | #region CanNavigate_KeyIsNull_ThrowException 34 | 35 | [Test] 36 | public void CanNavigate_KeyIsNull_ThrowException() 37 | { 38 | //Act 39 | TestDelegate action = () => 40 | { 41 | _navigationManager.CanNavigate(null); 42 | }; 43 | 44 | //Assert 45 | Assert.That(action, Throws.ArgumentNullException); 46 | } 47 | 48 | #endregion 49 | 50 | #region Navigate_ThrowExceptionDependingOnCanNavigate 51 | 52 | public static TestCaseData[] Navigate_ThrowExceptionDependingOnCanNavigate_CaseSource() 53 | { 54 | return new[] 55 | { 56 | TestCaseDataBuilder.Create() 57 | .WithParameter(false, "if can't navigate") 58 | .WithParameter(Throws.InvalidOperationException, "throw InvalidOperationException") 59 | .Build(), 60 | TestCaseDataBuilder.Create() 61 | .WithParameter(true, "if can navigate") 62 | .WithParameter(Throws.Nothing, "throw nothing") 63 | .Build(), 64 | }; 65 | } 66 | 67 | [TestCaseSource(nameof(Navigate_ThrowExceptionDependingOnCanNavigate_CaseSource))] 68 | public void Navigate_ThrowExceptionDependingOnCanNavigate(bool canNavigate, Constraint throwExceptionConstraint) 69 | { 70 | //Arrange 71 | SetupCanNavigate(_navigationManager, _navigationKey, canNavigate); 72 | 73 | if (_navigationManager.CanNavigate(_navigationKey) != canNavigate) 74 | { 75 | Assert.Fail($"The test is configured incorrectly. SetupCanNavigate method didn't set CanNavigate(navigationKey) to {canNavigate}"); 76 | } 77 | 78 | //Act 79 | TestDelegate action = () => 80 | { 81 | _navigationManager.Navigate(_navigationKey, null); 82 | }; 83 | 84 | //Assert 85 | Assert.That(action, throwExceptionConstraint); 86 | } 87 | 88 | protected abstract void SetupCanNavigate(TNavigationManager navigationManager, string navigationKey, bool canNavigate); 89 | 90 | #endregion 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Abstractions.UnitTests/MvvmNavigation.Abstractions.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Abstractions.UnitTests/NavigationManagerExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using Moq; 4 | using NUnit.Framework; 5 | 6 | namespace Egor92.MvvmNavigation.Abstractions.UnitTests 7 | { 8 | [TestFixture] 9 | public class NavigationManagerExtensionsTests 10 | { 11 | private readonly Mock _navigationManager = new Mock(); 12 | 13 | [Test] 14 | public void Navigate_WithoutParameter_ArgIsNull() 15 | { 16 | //Arrange 17 | string key = TestContext.CurrentContext.Random.GetString(); 18 | 19 | //Act 20 | _navigationManager.Object.Navigate(key); 21 | 22 | //Assert 23 | _navigationManager.Verify(x => x.Navigate(key, null), Times.Once); 24 | } 25 | 26 | [Test] 27 | public async Task NavigateAsync_WithoutParameter_ArgIsNull() 28 | { 29 | //Arrange 30 | string key = TestContext.CurrentContext.Random.GetString(); 31 | 32 | //Act 33 | await _navigationManager.Object.NavigateAsync(key); 34 | 35 | //Assert 36 | _navigationManager.Verify(x => x.NavigateAsync(key, null, default), Times.Once); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.UnitTests/MvvmNavigation.Avalonia.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.UnitTests/NavigationManagerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Avalonia.Controls; 4 | using Egor92.MvvmNavigation.Core.ContractTests; 5 | using NUnit.Framework; 6 | 7 | namespace Egor92.MvvmNavigation.Avalonia.UnitTests 8 | { 9 | [TestFixture] 10 | [Parallelizable(ParallelScope.Children)] 11 | [Apartment(ApartmentState.STA)] 12 | public class NavigationManagerTests : NavigationManagerBaseContractTests 13 | { 14 | [SetUp] 15 | public override void SetUp() 16 | { 17 | base.SetUp(); 18 | } 19 | 20 | protected override NavigationManager CreateNavigationManager(ContentControl frameControl) 21 | { 22 | return new NavigationManager(frameControl); 23 | } 24 | 25 | protected override NavigationManager CreateNavigationManager(ContentControl frameControl, IDataStorage dataStorage) 26 | { 27 | return new NavigationManager(frameControl, dataStorage); 28 | } 29 | 30 | protected override void RegisterNavigationRule(NavigationManager navigationManager, 31 | string navigationKey, 32 | Func viewModelFunc, 33 | Func viewFunc) 34 | { 35 | navigationManager.Register(navigationKey, viewModelFunc, viewFunc); 36 | } 37 | 38 | protected override object GetContent(ContentControl contentControl) 39 | { 40 | return contentControl.Content; 41 | } 42 | 43 | protected override object GetDataContext(object view) 44 | { 45 | return (view as Control)?.DataContext; 46 | } 47 | 48 | protected override void SetupCanNavigate(NavigationManager navigationManager, string navigationKey, bool canNavigate) 49 | { 50 | if (canNavigate) 51 | { 52 | navigationManager.Register(navigationKey, () => new object(), () => new ContentControl()); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.UnitTests/NavigationManagerTypeProviderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Internal.ContractTests; 3 | using NUnit.Framework; 4 | 5 | namespace Egor92.MvvmNavigation.Avalonia.UnitTests 6 | { 7 | [TestFixture] 8 | public class NavigationManagerTypeProviderTests : NavigationManagerTypeProviderContractTests 9 | { 10 | protected override Type GetRequiredNavigationManagerType() 11 | { 12 | return typeof(NavigationManager); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.UnitTests/ViewInteractionStrategyTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Avalonia.Controls; 3 | using Egor92.MvvmNavigation.Core.ContractTests; 4 | using NUnit.Framework; 5 | 6 | namespace Egor92.MvvmNavigation.Avalonia.UnitTests 7 | { 8 | [TestFixture] 9 | [Apartment(ApartmentState.STA)] 10 | public class ViewInteractionStrategyTests : ViewInteractionStrategyContractTests 11 | { 12 | [SetUp] 13 | public override void SetUp() 14 | { 15 | base.SetUp(); 16 | } 17 | 18 | protected override ViewInteractionStrategy CreateViewInteractionStrategy() 19 | { 20 | return new ViewInteractionStrategy(); 21 | } 22 | 23 | protected override object GetContent(ContentControl contentControl) 24 | { 25 | return contentControl.Content; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.Unity.IntegrationTests/Internal/ThrowsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Unity.Internal; 3 | using NUnit.Framework; 4 | using NUnit.Framework.Constraints; 5 | 6 | namespace Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests.Internal 7 | { 8 | internal static class ThrowsException 9 | { 10 | internal static IResolveConstraint FrameControlIsNotOfFrameControlType(object frameControl, Type frameControlType) 11 | { 12 | var message = ExceptionMessages.FrameControlIsNotOfFrameControlType(frameControl, frameControlType); 13 | return Throws.ArgumentException.And.Message.EqualTo(message); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.Unity.IntegrationTests/Internal/Types/View.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Avalonia.Controls; 3 | 4 | namespace Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests.Internal.Types 5 | { 6 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 7 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] 8 | internal class View : ContentControl 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.Unity.IntegrationTests/Internal/Types/ViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests.Internal.Types 4 | { 5 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 6 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] 7 | public class ViewModel 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.Unity.IntegrationTests/MvvmNavigation.Avalonia.Unity.IntegrationTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Avalonia.Unity.IntegrationTests/ScenarioTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Avalonia.Controls; 3 | using Egor92.MvvmNavigation.Abstractions; 4 | using Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests.Internal; 5 | using Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests.Internal.Types; 6 | using Egor92.MvvmNavigation.Tests.Common.Unity; 7 | using Egor92.MvvmNavigation.Unity; 8 | using NUnit.Framework; 9 | using Unity; 10 | 11 | namespace Egor92.MvvmNavigation.Avalonia.Unity.IntegrationTests 12 | { 13 | [TestFixture] 14 | [Apartment(ApartmentState.STA)] 15 | public class ScenarioTests 16 | { 17 | private UnityContainer _unityContainer; 18 | 19 | [SetUp] 20 | public void SetUp() 21 | { 22 | _unityContainer = new UnityContainer(); 23 | } 24 | 25 | [TearDown] 26 | public void TearDown() 27 | { 28 | _unityContainer.Dispose(); 29 | } 30 | 31 | [Test] 32 | public void RegisterNavigationManager_NavigationManagerIsRegistered() 33 | { 34 | //Arrange 35 | var frameControl = new ContentControl(); 36 | 37 | //Act 38 | _unityContainer.RegisterNavigationManager(frameControl); 39 | 40 | //Assert 41 | UnityAssert.IsRegistered(_unityContainer); 42 | } 43 | 44 | [Test] 45 | public void RegisterNavigationManager_INavigationManagerIsRegistered() 46 | { 47 | //Arrange 48 | var frameControl = new ContentControl(); 49 | 50 | //Act 51 | _unityContainer.RegisterNavigationManager(frameControl); 52 | 53 | //Assert 54 | UnityAssert.IsRegistered(_unityContainer); 55 | } 56 | 57 | [Test] 58 | public void RegisterNavigationManager_FrameControlIsNotContentControl_ThrowException() 59 | { 60 | //Arrange 61 | var frameControl = new object(); 62 | 63 | //Act 64 | void Action() 65 | { 66 | _unityContainer.RegisterNavigationManager(frameControl); 67 | } 68 | 69 | //Assert 70 | Assert.That(Action, ThrowsException.FrameControlIsNotOfFrameControlType(frameControl, typeof(ContentControl))); 71 | } 72 | 73 | [Test] 74 | public void RegisterNavigationManager_NavigationManagerCanBeResolved() 75 | { 76 | //Arrange 77 | var frameControl = new ContentControl(); 78 | 79 | //Act 80 | _unityContainer.RegisterNavigationManager(frameControl); 81 | 82 | //Assert 83 | UnityAssert.CanResolve(_unityContainer); 84 | } 85 | 86 | [Test] 87 | public void RegisterNavigationRule_CanNavigate() 88 | { 89 | //Arrange 90 | var navigationKey = "navigationKey"; 91 | var frameControl = new ContentControl(); 92 | _unityContainer.RegisterNavigationManager(frameControl); 93 | 94 | //Act 95 | _unityContainer.RegisterNavigationRule(navigationKey); 96 | var navigationManager = _unityContainer.Resolve(); 97 | navigationManager.Navigate(navigationKey); 98 | 99 | //Assert 100 | Assert.That(frameControl.Content, Is.TypeOf()); 101 | Assert.That(((View)frameControl.Content).DataContext, Is.TypeOf()); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.ContractTests/Internal/ArgumentNames.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Core.ContractTests.Internal 2 | { 3 | public static class ArgumentNames 4 | { 5 | public const string Key = "key"; 6 | public const string RegistrationData = "registrationData"; 7 | public const string Control = "control"; 8 | public const string Action = "action"; 9 | public const string NavigationKey = "navigationKey"; 10 | public const string GetViewModel = "getViewModel"; 11 | public const string GetView = "getView"; 12 | public const string ViewModelFunc = "viewModelFunc"; 13 | public const string ViewFunc = "viewFunc"; 14 | public const string DataStorage = "dataStorage"; 15 | public const string ViewInteractionStrategy = "viewInteractionStrategy"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.ContractTests/Internal/ThrowsException.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using NUnit.Framework.Constraints; 3 | 4 | namespace Egor92.MvvmNavigation.Core.ContractTests.Internal 5 | { 6 | internal static class ThrowsException 7 | { 8 | internal static IResolveConstraint NullArgument(string argumentName) 9 | { 10 | return Throws.ArgumentNullException.With.Property("ParamName").EqualTo(argumentName); 11 | } 12 | 13 | internal static IResolveConstraint CanNotRegisterKeyTwice() 14 | { 15 | var message = MvvmNavigation.Internal.ExceptionMessages.CanNotRegisterKeyTwice; 16 | return Throws.InvalidOperationException.With.Message.EqualTo(message); 17 | } 18 | 19 | internal static IResolveConstraint KeyIsNotRegistered(string navigationKey) 20 | { 21 | var message = MvvmNavigation.Internal.ExceptionMessages.KeyIsNotRegistered(navigationKey); 22 | return Throws.InvalidOperationException.With.Message.EqualTo(message); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.ContractTests/InternalTests/DataStorageTestsBase.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Egor92.MvvmNavigation.Core.ContractTests.Internal; 3 | using NUnit.Framework; 4 | using ThrowsException = Egor92.MvvmNavigation.Tests.Common.ThrowsException; 5 | 6 | namespace Egor92.MvvmNavigation.Core.ContractTests.InternalTests 7 | { 8 | public abstract class DataStorageTestsBase 9 | where TDataStorage : IDataStorage 10 | 11 | { 12 | private TDataStorage _dataStorage; 13 | private RegistrationData _registrationData; 14 | 15 | [SetUp] 16 | public virtual void SetUp() 17 | { 18 | _dataStorage = CreateDataStorage(); 19 | _registrationData = new RegistrationData(() => new object(), () => new object()); 20 | } 21 | 22 | protected abstract TDataStorage CreateDataStorage(); 23 | 24 | [Test] 25 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 26 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 27 | public void Add_KeyIsNull_ThrowException() 28 | { 29 | //Act 30 | TestDelegate action = () => 31 | { 32 | _dataStorage.Add(null, _registrationData); 33 | }; 34 | 35 | //Assert 36 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.Key)); 37 | } 38 | 39 | [Test] 40 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 41 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 42 | public void Add_RegistrationDataIsNull_ThrowException() 43 | { 44 | //Arrange 45 | const string key = "key"; 46 | 47 | //Act 48 | TestDelegate action = () => 49 | { 50 | _dataStorage.Add(key, null); 51 | }; 52 | 53 | //Assert 54 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.RegistrationData)); 55 | } 56 | 57 | [Test] 58 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 59 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 60 | public void IsExist_KeyIsNull_ThrowException() 61 | { 62 | //Act 63 | TestDelegate action = () => 64 | { 65 | _dataStorage.IsExist(null); 66 | }; 67 | 68 | //Assert 69 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.Key)); 70 | } 71 | 72 | [Test] 73 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 74 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 75 | public void Get_KeyIsNull_ThrowException() 76 | { 77 | //Act 78 | TestDelegate action = () => 79 | { 80 | _dataStorage.Get(null); 81 | }; 82 | 83 | //Assert 84 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.Key)); 85 | } 86 | 87 | [Test] 88 | public void IsExist_KeyWasAdded_ReturnTrue() 89 | { 90 | //Arrange 91 | const string key = "key"; 92 | 93 | //Act 94 | _dataStorage.Add(key, _registrationData); 95 | 96 | bool isExist = _dataStorage.IsExist(key); 97 | 98 | //Assert 99 | Assert.That(isExist, Is.True); 100 | } 101 | 102 | [Test] 103 | public void Get_IsExist_NavigationDataIsNotNull() 104 | { 105 | //Arrange 106 | const string key = "key"; 107 | SetupIsExistTrue(_dataStorage, key); 108 | 109 | //Act 110 | var navigationData = _dataStorage.Get(key); 111 | 112 | //Assert 113 | Assert.That(navigationData, Is.Not.Null); 114 | } 115 | 116 | protected abstract void SetupIsExistTrue(TDataStorage dataStorage, string key); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.ContractTests/MvvmNavigation.Core.ContractTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.UnitTests/InternalTests/DataStorageTests.cs: -------------------------------------------------------------------------------- 1 | using Egor92.MvvmNavigation.Core.ContractTests.InternalTests; 2 | using Egor92.MvvmNavigation.Internal; 3 | using NUnit.Framework; 4 | 5 | namespace Egor92.MvvmNavigation.Core.UnitTests.InternalTests 6 | { 7 | [TestFixture] 8 | internal class DataStorageTests : DataStorageTestsBase 9 | { 10 | protected override DataStorage CreateDataStorage() 11 | { 12 | return new DataStorage(); 13 | } 14 | 15 | protected override void SetupIsExistTrue(DataStorage dataStorage, string key) 16 | { 17 | var navigationData = new RegistrationData(() => new object(), () => new object()); 18 | dataStorage.Add(key, navigationData); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.UnitTests/InternalTests/RegistrationDataTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Egor92.MvvmNavigation.Core.ContractTests.Internal; 3 | using Egor92.MvvmNavigation.Tests.Common; 4 | using NUnit.Framework; 5 | 6 | namespace Egor92.MvvmNavigation.Core.UnitTests.InternalTests 7 | { 8 | [TestFixture] 9 | internal class RegistrationDataTests 10 | { 11 | [Test] 12 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 13 | [SuppressMessage("ReSharper", "ObjectCreationAsStatement")] 14 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 15 | public void ViewModelFuncIsNull_ThrowException() 16 | { 17 | //Act 18 | TestDelegate action = () => 19 | { 20 | new RegistrationData(null, () => new object()); 21 | }; 22 | 23 | //Assert 24 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.ViewModelFunc)); 25 | } 26 | 27 | [Test] 28 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 29 | [SuppressMessage("ReSharper", "ObjectCreationAsStatement")] 30 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 31 | public void ViewFuncIsNull_ThrowException() 32 | { 33 | //Act 34 | TestDelegate action = () => 35 | { 36 | new RegistrationData(() => new object(), null); 37 | }; 38 | 39 | //Assert 40 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.ViewFunc)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.UnitTests/MvvmNavigation.Core.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Core.UnitTests/NavigationManagerBaseTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Threading; 4 | using Egor92.MvvmNavigation.Core.ContractTests.Internal; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace Egor92.MvvmNavigation.Core.UnitTests 9 | { 10 | [TestFixture] 11 | [Parallelizable(ParallelScope.Children)] 12 | [Apartment(ApartmentState.STA)] 13 | public class NavigationManagerBaseTests 14 | { 15 | [Test] 16 | [SuppressMessage("ReSharper", "ExpressionIsAlwaysNull")] 17 | [SuppressMessage("ReSharper", "UnusedVariable")] 18 | public void ViewInteractionStrategyIsNull_ThrowException() 19 | { 20 | //Arrange 21 | object frameControl = new object(); 22 | IViewInteractionStrategy viewInteractionStrategy = null; 23 | 24 | //Act 25 | void Action() 26 | { 27 | var navigationManagerBase = new Mock(MockBehavior.Strict, frameControl, viewInteractionStrategy).Object; 28 | } 29 | 30 | //Assert 31 | var exception = Assert.Catch(Action); 32 | Assert.That(exception.InnerException, Is.TypeOf()); 33 | 34 | var innerException = (ArgumentNullException) exception.InnerException; 35 | Assert.That(innerException!.ParamName, Is.EqualTo(ArgumentNames.ViewInteractionStrategy)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.ContractTests/MvvmNavigation.Internal.ContractTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.ContractTests/NavigationManagerTypeProviderContractTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace Egor92.MvvmNavigation.Internal.ContractTests 5 | { 6 | public abstract class NavigationManagerTypeProviderContractTests 7 | { 8 | private NavigationManagerTypeProvider _navigationManagerTypeProvider; 9 | 10 | [SetUp] 11 | public void SetUp() 12 | { 13 | _navigationManagerTypeProvider = new NavigationManagerTypeProvider(); 14 | } 15 | 16 | [Test] 17 | public void GetNavigationManagerType_NavigationManagerTypeIsFound() 18 | { 19 | //Act 20 | var navigationManagerType = _navigationManagerTypeProvider.GetNavigationManagerType(); 21 | 22 | //Assert 23 | var requiredNavigationManagerType = GetRequiredNavigationManagerType(); 24 | Assert.That(navigationManagerType, Is.EqualTo(requiredNavigationManagerType)); 25 | } 26 | 27 | protected abstract Type GetRequiredNavigationManagerType(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.UnitTests/FrameControlTypeProviderTests.cs: -------------------------------------------------------------------------------- 1 | using Egor92.MvvmNavigation.Internal.UnitTests.Internal; 2 | using NUnit.Framework; 3 | 4 | namespace Egor92.MvvmNavigation.Internal.UnitTests 5 | { 6 | [TestFixture] 7 | [Parallelizable(ParallelScope.Children)] 8 | [RunInApplicationDomain] 9 | public class FrameControlTypeProviderTests 10 | { 11 | private FrameControlTypeProvider _frameControlTypeProvider; 12 | 13 | [SetUp] 14 | public void SetUp() 15 | { 16 | _frameControlTypeProvider = new FrameControlTypeProvider(); 17 | } 18 | 19 | [Test] 20 | public void GetFrameControlType_TypeHasNoNavigationManagerAttribute_ReturnNull() 21 | { 22 | //Arrange 23 | var generatedType = ClassBuilder.CreateNewClass() 24 | .Build(); 25 | 26 | //Act 27 | var frameControlType = _frameControlTypeProvider.GetFrameControlType(generatedType); 28 | 29 | //Assert 30 | Assert.That(frameControlType, Is.Null); 31 | } 32 | 33 | [Test] 34 | public void GetFrameControlType_InputTypeHasNavigationManagerAttribute_ReturnFrameControlType() 35 | { 36 | //Arrange 37 | var originalFrameControlType = typeof(object); 38 | var generatedType = ClassBuilder.CreateNewClass() 39 | .WithFrameControlType(originalFrameControlType) 40 | .Build(); 41 | 42 | //Act 43 | var frameControlType = _frameControlTypeProvider.GetFrameControlType(generatedType); 44 | 45 | //Assert 46 | Assert.That(frameControlType, Is.EqualTo(originalFrameControlType)); 47 | } 48 | 49 | [Test] 50 | public void GetFrameControlType_FrameControlTypeIsNull_ReturnPlatformSpecificTypeInfoWithNullAsFrameControlType() 51 | { 52 | //Arrange 53 | var generatedType = ClassBuilder.CreateNewClass() 54 | .WithFrameControlType(null) 55 | .Build(); 56 | 57 | //Act 58 | var frameControlType = _frameControlTypeProvider.GetFrameControlType(generatedType); 59 | 60 | //Assert 61 | Assert.That(frameControlType, Is.Null); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.UnitTests/Internal/ArgumentNames.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Internal.UnitTests.Internal 2 | { 3 | public static class ArgumentNames 4 | { 5 | public const string NavigationManagerType = "navigationManagerType"; 6 | public const string FrameControlType = "frameControlType"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.UnitTests/Internal/ClassBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Reflection.Emit; 4 | 5 | namespace Egor92.MvvmNavigation.Internal.UnitTests.Internal 6 | { 7 | internal class ClassBuilder 8 | { 9 | private bool _toConfigureNavigationManagerAttribute; 10 | private Type _frameControlType; 11 | 12 | private ClassBuilder() 13 | { 14 | } 15 | 16 | internal static ClassBuilder CreateNewClass() 17 | { 18 | return new ClassBuilder(); 19 | } 20 | 21 | internal ClassBuilder WithFrameControlType(Type frameControlType) 22 | { 23 | _toConfigureNavigationManagerAttribute = true; 24 | _frameControlType = frameControlType; 25 | return this; 26 | } 27 | 28 | internal Type Build() 29 | { 30 | var typeBuilder = CreateTypeBuilder(); 31 | CreateConstructor(typeBuilder); 32 | if (_toConfigureNavigationManagerAttribute) 33 | { 34 | ConfigureNavigationManagerAttribute(typeBuilder); 35 | } 36 | 37 | return typeBuilder.CreateType(); 38 | } 39 | 40 | private static TypeBuilder CreateTypeBuilder() 41 | { 42 | var assemblyName = new AssemblyName($"GeneratedAssembly_{Guid.NewGuid():N}"); 43 | var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); 44 | var moduleBuilder = assemblyBuilder.DefineDynamicModule($"GeneratedModule_{Guid.NewGuid():N}"); 45 | return moduleBuilder.DefineType($"GeneratedModuleNavigationManager_{Guid.NewGuid():N}", 46 | TypeAttributes.Public 47 | | TypeAttributes.Class 48 | | TypeAttributes.AutoClass 49 | | TypeAttributes.AnsiClass 50 | | TypeAttributes.BeforeFieldInit 51 | | TypeAttributes.AutoLayout, null); 52 | } 53 | 54 | private void ConfigureNavigationManagerAttribute(TypeBuilder typeBuilder) 55 | { 56 | var types = new[] 57 | { 58 | typeof(Type) 59 | }; 60 | var constructorValues = new object[] 61 | { 62 | _frameControlType 63 | }; 64 | var constructorInfo = 65 | typeof(FrameControlTypeAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, types, null); 66 | var customAttributeBuilder = new CustomAttributeBuilder(constructorInfo, constructorValues); 67 | typeBuilder.SetCustomAttribute(customAttributeBuilder); 68 | } 69 | 70 | private static void CreateConstructor(TypeBuilder typeBuilder) 71 | { 72 | typeBuilder.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Internal.UnitTests/MvvmNavigation.Internal.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common.Unity/MvvmNavigation.Tests.Common.Unity.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common.Unity/UnityAssert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | using Unity; 4 | 5 | namespace Egor92.MvvmNavigation.Tests.Common.Unity 6 | { 7 | public static class UnityAssert 8 | { 9 | public static void IsRegistered(IUnityContainer unityContainer) 10 | { 11 | var isRegistered = unityContainer.IsRegistered(); 12 | if (!isRegistered) 13 | { 14 | throw new AssertionException($"Type '{typeof(T).FullName}' isn't registered in UnityContainer"); 15 | } 16 | } 17 | 18 | public static void IsRegisteredWithName(IUnityContainer unityContainer, string name) 19 | { 20 | var isRegistered = unityContainer.IsRegistered(name); 21 | if (!isRegistered) 22 | { 23 | throw new AssertionException($"Type '{typeof(T).FullName}' isn't registered in UnityContainer with name {name}"); 24 | } 25 | } 26 | 27 | public static void CanResolve(IUnityContainer unityContainer) 28 | { 29 | try 30 | { 31 | unityContainer.Resolve(); 32 | } 33 | catch (Exception e) 34 | { 35 | throw new AssertionException($"Type '{typeof(T).FullName}' can't be resolved by UnityContainer", e); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common/MvvmNavigation.Tests.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common/TaskHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace Egor92.MvvmNavigation.Tests.Common 6 | { 7 | public static class TaskHelper 8 | { 9 | public static Task StartTaskWithApartmentState(ApartmentState apartmentState, Action action) 10 | { 11 | return StartTaskWithApartmentState(apartmentState, () => 12 | { 13 | action(); 14 | return null; 15 | }); 16 | } 17 | 18 | public static Task StartTaskWithApartmentState(ApartmentState apartmentState, Func func) 19 | { 20 | var tcs = new TaskCompletionSource(); 21 | Thread thread = new Thread(() => 22 | { 23 | try 24 | { 25 | tcs.SetResult(func()); 26 | } 27 | catch (Exception e) 28 | { 29 | tcs.SetException(e); 30 | } 31 | }); 32 | thread.SetApartmentState(apartmentState); 33 | thread.Name = $"Thread({apartmentState})"; 34 | thread.Start(); 35 | return tcs.Task; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common/TestCaseDataBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | 5 | namespace Egor92.MvvmNavigation.Tests.Common 6 | { 7 | public class TestCaseDataBuilder 8 | { 9 | private readonly IList _values = new List(); 10 | private readonly IList _displayNames = new List(); 11 | 12 | public static TestCaseDataBuilder Create() 13 | { 14 | return new TestCaseDataBuilder(); 15 | } 16 | 17 | public TestCaseDataBuilder WithParameter(object value, string displayName) 18 | { 19 | _values.Add(value); 20 | _displayNames.Add(displayName); 21 | return this; 22 | } 23 | 24 | public TestCaseData Build() 25 | { 26 | var values = _values.ToArray(); 27 | var displayNames = _displayNames.ToArray(); 28 | return new TestCaseData(values).SetArgDisplayNames(displayNames); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Tests.Common/ThrowsException.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using NUnit.Framework.Constraints; 3 | 4 | namespace Egor92.MvvmNavigation.Tests.Common 5 | { 6 | public static class ThrowsException 7 | { 8 | public static IResolveConstraint NullArgument(string argumentName) 9 | { 10 | return Throws.ArgumentNullException.With.Property("ParamName").EqualTo(argumentName); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/ArgumentNames.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal 2 | { 3 | internal static class ArgumentNames 4 | { 5 | public const string UnityContainer = "unityContainer"; 6 | public const string FrameControl = "frameControl"; 7 | public const string NavigationKey = "navigationKey"; 8 | public const string NavigationManagerType = "navigationManagerType"; 9 | public const string FrameControlType = "frameControlType"; 10 | public const string InjectionMembers = "injectionMembers"; 11 | public const string NavigationManagerTypeProvider = "navigationManagerTypeProvider"; 12 | public const string FrameControlTypeProvider = "frameControlTypeProvider"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/ThrowsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Unity.Internal; 3 | using NUnit.Framework; 4 | using NUnit.Framework.Constraints; 5 | 6 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal 7 | { 8 | internal static class ThrowsException 9 | { 10 | internal static IResolveConstraint CanNotRegisterInterfaceAsViewModel() 11 | { 12 | var message = ExceptionMessages.CanNotRegisterInterfaceAsViewModel(); 13 | return Throws.ArgumentException.And.Message.EqualTo(message); 14 | } 15 | 16 | internal static IResolveConstraint CanNotRegisterAbstractClassAsViewModel() 17 | { 18 | var message = ExceptionMessages.CanNotRegisterAbstractClassAsViewModel(); 19 | return Throws.ArgumentException.And.Message.EqualTo(message); 20 | } 21 | 22 | internal static IResolveConstraint CanNotRegisterInterfaceAsView() 23 | { 24 | var message = ExceptionMessages.CanNotRegisterInterfaceAsView(); 25 | return Throws.ArgumentException.And.Message.EqualTo(message); 26 | } 27 | 28 | internal static IResolveConstraint CanNotRegisterAbstractClassAsView() 29 | { 30 | var message = ExceptionMessages.CanNotRegisterAbstractClassAsView(); 31 | return Throws.ArgumentException.And.Message.EqualTo(message); 32 | } 33 | 34 | internal static IResolveConstraint CanNotRegisterTypeAsNavigationManager(Type navigationManagerType) 35 | { 36 | var message = ExceptionMessages.CanNotRegisterTypeAsNavigationManager(navigationManagerType); 37 | return Throws.ArgumentException.And.Message.EqualTo(message); 38 | } 39 | 40 | internal static IResolveConstraint FailedToRegisterNavigationManager() 41 | { 42 | var message = ExceptionMessages.FailedToRegisterNavigationManager(); 43 | return Throws.ArgumentException.And.Message.EqualTo(message); 44 | } 45 | 46 | internal static IResolveConstraint CanNotRegisterAbstractNavigationManagerType(Type navigationManagerType) 47 | { 48 | var message = ExceptionMessages.CanNotRegisterAbstractNavigationManagerType(navigationManagerType); 49 | return Throws.ArgumentException.And.Message.EqualTo(message); 50 | } 51 | 52 | internal static IResolveConstraint FrameControlIsNotOfFrameControlType(object frameControl, Type frameControlType) 53 | { 54 | var message = ExceptionMessages.FrameControlIsNotOfFrameControlType(frameControl, frameControlType); 55 | return Throws.ArgumentException.And.Message.EqualTo(message); 56 | } 57 | 58 | internal static IResolveConstraint NavigationManagerTypeIsNotFound() 59 | { 60 | var message = ExceptionMessages.NavigationManagerTypeIsNotFound(); 61 | return Throws.InvalidOperationException.And.Message.EqualTo(message); 62 | } 63 | 64 | internal static IResolveConstraint FrameControlTypeIsNotFound() 65 | { 66 | var message = ExceptionMessages.FrameControlTypeIsNotFound(); 67 | return Throws.InvalidOperationException.And.Message.EqualTo(message); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/Types/AbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal.Types 4 | { 5 | [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "This type is used for tests only")] 6 | internal abstract class AbstractClass 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/Types/ContentControl.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal.Types 4 | { 5 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "This type is used for tests only")] 6 | internal class ContentControl 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/Types/ISomeInterface.cs: -------------------------------------------------------------------------------- 1 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal.Types 2 | { 3 | internal interface ISomeInterface 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/Types/InstanceClass.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal.Types 4 | { 5 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "This type is used for tests only")] 6 | internal class InstanceClass 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/Internal/Types/NavigationManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Egor92.MvvmNavigation.Abstractions; 5 | 6 | namespace Egor92.MvvmNavigation.Unity.UnitTests.Internal.Types 7 | { 8 | internal class NavigationManager : INavigationManager 9 | { 10 | public bool CanNavigate(string navigationKey) 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public NavigationData Navigate(string navigationKey, object arg) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public Task NavigateAsync(string navigationKey, object arg, CancellationToken token = default) 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public NavigationData NavigateBack() 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | 30 | public Task NavigateBackAsync(CancellationToken token = default) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | 35 | #pragma warning disable 67 36 | public event EventHandler Navigated; 37 | #pragma warning restore 67 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/MvvmNavigation.Unity.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | UnityContainerExtensionsTests.cs 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Unity.UnitTests/UnityDataStorageTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Egor92.MvvmNavigation.Core.ContractTests.InternalTests; 3 | using Egor92.MvvmNavigation.Unity.UnitTests.Internal; 4 | using NUnit.Framework; 5 | using Unity; 6 | using ThrowsException = Egor92.MvvmNavigation.Tests.Common.ThrowsException; 7 | 8 | namespace Egor92.MvvmNavigation.Unity.UnitTests 9 | { 10 | [TestFixture] 11 | [SuppressMessage("ReSharper", "ConvertToLocalFunction")] 12 | public class UnityDataStorageTests : DataStorageTestsBase 13 | { 14 | private IUnityContainer _unityContainer; 15 | 16 | [SetUp] 17 | public override void SetUp() 18 | { 19 | _unityContainer = new UnityContainer(); 20 | base.SetUp(); 21 | } 22 | 23 | [TearDown] 24 | public void TearDown() 25 | { 26 | _unityContainer.Dispose(); 27 | } 28 | 29 | protected override UnityDataStorage CreateDataStorage() 30 | { 31 | return new UnityDataStorage(_unityContainer); 32 | } 33 | 34 | protected override void SetupIsExistTrue(UnityDataStorage dataStorage, string key) 35 | { 36 | var navigationData = new RegistrationData(() => new object(), () => new object()); 37 | _unityContainer.RegisterInstance(key, navigationData); 38 | } 39 | 40 | [Test] 41 | [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] 42 | [SuppressMessage("ReSharper", "ObjectCreationAsStatement")] 43 | public void UnityContainerIsNull_ThrowException() 44 | { 45 | //Act 46 | TestDelegate action = () => 47 | { 48 | new UnityDataStorage(null); 49 | }; 50 | 51 | //Assert 52 | Assert.That(action, ThrowsException.NullArgument(ArgumentNames.UnityContainer)); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.UnitTests/MvvmNavigation.Wpf.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.UnitTests/NavigationManagerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using Egor92.MvvmNavigation.Core.ContractTests; 6 | using NUnit.Framework; 7 | 8 | namespace Egor92.MvvmNavigation.Wpf.UnitTests 9 | { 10 | [TestFixture] 11 | [Parallelizable(ParallelScope.Children)] 12 | [Apartment(ApartmentState.STA)] 13 | public class NavigationManagerTests : NavigationManagerBaseContractTests 14 | { 15 | [SetUp] 16 | public override void SetUp() 17 | { 18 | base.SetUp(); 19 | } 20 | 21 | protected override NavigationManager CreateNavigationManager(ContentControl frameControl) 22 | { 23 | return new NavigationManager(frameControl); 24 | } 25 | 26 | protected override NavigationManager CreateNavigationManager(ContentControl frameControl, IDataStorage dataStorage) 27 | { 28 | return new NavigationManager(frameControl, dataStorage); 29 | } 30 | 31 | protected override void RegisterNavigationRule(NavigationManager navigationManager, 32 | string navigationKey, 33 | Func viewModelFunc, 34 | Func viewFunc) 35 | { 36 | navigationManager.Register(navigationKey, viewModelFunc, viewFunc); 37 | } 38 | 39 | protected override object GetContent(ContentControl contentControl) 40 | { 41 | return contentControl.Content; 42 | } 43 | 44 | protected override object GetDataContext(object view) 45 | { 46 | return (view as FrameworkElement)?.DataContext; 47 | } 48 | 49 | protected override void SetupCanNavigate(NavigationManager navigationManager, string navigationKey, bool canNavigate) 50 | { 51 | if (canNavigate) 52 | { 53 | navigationManager.Register(navigationKey, () => new object(), () => new ContentControl()); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.UnitTests/NavigationManagerTypeProviderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Internal.ContractTests; 3 | using NUnit.Framework; 4 | 5 | namespace Egor92.MvvmNavigation.Wpf.UnitTests 6 | { 7 | [TestFixture] 8 | public class NavigationManagerTypeProviderTests : NavigationManagerTypeProviderContractTests 9 | { 10 | protected override Type GetRequiredNavigationManagerType() 11 | { 12 | return typeof(NavigationManager); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.UnitTests/ViewInteractionStrategyTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using Egor92.MvvmNavigation.Core.ContractTests; 5 | using NUnit.Framework; 6 | 7 | namespace Egor92.MvvmNavigation.Wpf.UnitTests 8 | { 9 | [TestFixture] 10 | [Apartment(ApartmentState.STA)] 11 | public class ViewInteractionStrategyTests : ViewInteractionStrategyContractTests 12 | { 13 | [SetUp] 14 | public override void SetUp() 15 | { 16 | base.SetUp(); 17 | } 18 | 19 | protected override ViewInteractionStrategy CreateViewInteractionStrategy() 20 | { 21 | return new ViewInteractionStrategy(); 22 | } 23 | 24 | protected override object GetContent(ContentControl contentControl) 25 | { 26 | return contentControl.Content; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.Unity.IntegrationTests/Internal/ThrowsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Egor92.MvvmNavigation.Unity.Internal; 3 | using NUnit.Framework; 4 | using NUnit.Framework.Constraints; 5 | 6 | namespace Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests.Internal 7 | { 8 | internal static class ThrowsException 9 | { 10 | internal static IResolveConstraint FrameControlIsNotOfFrameControlType(object frameControl, Type frameControlType) 11 | { 12 | var message = ExceptionMessages.FrameControlIsNotOfFrameControlType(frameControl, frameControlType); 13 | return Throws.ArgumentException.And.Message.EqualTo(message); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.Unity.IntegrationTests/Internal/Types/View.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Windows.Controls; 3 | 4 | namespace Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests.Internal.Types 5 | { 6 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 7 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] 8 | internal class View : ContentControl 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.Unity.IntegrationTests/Internal/Types/ViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests.Internal.Types 4 | { 5 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 6 | [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] 7 | public class ViewModel 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.Unity.IntegrationTests/MvvmNavigation.Wpf.Unity.IntegrationTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;netcoreapp3.0 5 | false 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /code/test/MvvmNavigation.Wpf.Unity.IntegrationTests/ScenarioTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Windows.Controls; 3 | using Egor92.MvvmNavigation.Abstractions; 4 | using Egor92.MvvmNavigation.Tests.Common.Unity; 5 | using Egor92.MvvmNavigation.Unity; 6 | using Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests.Internal; 7 | using Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests.Internal.Types; 8 | using NUnit.Framework; 9 | using Unity; 10 | 11 | namespace Egor92.MvvmNavigation.Wpf.Unity.IntegrationTests 12 | { 13 | [TestFixture] 14 | [Apartment(ApartmentState.STA)] 15 | public class ScenarioTests 16 | { 17 | private UnityContainer _unityContainer; 18 | 19 | [SetUp] 20 | public void SetUp() 21 | { 22 | _unityContainer = new UnityContainer(); 23 | } 24 | 25 | [TearDown] 26 | public void TearDown() 27 | { 28 | _unityContainer.Dispose(); 29 | } 30 | 31 | [Test] 32 | public void RegisterNavigationManager_NavigationManagerIsRegistered() 33 | { 34 | //Arrange 35 | var frameControl = new ContentControl(); 36 | 37 | //Act 38 | _unityContainer.RegisterNavigationManager(frameControl); 39 | 40 | //Assert 41 | UnityAssert.IsRegistered(_unityContainer); 42 | } 43 | 44 | [Test] 45 | public void RegisterNavigationManager_INavigationManagerIsRegistered() 46 | { 47 | //Arrange 48 | var frameControl = new ContentControl(); 49 | 50 | //Act 51 | _unityContainer.RegisterNavigationManager(frameControl); 52 | 53 | //Assert 54 | UnityAssert.IsRegistered(_unityContainer); 55 | } 56 | 57 | [Test] 58 | public void RegisterNavigationManager_FrameControlIsNotContentControl_ThrowException() 59 | { 60 | //Arrange 61 | var frameControl = new object(); 62 | 63 | //Act 64 | void Action() 65 | { 66 | _unityContainer.RegisterNavigationManager(frameControl); 67 | } 68 | 69 | //Assert 70 | Assert.That(Action, ThrowsException.FrameControlIsNotOfFrameControlType(frameControl, typeof(ContentControl))); 71 | } 72 | 73 | [Test] 74 | public void RegisterNavigationManager_NavigationManagerCanBeResolved() 75 | { 76 | //Arrange 77 | var frameControl = new ContentControl(); 78 | 79 | //Act 80 | _unityContainer.RegisterNavigationManager(frameControl); 81 | 82 | //Assert 83 | UnityAssert.CanResolve(_unityContainer); 84 | } 85 | 86 | [Test] 87 | public void RegisterNavigationRule_CanNavigate() 88 | { 89 | //Arrange 90 | var navigationKey = "navigationKey"; 91 | var frameControl = new ContentControl(); 92 | _unityContainer.RegisterNavigationManager(frameControl); 93 | 94 | //Act 95 | _unityContainer.RegisterNavigationRule(navigationKey); 96 | var navigationManager = _unityContainer.Resolve(); 97 | navigationManager.Navigate(navigationKey); 98 | 99 | //Assert 100 | Assert.That(frameControl.Content, Is.TypeOf()); 101 | Assert.That(((View)frameControl.Content).DataContext, Is.TypeOf()); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /samples/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Egor92 4 | Egor92 5 | $(Company)™ 6 | 7 | 8 | 9 | false 10 | none 11 | true 12 | 13 | 14 | 15 | true 16 | full 17 | false 18 | DEBUG;TRACE 19 | 20 | 21 | -------------------------------------------------------------------------------- /samples/MvvmNavigation.Samples.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29503.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{C2E400D5-6E0C-4B70-A144-60E0F6F9D5DF}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SinglePageApp", "SinglePageApp\SinglePageApp.csproj", "{6B865561-25C5-4192-B1C8-60E89864BA6F}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{86DDB864-BCB3-407C-B276-34766F27EB27}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestaurantApp", "RestaurantApp\RestaurantApp.csproj", "{C7525398-2898-4AAD-93FA-2888A3A64CDC}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWithUnity", "SampleWithUnity\SampleWithUnity.csproj", "{9E291E01-9EA6-4BE9-9944-A2934B864C03}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Common", "Samples.Common\Samples.Common.csproj", "{A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Debug|x86 = Debug|x86 22 | Release|Any CPU = Release|Any CPU 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Debug|x86.ActiveCfg = Debug|Any CPU 29 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Debug|x86.Build.0 = Debug|Any CPU 30 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Release|x86.ActiveCfg = Release|Any CPU 33 | {6B865561-25C5-4192-B1C8-60E89864BA6F}.Release|x86.Build.0 = Release|Any CPU 34 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Debug|x86.Build.0 = Debug|Any CPU 38 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Release|x86.ActiveCfg = Release|Any CPU 41 | {C7525398-2898-4AAD-93FA-2888A3A64CDC}.Release|x86.Build.0 = Release|Any CPU 42 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Debug|x86.ActiveCfg = Debug|Any CPU 45 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Debug|x86.Build.0 = Debug|Any CPU 46 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Release|Any CPU.Build.0 = Release|Any CPU 48 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Release|x86.ActiveCfg = Release|Any CPU 49 | {9E291E01-9EA6-4BE9-9944-A2934B864C03}.Release|x86.Build.0 = Release|Any CPU 50 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Debug|x86.ActiveCfg = Debug|Any CPU 53 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Debug|x86.Build.0 = Debug|Any CPU 54 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Release|Any CPU.ActiveCfg = Release|Any CPU 55 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Release|Any CPU.Build.0 = Release|Any CPU 56 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Release|x86.ActiveCfg = Release|Any CPU 57 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA}.Release|x86.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(NestedProjects) = preSolution 63 | {6B865561-25C5-4192-B1C8-60E89864BA6F} = {C2E400D5-6E0C-4B70-A144-60E0F6F9D5DF} 64 | {C7525398-2898-4AAD-93FA-2888A3A64CDC} = {C2E400D5-6E0C-4B70-A144-60E0F6F9D5DF} 65 | {9E291E01-9EA6-4BE9-9944-A2934B864C03} = {C2E400D5-6E0C-4B70-A144-60E0F6F9D5DF} 66 | {A7AD78CE-EAE2-44A2-87A5-E073E1F031BA} = {86DDB864-BCB3-407C-B276-34766F27EB27} 67 | EndGlobalSection 68 | GlobalSection(ExtensibilityGlobals) = postSolution 69 | SolutionGuid = {136C6A0F-93AC-4370-BA63-796C63800FAB} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /samples/RestaurantApp/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/RestaurantApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using Egor92.MvvmNavigation; 3 | using RestaurantApp.Constants; 4 | using RestaurantApp.Infrastructure.Implementations; 5 | using RestaurantApp.ViewModels; 6 | using RestaurantApp.Views; 7 | 8 | namespace RestaurantApp 9 | { 10 | public partial class App : Application 11 | { 12 | protected override void OnStartup(StartupEventArgs e) 13 | { 14 | var window = new MainWindow(); 15 | var navigationManager = new NavigationManager(window.FrameContent); 16 | 17 | var dialogManager = new DialogManager(); 18 | 19 | var viewModel = new MainWindowViewModel(navigationManager); 20 | window.DataContext = viewModel; 21 | 22 | navigationManager.Register(NavigationKeys.FoodSelection, () => new FoodSelectionViewModel(navigationManager, dialogManager)); 23 | navigationManager.Register(NavigationKeys.FoodCooking, () => new FoodCookingViewModel(navigationManager, dialogManager)); 24 | 25 | window.Show(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Constants/NavigationKeys.cs: -------------------------------------------------------------------------------- 1 | namespace RestaurantApp.Constants 2 | { 3 | public static class NavigationKeys 4 | { 5 | public const string FoodSelection = @"FoodSelection"; 6 | public const string FoodCooking = @"FoodCooking"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/RestaurantApp/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /samples/RestaurantApp/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 12 | 13 | 14 | 15 | 16 | A comma-separated list of error codes that can be safely ignored in assembly verification. 17 | 18 | 19 | 20 | 21 | 'false' to turn off automatic generation of the XML Schema file. 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Infrastructure/Abstractions/IDialogManager.cs: -------------------------------------------------------------------------------- 1 | namespace RestaurantApp.Infrastructure.Abstractions 2 | { 3 | public interface IDialogManager 4 | { 5 | void ShowMessage(string message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Infrastructure/Implementations/DialogManager.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using RestaurantApp.Infrastructure.Abstractions; 3 | 4 | namespace RestaurantApp.Infrastructure.Implementations 5 | { 6 | public class DialogManager : IDialogManager 7 | { 8 | public void ShowMessage(string message) 9 | { 10 | MessageBox.Show(message); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Models/Food.cs: -------------------------------------------------------------------------------- 1 | namespace RestaurantApp.Models 2 | { 3 | public class Food 4 | { 5 | public Food(string name, double price) 6 | { 7 | Name = name; 8 | Price = price; 9 | } 10 | 11 | public string Name { get; private set; } 12 | 13 | public double Price { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /samples/RestaurantApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // Setting ComVisible to false makes the types in this assembly not visible 8 | // to COM components. If you need to access a type in this assembly from 9 | // COM, set the ComVisible attribute to true on that type. 10 | [assembly: ComVisible(false)] 11 | 12 | //In order to begin building localizable applications, set 13 | //CultureYouAreCodingWith in your .csproj file 14 | //inside a . For example, if you are using US english 15 | //in your source files, set the to en-US. Then uncomment 16 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 17 | //the line below to match the UICulture setting in the project file. 18 | 19 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 20 | 21 | 22 | [assembly: ThemeInfo( 23 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 24 | //(used if a resource is not found in the page, 25 | // or application resource dictionaries) 26 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 27 | //(used if a resource is not found in the page, 28 | // app, or any theme specific resource dictionaries) 29 | )] 30 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace RestaurantApp.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RestaurantApp.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace RestaurantApp.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /samples/RestaurantApp/RestaurantApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net8.0-windows 4 | WinExe 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /samples/RestaurantApp/ViewModels/FoodCookingViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using Egor92.MvvmNavigation.Abstractions; 4 | using ReactiveUI; 5 | using ReactiveUI.Fody.Helpers; 6 | using RestaurantApp.Constants; 7 | using RestaurantApp.Infrastructure.Implementations; 8 | using RestaurantApp.Models; 9 | 10 | namespace RestaurantApp.ViewModels 11 | { 12 | public class FoodCookingViewModel(INavigationManager navigationManager, DialogManager dialogManager) 13 | : ReactiveObject, IAsyncNavigatedToAware 14 | { 15 | [Reactive] 16 | public Food Food { get; set; } 17 | 18 | [Reactive] 19 | public int CookingProgress { get; set; } 20 | 21 | #region Implementation of INavigationAware 22 | 23 | public async Task OnNavigatedToAsync(object arg, CancellationToken token = default) 24 | { 25 | Food = (Food)arg; 26 | 27 | for (int i = 0; i <= 100; i++) 28 | { 29 | CookingProgress = i; 30 | await Task.Delay(50, token); 31 | } 32 | 33 | dialogManager.ShowMessage($"Your dish is ready. Please sit down and enjoy your {Food.Name}."); 34 | navigationManager.Navigate(NavigationKeys.FoodSelection); 35 | } 36 | 37 | #endregion 38 | } 39 | } -------------------------------------------------------------------------------- /samples/RestaurantApp/ViewModels/FoodSelectionViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reactive.Linq; 4 | using System.Windows.Input; 5 | using Egor92.MvvmNavigation.Abstractions; 6 | using ReactiveUI; 7 | using ReactiveUI.Fody.Helpers; 8 | using RestaurantApp.Constants; 9 | using RestaurantApp.Infrastructure.Implementations; 10 | using RestaurantApp.Models; 11 | 12 | namespace RestaurantApp.ViewModels 13 | { 14 | public class FoodSelectionViewModel(INavigationManager navigationManager, DialogManager dialogManager) 15 | : ReactiveObject, INavigatedToAware 16 | { 17 | [Reactive] 18 | public Food[] Foods { get; set; } 19 | 20 | [Reactive] 21 | public Food SelectedFood { get; set; } 22 | 23 | #region CookFoodCommand 24 | 25 | private ICommand _cookFoodCommand; 26 | 27 | public ICommand CookFoodCommand => _cookFoodCommand ??= ReactiveCommand.Create(CookFood, WhenCanCookFoodChanged()); 28 | 29 | private IObservable WhenCanCookFoodChanged() 30 | { 31 | return this.ObservableForProperty(x => x.SelectedFood) 32 | .Select(x => x.Value != null); 33 | } 34 | 35 | private void CookFood() 36 | { 37 | dialogManager.ShowMessage($"Your order '{SelectedFood.Name}' has been sent to the chef."); 38 | navigationManager.Navigate(NavigationKeys.FoodCooking, SelectedFood); 39 | } 40 | 41 | #endregion 42 | 43 | #region Implementation of INavigationAware 44 | 45 | public void OnNavigatedTo(object arg) 46 | { 47 | Foods = new Food[] 48 | { 49 | new Food("Borscht", 70), 50 | new Food("Shchi", 60), 51 | new Food("Potatoes", 30), 52 | new Food("Rice", 25), 53 | new Food("Pasta", 20), 54 | new Food("Olivier Salad", 45), 55 | new Food("Tea", 15), 56 | new Food("Compote", 20) 57 | }; 58 | 59 | SelectedFood = Foods.FirstOrDefault(); 60 | } 61 | 62 | #endregion 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /samples/RestaurantApp/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Input; 2 | using Egor92.MvvmNavigation.Abstractions; 3 | using ReactiveUI; 4 | using RestaurantApp.Constants; 5 | 6 | namespace RestaurantApp.ViewModels 7 | { 8 | public class MainWindowViewModel(INavigationManager navigationManager) : ReactiveObject 9 | { 10 | #region ShowFoodSelectionCommand 11 | 12 | private ICommand _showFoodSelectionCommand; 13 | 14 | public ICommand ShowFoodSelectionCommand => _showFoodSelectionCommand ??= ReactiveCommand.Create(ShowFoodSelection); 15 | 16 | private async void ShowFoodSelection() 17 | { 18 | await navigationManager.NavigateAsync(NavigationKeys.FoodSelection); 19 | } 20 | 21 | #endregion 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Views/FoodCookingView.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Views/FoodCookingView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace RestaurantApp.Views 4 | { 5 | public partial class FoodCookingView : UserControl 6 | { 7 | public FoodCookingView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Views/FoodSelectionView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Views/FoodSelectionView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace RestaurantApp.Views 4 | { 5 | public partial class FoodSelectionView : UserControl 6 | { 7 | public FoodSelectionView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/RestaurantApp/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 18 | 19 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /samples/SinglePageApp/Views/ParameterSelectionView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace SinglePageApp.Views 4 | { 5 | public partial class ParameterSelectionView : UserControl 6 | { 7 | public ParameterSelectionView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/SinglePageApp/Views/WelcomeView.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 25 | 29 |