├── .gitignore ├── Data ├── .NETFramework4.5 │ ├── Contracts │ │ ├── Microsoft.VisualBasic.Compatibility.Contracts.dll │ │ ├── Microsoft.VisualBasic.Contracts.dll │ │ ├── PresentationCore.Contracts.dll │ │ ├── PresentationFramework.Contracts.dll │ │ ├── System.ComponentModel.Composition.Contracts.dll │ │ ├── System.Configuration.Contracts.dll │ │ ├── System.Configuration.Install.Contracts.dll │ │ ├── System.Contracts.dll │ │ ├── System.Core.Contracts.dll │ │ ├── System.Data.Contracts.dll │ │ ├── System.Data.Services.Contracts.dll │ │ ├── System.DirectoryServices.Contracts.dll │ │ ├── System.Drawing.Contracts.dll │ │ ├── System.Numerics.Contracts.dll │ │ ├── System.Runtime.Caching.Contracts.dll │ │ ├── System.Security.Contracts.dll │ │ ├── System.ServiceModel.Contracts.dll │ │ ├── System.ServiceProcess.Contracts.dll │ │ ├── System.Web.ApplicationServices.Contracts.dll │ │ ├── System.Web.Contracts.dll │ │ ├── System.Windows.Forms.Contracts.dll │ │ ├── System.Xml.Contracts.dll │ │ ├── System.Xml.Linq.Contracts.dll │ │ ├── WindowsBase.Contracts.dll │ │ └── mscorlib.Contracts.dll │ └── Libraries │ │ ├── Microsoft.VisualBasic.Compatibility.dll │ │ ├── Microsoft.VisualBasic.dll │ │ ├── PresentationCore.dll │ │ ├── PresentationFramework.dll │ │ ├── System.ComponentModel.Composition.dll │ │ ├── System.Configuration.Install.dll │ │ ├── System.Configuration.dll │ │ ├── System.Core.dll │ │ ├── System.Data.Services.dll │ │ ├── System.Data.dll │ │ ├── System.DirectoryServices.dll │ │ ├── System.Drawing.dll │ │ ├── System.Numerics.dll │ │ ├── System.Runtime.Caching.dll │ │ ├── System.Security.dll │ │ ├── System.ServiceModel.dll │ │ ├── System.ServiceProcess.dll │ │ ├── System.Web.ApplicationServices.dll │ │ ├── System.Web.dll │ │ ├── System.Windows.Forms.dll │ │ ├── System.Xml.Linq.dll │ │ ├── System.Xml.dll │ │ ├── System.dll │ │ ├── WindowsBase.dll │ │ └── mscorlib.dll ├── AdventureWorks.bacpac ├── AdventureWorks_Data.mdf └── AdventureWorks_Log.ldf ├── LICENSE ├── Tools ├── Analyzers.ruleset ├── CodeAnalysis.ruleset ├── CodeAnalysisDictionary.xml ├── CommonAssemblyInfo.cs ├── CommonAssemblyInfo.fs ├── Key.snk └── VS2017.gitconfig ├── Tutorial.Android ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Tutorial.Android.csproj ├── app.config └── packages.config ├── Tutorial.Console.Core ├── Program.cs └── Tutorial.Console.Core.csproj ├── Tutorial.Console.Net ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── Tutorial.Console.Net.csproj ├── Tutorial.Core ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx └── Tutorial.Core.csproj ├── Tutorial.Net ├── App.config ├── LinqToSql │ ├── Database.cs │ ├── Relationship.cs │ ├── TableHelper.cs │ └── Tables.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Tutorial.Net.csproj └── packages.config ├── Tutorial.Shared ├── ActionFunc.Compose.cs ├── Blog.htm ├── BlogOriginal.htm ├── CategoryTheory │ ├── Bifunctor.cs │ ├── Category.cs │ ├── Functions.cs │ ├── Functor.cs │ ├── Monad.Cps.cs │ ├── Monad.Exception.cs │ ├── Monad.IO.cs │ ├── Monad.Reader.cs │ ├── Monad.SelectMany.cs │ ├── Monad.State.cs │ ├── Monad.Writer.cs │ ├── Monad.cs │ ├── Monoid.cs │ ├── MonoidalCategory.cs │ ├── MonoidalFunctor.cs │ ├── NaturalTransformation.cs │ ├── Optional`1.cs │ └── Performance.cs ├── Functional │ ├── AsynchronousFunction.cs │ ├── Composition.Linq.cs │ ├── Composition.cs │ ├── CovarianceContravariance.Func.il │ ├── CovarianceContravariance.cs │ ├── Delegate.cs │ ├── ExceptionFilter.il │ ├── FirstClassFunction.Curry.cs │ ├── FirstClassFunction.cs │ ├── Immutability.cs │ ├── InputOutput.OptionalParameter.il │ ├── InputOutput.cs │ ├── Lambda.AnonymousFunction.cs │ ├── Lambda.ExpressionTree.cs │ ├── Lambda.ExpressionTree.txt │ ├── LocalFunction.cs │ ├── NamedFunction.Data.il │ ├── NamedFunction.cs │ ├── PatternMatching.cs │ ├── PurreFunction.cs │ └── TraceExtensions.cs ├── GettingStarted │ ├── Basics.cs │ ├── Overview.Declarative.cs │ ├── Overview.Functional.cs │ ├── Overview.Linq.LinqToJson.json │ ├── Overview.Linq.LinqToNoSql.All.json │ ├── Overview.Linq.LinqToNoSql.cs │ ├── Overview.Linq.LinqToNoSql.json │ ├── Overview.Linq.LinqToNoSql.sql │ ├── Overview.Linq.LinqToObjects.cs │ ├── Overview.Linq.LinqToXml.xml │ ├── Overview.Linq.NetFX.cs │ ├── Overview.Linq.cs │ └── Overview.ObjectOriented.cs ├── LambdaCalculus │ ├── ChurchAggregateList.Generic.cs │ ├── ChurchAggregateList.cs │ ├── ChurchBoolean.Generic.cs │ ├── ChurchBoolean.cs │ ├── ChurchEncoding.cs │ ├── ChurchList.cs │ ├── ChurchNestedList.cs │ ├── ChurchNumeral.Generic.cs │ ├── ChurchNumeral.cs │ ├── ChurchSignedNumeral.cs │ ├── ChurchTuple.cs │ ├── Combinators.Bckw.cs │ ├── Combinators.FixedPoint.cs │ ├── Combinators.Iota.cs │ ├── Combinators.Omega.cs │ ├── Combinators.Ski.cs │ ├── Equivalence.cs │ ├── Expressions.cs │ ├── Functions.cs │ ├── Lambda.txt │ ├── SkiCompiler.cs │ └── SkiCompiler.hs ├── LinqToEntities │ ├── AdventureWorks.Trim.sql │ ├── Loading.cs │ ├── Loading.sql │ ├── Manipulation.Changes.cs │ ├── Manipulation.Changes.sql │ ├── Manipulation.Concurrency.cs │ ├── Manipulation.Concurrency.sql │ ├── Manipulation.Tracking.cs │ ├── Manipulation.Transactions.cs │ ├── Manipulation.UnitOfWork.cs │ ├── Modeling.ConnectionStrings.cs │ ├── Modeling.Database.cs │ ├── Modeling.Database.sql │ ├── Modeling.Inheritance.cs │ ├── Modeling.Inheritance.sql │ ├── Modeling.Mapping.sql │ ├── Modeling.Relationship.cs │ ├── Modeling.Tables.cs │ ├── Modeling.Tables.sql │ ├── Modeling.Views.cs │ ├── Modeling.Views.sql │ ├── Performance.cs │ ├── Performance.sql │ ├── QueryExpressions.cs │ ├── QueryMethods.cs │ ├── QueryTracing.cs │ ├── QueryTracing.sql │ ├── RemoteQuery.cs │ ├── RemoteQuery.sql │ ├── Translation.cs │ └── Translation.txt ├── LinqToObjects │ ├── DeferredExecution.cs │ ├── Enumerable.cs │ ├── EnumerableExtensions.Interactive.cs │ ├── EnumerableExtensions.Linq.cs │ ├── EnumerableExtensions.Order.cs │ ├── EnumerableX.Compare.cs │ ├── EnumerableX.List.cs │ ├── EnumerableX.cs │ ├── Generator.cs │ ├── Grouping`2.cs │ ├── HashSet`1.cs │ ├── IteratorPattern.cs │ ├── Lookup`1.cs │ ├── QueryExpressions.cs │ ├── QueryMethods.Interactive.cs │ ├── QueryMethods.Linq.cs │ ├── QueryMethods.cs │ └── TraceExtensions.cs ├── LinqToXml │ ├── AspNetRss.xml │ ├── AspNetRss.xsd │ ├── FlickrRss.dc.xsd │ ├── FlickrRss.flickr.xsd │ ├── FlickrRss.media.xsd │ ├── FlickrRss.xml │ ├── FlickrRss.xsd │ ├── Manipulation.cs │ ├── Modeling.cs │ ├── QueryMethods.cs │ └── XExtensions.cs ├── NetStandard.cs ├── ParallelLinq │ ├── Partitioning.cs │ ├── Partitioning.txt │ ├── Performance.cs │ ├── QueryMethods.cs │ └── Visualizer.cs ├── Tutorial.Shared.projitems └── Tutorial.Shared.shproj ├── Tutorial.Tests.Android ├── MainActivity.cs ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── Resource.Designer.cs │ ├── drawable │ │ └── Icon.png │ └── values │ │ └── Strings.xml ├── Tests.cs ├── Tutorial.Tests.Android.csproj ├── app.config └── packages.config ├── Tutorial.Tests.Core ├── Tutorial.Tests.Core.csproj └── app.json ├── Tutorial.Tests.External.Core └── Tutorial.Tests.External.Core.csproj ├── Tutorial.Tests.External.Net ├── Properties │ └── AssemblyInfo.cs ├── Tutorial.Tests.External.Net.csproj ├── app.config └── packages.config ├── Tutorial.Tests.External.Shared ├── ActiveIssueAttribute.cs ├── LinqToObjects │ ├── AggregateTests.cs │ ├── AllTests.cs │ ├── AnyTests.cs │ ├── AppendPrependTests.cs │ ├── AsEnumerableTests.cs │ ├── AverageTests.cs │ ├── CastTests.cs │ ├── ConcatTests.cs │ ├── ConsistencyTests.cs │ ├── ContainsTests.cs │ ├── CountTests.cs │ ├── DefaultIfEmptyTests.cs │ ├── DistinctTests.cs │ ├── ElementAtOrDefaultTests.cs │ ├── ElementAtTests.cs │ ├── EmptyEnumerable.cs │ ├── EmptyPartitionTests.cs │ ├── EnumerableDebugViewTests.cs │ ├── EnumerableTests.cs │ ├── ExceptTests.cs │ ├── FirstOrDefaultTests.cs │ ├── FirstTests.cs │ ├── GroupByTests.cs │ ├── GroupJoinTests.cs │ ├── IntersectTests.cs │ ├── JoinTests.cs │ ├── LastOrDefaultTests.cs │ ├── LastTests.cs │ ├── LongCountTests.cs │ ├── MaxTests.cs │ ├── MinTests.cs │ ├── OfTypeTests.cs │ ├── OrderByDescendingTests.cs │ ├── OrderByTests.cs │ ├── OrderedSubsetting.cs │ ├── RangeTests.cs │ ├── RepeatTests.cs │ ├── ReverseTests.cs │ ├── SelectManyTests.cs │ ├── SelectTests.cs │ ├── SequenceEqualTests.cs │ ├── ShortCircuitingTests.cs │ ├── Shuffler.cs │ ├── SingleOrDefaultTests.cs │ ├── SingleTests.cs │ ├── SkipTests.cs │ ├── SkipWhileTests.cs │ ├── SumTests.cs │ ├── TakeTests.cs │ ├── TakeWhileTests.cs │ ├── ThenByDescendingTests.cs │ ├── ThenByTests.cs │ ├── ToArrayTests.cs │ ├── ToDictionaryTests.cs │ ├── ToListTests.cs │ ├── ToLookupTests.cs │ ├── UnionTests.cs │ ├── WhereTests.cs │ └── ZipTests.cs ├── TestPlatforms.cs ├── Tutorial.Tests.External.Shared.projitems └── Tutorial.Tests.External.Shared.shproj ├── Tutorial.Tests.Net ├── Properties │ └── AssemblyInfo.cs ├── Tutorial.Tests.Net.csproj ├── app.config └── packages.config ├── Tutorial.Tests.Shared ├── CategoryTheory │ ├── ApplicativeTests.cs │ ├── BifunctorTests.cs │ ├── CategoryTests.cs │ ├── EnumerableExtensionsTests.cs │ ├── FunctorTests.cs │ ├── LinqHelper.cs │ ├── MonadTests.cs │ ├── MonoidTests.cs │ ├── NaturalTransformationsTests.cs │ └── PerformanceTests.cs ├── Functional │ ├── AsynchronousFunctionTests.cs │ ├── CovarianceContravarianceTests.cs │ ├── DelegateTests.cs │ ├── ImmutabilityTests.cs │ ├── InputOutputTests.cs │ ├── LambdaTests.cs │ └── LocalFunctionTests.cs ├── GettingStarted │ ├── BasicsTests.cs │ ├── OverviewTests.Contact.cs │ └── OverviewTests.cs ├── Lambda │ ├── ChurchAggregateListTests.cs │ ├── ChurchAggregateListWrapperTests.cs │ ├── ChurchBooleanTests.cs │ ├── ChurchListTests.cs │ ├── ChurchNestedListTests.cs │ ├── ChurchNumeralTests.cs │ ├── ChurchNumeralWrapperTests.cs │ ├── ChurchPredicateTests.cs │ ├── ChurchSignedNumeralTests.cs │ ├── ChurchTupleTests.cs │ ├── CombinatorTests.FixedPoint.cs │ ├── CombinatorTests.Iota.cs │ └── CombinatorsTests.Ski.cs ├── LinqToEntities │ ├── LoadingTests.cs │ ├── Manipulation.ChangesTests.cs │ ├── Manipulation.ConcurrencyTests.cs │ ├── Manipulation.SaveChangesTests.cs │ ├── Manipulation.TransactionHelper.cs │ ├── Manipulation.TransactionTests.cs │ ├── Modeling.ConnectionStringsTests.cs │ ├── Modeling.DatabaseTests.cs │ ├── PerformanceTests.cs │ ├── QueryExpressionTests.cs │ ├── QueryMethodsTests.cs │ ├── QueryTracingTests.cs │ ├── RemoteQueryTests.cs │ └── TranslationTests.cs ├── LinqToObjects │ ├── DeferredExecutionTests.cs │ ├── EnumerableAssert.cs │ ├── EnumerableQueryMethodsTests.cs │ ├── EnumerableXTests.cs │ ├── IteratorPatternTests.cs │ ├── LinkedListSequenceTests.cs │ └── QueryMethodsTests.cs ├── LinqToXml │ ├── ManipulationTests.cs │ ├── ModelingTests.cs │ ├── QueryMethodsTests.cs │ ├── XExtensionsTests.XPath.cs │ └── XExtensionsTests.cs ├── MSTest.cs ├── ParallelLinq │ ├── PartitioningTests.cs │ ├── PerformanceTests.cs │ └── QueryMethodsTests.cs ├── Tutorial.Tests.Shared.projitems └── Tutorial.Tests.Shared.shproj ├── Tutorial.Tests.Uwp ├── AppConfig.cs ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png ├── Package.appxmanifest ├── Properties │ ├── AssemblyInfo.cs │ └── UnitTestApp.rd.xml ├── Tutorial.Tests.Uwp.csproj ├── UnitTestApp.xaml └── UnitTestApp.xaml.cs ├── Tutorial.Tests.iOS ├── AppDelegate.cs ├── Entitlements.plist ├── Info.plist ├── Main.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ ├── Default-568h@2x.png │ ├── Default.png │ └── Default@2x.png ├── Tests.cs ├── Tutorial.Tests.iOS.csproj ├── app.config └── packages.config ├── Tutorial.Uwp ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png ├── MainPage.xaml ├── MainPage.xaml.cs ├── Package.appxmanifest ├── Properties │ ├── AssemblyInfo.cs │ ├── Default.rd.xml │ ├── Resources.cs │ └── Resources.resw ├── ReadMe.txt └── Tutorial.Uwp.csproj ├── Tutorial.iOS ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Tutorial.iOS.csproj ├── any │ └── netstandard1.6 │ │ ├── FSharp.Core.optdata │ │ └── FSharp.Core.sigdata ├── app.config └── packages.config ├── Tutorial.sln ├── Tutorial.sln.DotSettings └── appveyor.yml /Data/.NETFramework4.5/Contracts/Microsoft.VisualBasic.Compatibility.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/Microsoft.VisualBasic.Compatibility.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/Microsoft.VisualBasic.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/Microsoft.VisualBasic.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/PresentationCore.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/PresentationCore.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/PresentationFramework.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/PresentationFramework.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.ComponentModel.Composition.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.ComponentModel.Composition.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Configuration.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Configuration.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Configuration.Install.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Configuration.Install.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Core.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Core.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Data.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Data.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Data.Services.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Data.Services.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.DirectoryServices.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.DirectoryServices.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Drawing.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Drawing.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Numerics.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Numerics.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Runtime.Caching.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Runtime.Caching.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Security.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Security.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.ServiceModel.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.ServiceModel.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.ServiceProcess.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.ServiceProcess.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Web.ApplicationServices.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Web.ApplicationServices.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Web.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Web.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Windows.Forms.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Windows.Forms.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Xml.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Xml.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/System.Xml.Linq.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/System.Xml.Linq.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/WindowsBase.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/WindowsBase.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Contracts/mscorlib.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Contracts/mscorlib.Contracts.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/Microsoft.VisualBasic.Compatibility.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/Microsoft.VisualBasic.Compatibility.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/Microsoft.VisualBasic.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/Microsoft.VisualBasic.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/PresentationCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/PresentationCore.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/PresentationFramework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/PresentationFramework.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.ComponentModel.Composition.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.ComponentModel.Composition.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Configuration.Install.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Configuration.Install.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Configuration.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Configuration.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Core.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Data.Services.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Data.Services.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Data.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Data.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.DirectoryServices.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.DirectoryServices.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Drawing.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Drawing.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Numerics.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Numerics.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Runtime.Caching.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Runtime.Caching.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Security.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Security.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.ServiceModel.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.ServiceModel.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.ServiceProcess.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.ServiceProcess.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Web.ApplicationServices.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Web.ApplicationServices.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Web.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Web.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Windows.Forms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Windows.Forms.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Xml.Linq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Xml.Linq.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.Xml.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.Xml.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/System.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/System.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/WindowsBase.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/WindowsBase.dll -------------------------------------------------------------------------------- /Data/.NETFramework4.5/Libraries/mscorlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/.NETFramework4.5/Libraries/mscorlib.dll -------------------------------------------------------------------------------- /Data/AdventureWorks.bacpac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/AdventureWorks.bacpac -------------------------------------------------------------------------------- /Data/AdventureWorks_Data.mdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/AdventureWorks_Data.mdf -------------------------------------------------------------------------------- /Data/AdventureWorks_Log.ldf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Data/AdventureWorks_Log.ldf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dixin Yan 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 | 23 | -------------------------------------------------------------------------------- /Tools/CodeAnalysis.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Tools/CodeAnalysisDictionary.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Dixin 6 | combinator 7 | combinators 8 | functor 9 | Mvc 10 | monoid 11 | Bckw 12 | uncurry 13 | contravariance 14 | memoize 15 | cpu 16 | awaitable 17 | awaiter 18 | retry 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Tools/CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Resources; 4 | #if NETFX || WINDOWS_UWP 5 | using System.Runtime.InteropServices; 6 | #endif 7 | 8 | [assembly: AssemblyDescription("Code examples for https://weblogs.asp.net/dixin/linq-via-csharp.")] 9 | [assembly: AssemblyCopyright("Dixin Yan https://weblogs.asp.net/dixin")] 10 | 11 | #if !NETSTANDARD && !NETCOREAPP 12 | [assembly: AssemblyVersion("1.0.0.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] 14 | [assembly: AssemblyCompany("Dixin Yan")] 15 | [assembly: AssemblyProduct("Tutorial")] 16 | #endif 17 | 18 | [assembly: CLSCompliant(false)] 19 | [assembly: NeutralResourcesLanguage("en-US")] 20 | 21 | #if NETFX || WINDOWS_UWP 22 | [assembly: ComVisible(false)] 23 | #endif 24 | -------------------------------------------------------------------------------- /Tools/CommonAssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Properties 2 | 3 | open System 4 | open System.Reflection 5 | open System.Resources 6 | open System.Runtime.InteropServices 7 | 8 | [] 9 | [] 10 | 11 | #if !NETSTANDARD2_0 && !NETCOREAPP2_0 12 | [] 13 | [] 14 | [] 15 | [] 16 | #endif 17 | 18 | [] 19 | [] 20 | 21 | #if NETFX || WINDOWS_UWP 22 | [] 23 | #endif 24 | 25 | do () -------------------------------------------------------------------------------- /Tools/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tools/Key.snk -------------------------------------------------------------------------------- /Tools/VS2017.gitconfig: -------------------------------------------------------------------------------- 1 | [diff] 2 | tool = vs2017 3 | [difftool] 4 | prompt = true 5 | [difftool "vs2015"] 6 | cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t 7 | keepbackup = false 8 | trustexistcode = true 9 | [merge] 10 | tool = vs2017 11 | [mergetool] 12 | prompt = true 13 | [mergetool "vs2015"] 14 | cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m 15 | keepbackup = false 16 | trustexistcode = true -------------------------------------------------------------------------------- /Tutorial.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyTitle("Tutorial.Android")] 5 | 6 | [assembly: InternalsVisibleTo("Tutorial.Tests.Android")] -------------------------------------------------------------------------------- /Tutorial.Console.Core/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Console 2 | { 3 | internal static class Program 4 | { 5 | private static void Main() { } 6 | } 7 | } -------------------------------------------------------------------------------- /Tutorial.Console.Core/Tutorial.Console.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net7.0 6 | Tutorial.Console 7 | 8 | Dixin Yan 9 | Tutorial 10 | 11 | 12 | 13 | latest 14 | 15 | 16 | 17 | latest 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Tutorial.Console.Net/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Console 2 | { 3 | internal static class Program 4 | { 5 | private static void Main() { } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Tutorial.Console.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Console.Net")] 4 | -------------------------------------------------------------------------------- /Tutorial.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Tutorial.Console.Core")] 4 | [assembly: InternalsVisibleTo("Tutorial.Core.FSharp")] 5 | [assembly: InternalsVisibleTo("Tutorial.Tests.Core")] 6 | [assembly: InternalsVisibleTo("Tutorial.Tests.External.Core")] 7 | -------------------------------------------------------------------------------- /Tutorial.Core/Tutorial.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | Tutorial 6 | Dixin Yan 7 | Tutorial 8 | latest 9 | 10 | 11 | ..\Tools\Analyzers.ruleset 12 | 1701;1702;219;659;1974;414;169;8321;8123;168 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | all 27 | runtime; build; native; contentfiles; analyzers; buildtransitive 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | all 36 | runtime; build; native; contentfiles; analyzers; buildtransitive 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | True 47 | True 48 | Resources.resx 49 | 50 | 51 | 52 | 53 | 54 | ResXFileCodeGenerator 55 | Resources.Designer.cs 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Tutorial.Net/LinqToSql/Database.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToSql 2 | { 3 | using System.Data.Linq; 4 | using System.Data.Linq.Mapping; 5 | using Tutorial.LinqToEntities; 6 | 7 | [Database(Name = "[AdventureWorks]")] 8 | public partial class AdventureWorks : DataContext 9 | { 10 | public AdventureWorks() 11 | : base(ConnectionStrings.AdventureWorks) { } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tutorial.Net/LinqToSql/Tables.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToSql 2 | { 3 | using System; 4 | using System.Data.Linq; 5 | using System.Data.Linq.Mapping; 6 | 7 | [Table(Name = "[Production].[ProductCategory]")] 8 | public partial class ProductCategory 9 | { 10 | [Column(DbType = "int NOT NULL IDENTITY", 11 | IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 12 | public int ProductCategoryID { get; set; } 13 | 14 | [Column(DbType = "nvarchar(50) NOT NULL", UpdateCheck = UpdateCheck.Never)] 15 | public string Name { get; set; } 16 | 17 | // Other columns are ignored. 18 | } 19 | 20 | [Table(Name = "[Production].[ProductSubcategory]")] 21 | public partial class ProductSubcategory 22 | { 23 | [Column(DbType = "int NOT NULL IDENTITY", 24 | IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 25 | public int ProductSubcategoryID { get; set; } 26 | 27 | [Column(DbType = "nvarchar(50) NOT NULL", UpdateCheck = UpdateCheck.Never)] 28 | public string Name { get; set; } 29 | 30 | // public int ProductCategoryID { get; set; } 31 | } 32 | 33 | [Table(Name = "[Production].[Product]")] 34 | public partial class Product 35 | { 36 | [Column(DbType = "int NOT NULL IDENTITY", 37 | IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 38 | public int ProductID { get; set; } 39 | 40 | [Column(DbType = "nvarchar(50) NOT NULL", UpdateCheck = UpdateCheck.Never)] 41 | public string Name { get; set; } 42 | 43 | [Column(DbType = "money NOT NULL", UpdateCheck = UpdateCheck.Never)] 44 | public decimal ListPrice { get; set; } 45 | 46 | // public int? ProductSubcategoryID { get; set; } 47 | 48 | // public string Style { get; set; } 49 | } 50 | 51 | [Table(Name = "[Production].[ProductPhoto]")] 52 | public partial class ProductPhoto 53 | { 54 | [Column(DbType = "int NOT NULL IDENTITY", UpdateCheck = UpdateCheck.Never, 55 | IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 56 | public int ProductPhotoID { get; set; } 57 | 58 | [Column(DbType = "nvarchar(50)", UpdateCheck = UpdateCheck.Never)] 59 | public string LargePhotoFileName { get; set; } 60 | 61 | [Column(DbType = "datetime NOT NULL", UpdateCheck = UpdateCheck.Always)] 62 | public DateTime ModifiedDate { get; set; } 63 | } 64 | 65 | public partial class AdventureWorks 66 | { 67 | public Table ProductCategories => this.GetTable(); 68 | 69 | public Table ProductSubcategories => this.GetTable(); 70 | 71 | public Table Products => this.GetTable(); 72 | 73 | public Table ProductPhotos => this.GetTable(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Tutorial.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyTitle("Tutorial.Net")] 5 | 6 | [assembly: InternalsVisibleTo("Tutorial.Console.Net")] 7 | [assembly: InternalsVisibleTo("Tutorial.FSharp")] 8 | [assembly: InternalsVisibleTo("Tutorial.Tests.Net")] 9 | [assembly: InternalsVisibleTo("Tutorial.Tests.External.Net")] 10 | -------------------------------------------------------------------------------- /Tutorial.Shared/ActionFunc.Compose.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial 2 | { 3 | using System; 4 | 5 | public static partial class FuncExtensions 6 | { 7 | public static Func o( // After. 8 | this Func function2, Func function1) => 9 | value => function2(function1(value)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tutorial.Shared/BlogOriginal.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Shared/BlogOriginal.htm -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/Bifunctor.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | using System; 4 | 5 | #if DEMO 6 | // Cannot be compiled. 7 | public interface IBifunctor> where TBifunctor<,> : IFunctor> 8 | { 9 | Func, TBifunctor> Select( 10 | Func selector1, Func selector2); 11 | } 12 | #endif 13 | 14 | public static partial class ValueTupleExtensions // ValueTuple : IBifunctor> 15 | { 16 | // Bifunctor Select: (TSource1 -> TResult1, TSource2 -> TResult2) -> (ValueTuple -> ValueTuple). 17 | public static Func, ValueTuple> Select( 18 | Func selector1, Func selector2) => source => 19 | Select(source, selector1, selector2); 20 | 21 | // LINQ-like Select: (ValueTuple, TSource1 -> TResult1, TSource2 -> TResult2) -> ValueTuple). 22 | public static ValueTuple Select( 23 | this ValueTuple source, 24 | Func selector1, 25 | Func selector2) => 26 | (selector1(source.Item1), selector2(source.Item2)); 27 | } 28 | 29 | public class Lazy 30 | { 31 | private readonly Lazy<(T1, T2)> lazy; 32 | 33 | public Lazy(Func<(T1, T2)> factory) => this.lazy = new Lazy<(T1, T2)>(factory); 34 | 35 | public T1 Value1 => this.lazy.Value.Item1; 36 | 37 | public T2 Value2 => this.lazy.Value.Item2; 38 | 39 | public override string ToString() => this.lazy.Value.ToString(); 40 | } 41 | 42 | public static partial class LazyExtensions // Lazy : IBifunctor> 43 | { 44 | // Bifunctor Select: (TSource1 -> TResult1, TSource2 -> TResult2) -> (Lazy -> Lazy). 45 | public static Func, Lazy> Select( 46 | Func selector1, Func selector2) => source => 47 | Select(source, selector1, selector2); 48 | 49 | // LINQ-like Select: (Lazy, TSource1 -> TResult1, TSource2 -> TResult2) -> Lazy). 50 | public static Lazy Select( 51 | this Lazy source, 52 | Func selector1, 53 | Func selector2) => 54 | new Lazy(() => (selector1(source.Value1), selector2(source.Value2))); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/Category.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | 8 | public interface ICategory 9 | { 10 | static abstract IEnumerable Objects { get; } 11 | 12 | static abstract TMorphism Compose(TMorphism morphism2, TMorphism morphism1); 13 | 14 | static abstract TMorphism Id(TObject @object); 15 | } 16 | 17 | public class Int32Category : ICategory 18 | { 19 | public static IEnumerable Objects 20 | { 21 | get 22 | { 23 | for (int int32 = int.MinValue; int32 <= int.MaxValue; int32++) 24 | { 25 | yield return int32; 26 | } 27 | } 28 | } 29 | 30 | public static BinaryExpression Compose(BinaryExpression morphism2, BinaryExpression morphism1) => 31 | Expression.LessThanOrEqual(morphism2.Left, morphism1.Right); // (Y <= Z) ∘ (X <= Y) => X <= Z. 32 | 33 | public static BinaryExpression Id(int @object) => 34 | Expression.GreaterThanOrEqual(Expression.Constant(@object), Expression.Constant(@object)); // X <= X. 35 | } 36 | 37 | #if DEMO 38 | public static partial class FuncExtensions 39 | { 40 | public static Func o( // After. 41 | this Func function2, Func function1) => 42 | value => function2(function1(value)); 43 | } 44 | #endif 45 | 46 | public partial class DotNetCategory : ICategory 47 | { 48 | public static IEnumerable Objects => AppDomain.CurrentDomain.GetAssemblies() 49 | .SelectMany(assembly => assembly.ExportedTypes); 50 | 51 | public static Delegate Compose(Delegate morphism2, Delegate morphism1) => 52 | // return (Func)Functions.Compose( 53 | // (Func)morphism2, (Func)morphism1); 54 | (Delegate)typeof(Tutorial.FuncExtensions).GetMethod(nameof(Tutorial.FuncExtensions.o)) 55 | .MakeGenericMethod( // TSource, TMiddle, TResult. 56 | morphism1.Method.GetParameters().Single().ParameterType, 57 | morphism1.Method.ReturnType, 58 | morphism2.Method.ReturnType) 59 | .Invoke(null, new object[] { morphism2, morphism1 }); 60 | 61 | public static Delegate Id(Type @object) => // Functions.Id 62 | typeof(Functions).GetMethod(nameof(Functions.Id)).MakeGenericMethod(@object) 63 | .CreateDelegate(typeof(Func<,>).MakeGenericType(@object, @object)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/Functions.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | public static partial class Functions 4 | { 5 | #if DEMO 6 | public static Func o( 7 | this Func function2, Func function1) => 8 | value => function2(function1(value)); 9 | #endif 10 | 11 | public static TSource Id(TSource value) => value; 12 | } 13 | 14 | public static partial class Functions 15 | { 16 | public static TFalse False(TTrue @true, TFalse @false) => @false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/Monad.Reader.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | using Microsoft.FSharp.Core; 7 | 8 | // Reader: TEnvironment -> T 9 | public delegate T Reader(TEnvironment environment); 10 | 11 | public static partial class ReaderExtensions 12 | { 13 | // SelectMany: (Reader, TSource -> Reader, (TSource, TSelector) -> TResult) -> Reader 14 | public static Reader SelectMany( 15 | this Reader source, 16 | Func> selector, 17 | Func resultSelector) => 18 | environment => 19 | { 20 | TSource value = source(environment); 21 | return resultSelector(value, selector(value)(environment)); 22 | }; 23 | 24 | // Wrap: TSource -> Reader 25 | public static Reader Reader(this TSource value) => 26 | environment => value; 27 | 28 | // Select: (Reader, TSource -> TResult) -> Reader 29 | public static Reader Select( 30 | this Reader source, Func selector) => 31 | source.SelectMany(value => selector(value).Reader(), (value, result) => result); 32 | } 33 | 34 | internal interface IConfiguration { } 35 | 36 | public static partial class ReaderExtensions 37 | { 38 | private static Reader DownloadHtml(Uri uri) => 39 | configuration => default; 40 | 41 | private static Reader ConvertToWord(FileInfo htmlDocument, FileInfo template) => 42 | configuration => default; 43 | 44 | private static Reader UploadToOneDrive(FileInfo file) => 45 | configuration => default; 46 | 47 | internal static void Workflow(IConfiguration configuration, Uri uri, FileInfo template) 48 | { 49 | Reader query = 50 | from htmlDocument in DownloadHtml(uri) // Reader. 51 | from wordDocument in ConvertToWord(htmlDocument, template) // Reader. 52 | from unit in UploadToOneDrive(wordDocument) // Reader. 53 | select (htmlDocument, wordDocument); // Define query. 54 | (FileInfo, FileInfo) result = query(configuration); // Execute query. 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/MonoidalCategory.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | using System; 4 | 5 | using Microsoft.FSharp.Core; 6 | 7 | public interface IMonoidalCategory : ICategory, IMonoid { } 8 | 9 | public partial class DotNetCategory : IMonoidalCategory 10 | { 11 | public static Type Multiply(Type value1, Type value2) => typeof(ValueTuple<,>).MakeGenericType(value1, value2); 12 | 13 | public static Type Unit => typeof(Unit); 14 | } 15 | 16 | public partial class DotNetCategory 17 | { 18 | // Associator: (T1 x T2) x T3 -> T1 x (T2 x T3) 19 | // Associator: ValueTuple, T3> -> ValueTuple> 20 | public static (T1, (T2, T3)) Associator(((T1, T2), T3) product) => 21 | (product.Item1.Item1, (product.Item1.Item2, product.Item2)); 22 | 23 | // LeftUnitor: Unit x T -> T 24 | // LeftUnitor: ValueTuple -> T 25 | public static T LeftUnitor((Unit, T) product) => product.Item2; 26 | 27 | // RightUnitor: T x Unit -> T 28 | // RightUnitor: ValueTuple -> T 29 | public static T RightUnitor((T, Unit) product) => product.Item1; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tutorial.Shared/CategoryTheory/Optional`1.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.CategoryTheory 2 | { 3 | using System; 4 | 5 | #pragma warning disable CA1815 // Override equals and operator equals on value types 6 | public readonly struct Optional 7 | #pragma warning restore CA1815 // Override equals and operator equals on value types 8 | { 9 | private readonly Lazy<(bool, T)> factory; 10 | 11 | public Optional(Func<(bool, T)> factory = null) => 12 | this.factory = factory == null ? null : new Lazy<(bool, T)>(factory); 13 | 14 | public bool HasValue => this.factory?.Value.Item1 ?? false; 15 | 16 | public T Value 17 | { 18 | get 19 | { 20 | if (!this.HasValue) 21 | { 22 | throw new InvalidOperationException($"{nameof(Optional)} object must have a value."); 23 | } 24 | return this.factory.Value.Item2; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/CovarianceContravariance.Func.il: -------------------------------------------------------------------------------- 1 | .class public auto ansi sealed Func<-T, +TResult> extends System.MulticastDelegate 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/ExceptionFilter.il: -------------------------------------------------------------------------------- 1 | .method assembly hidebysig static void ExceptionFilter(class [System]System.Net.WebClient webClient) cil managed 2 | { 3 | .try 4 | { 5 | // string html = webClient.DownloadString("http://weblogs.asp.net/dixin"); 6 | } 7 | filter 8 | { 9 | // when ((exception.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.BadRequest) 10 | } 11 | { 12 | // Handle exception. 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/InputOutput.OptionalParameter.il: -------------------------------------------------------------------------------- 1 | .method assembly hidebysig static 2 | void Optional ( 3 | bool required1, 4 | char required2, 5 | [opt] int32 optional1, 6 | [opt] string optional2, 7 | [opt] class [System]System.Uri optional3, 8 | [opt] valuetype [mscorlib]System.Guid optional4, 9 | [opt] class [System]System.Uri optional5, 10 | [opt] valuetype [mscorlib]System.Guid optional6 11 | ) cil managed 12 | { 13 | .param [3] = int32(2147483647) // optional1 = int.MaxValue 14 | .param [4] = "Default value." // optional2 = "Default value." 15 | .param [5] = nullref // optional3 = null 16 | .param [6] = nullref // optional4 = new Guid() 17 | .param [7] = nullref // optional5 = default 18 | .param [8] = nullref // optional6 = default 19 | 20 | .maxstack 8 21 | 22 | IL_0000: nop 23 | IL_0001: ret 24 | } -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/Lambda.ExpressionTree.txt: -------------------------------------------------------------------------------- 1 | Expression> (NodeType = Lambda, Type = Func) 2 | |_Parameters 3 | | |_ParameterExpression (NodeType = Parameter, Type = int) 4 | | |_Name = "int32" 5 | |_Body 6 | |_BinaryExpression (NodeType = GreaterThan, Type = bool) 7 | |_Left 8 | | |_ParameterExpression (NodeType = Parameter, Type = int) 9 | | |_Name = "int32" 10 | |_Right 11 | |_ConstantExpression (NodeType = Constant, Type = int) 12 | |_Value = 0 13 | 14 | Expression> (NodeType = Lambda, Type = Func) 15 | |_Parameters 16 | | |_ParameterExpression (NodeType = Parameter, Type = double) 17 | | | |_Name = "a" 18 | | |_ParameterExpression (NodeType = Parameter, Type = double) 19 | | | |_Name = "b" 20 | | |_ParameterExpression (NodeType = Parameter, Type = double) 21 | | | |_Name = "c" 22 | | |_ParameterExpression (NodeType = Parameter, Type = double) 23 | | | |_Name = "d" 24 | | |_ParameterExpression (NodeType = Parameter, Type = double) 25 | | |_Name = "e" 26 | |_Body 27 | |_BinaryExpression (NodeType = Add, Type = double) 28 | |_Left 29 | | |_BinaryExpression (NodeType = Subtract, Type = double) 30 | | |_Left 31 | | | |_BinaryExpression (NodeType = Add, Type = double) 32 | | | |_Left 33 | | | | |_ParameterExpression (NodeType = Parameter, Type = double) 34 | | | | |_Name = "a" 35 | | | |_Right 36 | | | |_ParameterExpression (NodeType = Parameter, Type = double) 37 | | | |_Name = "b" 38 | | |_Right 39 | | |_BinaryExpression (NodeType = Divide, Type = double) 40 | | |_Left 41 | | | |_BinaryExpression (NodeType = Multiply, Type = double) 42 | | | |_Left 43 | | | | |_ParameterExpression (NodeType = Parameter, Type = double) 44 | | | | |_Name = "c" 45 | | | |_right 46 | | | |_ParameterExpression (NodeType = Parameter, Type = double) 47 | | | |_Name = "d" 48 | | |_Right 49 | | |_ConstantExpression (NodeType = Constant, Type = double) 50 | | |_Value = 2 51 | |_Right 52 | |_BinaryExpression (NodeType = Multiply, Type = double) 53 | |_Left 54 | | |_ParameterExpression (NodeType = Parameter, Type = double) 55 | | |_Name = "e" 56 | |_Right 57 | |_ConstantExpression (NodeType = Constant, Type = double) 58 | |_Value = 3 -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/NamedFunction.Data.il: -------------------------------------------------------------------------------- 1 | .class private auto ansi beforefieldinit Data 2 | extends [mscorlib]System.Object 3 | { 4 | .method assembly hidebysig instance int32 InstanceAdd ( 5 | int32 value1, 6 | int32 value2) cil managed 7 | { 8 | .maxstack 2 9 | .locals init ([0] int32 V_0) // Local int variable V_0. 10 | IL_0000: nop // Do nothing. 11 | IL_0001: ldarg.0 // Load first argument this. 12 | IL_0002: ldfld int32 Data::'value' // Load field this.value. 13 | IL_0007: ldarg.1 // Load second argument value1. 14 | IL_0008: add // Add this.value and value1. 15 | IL_0009: ldarg.2 // Load third argument value2. 16 | IL_000a: add // Add value2. 17 | IL_000b: stloc.0 // Set result to first local variable V_0. 18 | IL_000c: br.s IL_000e // Transfer control to IL_000e. 19 | IL_000e: ldloc.0 // Load first local variable V_0. 20 | IL_000f: ret // Return V_0. 21 | } 22 | 23 | .method assembly hidebysig static int32 StaticAdd ( 24 | class Data this, 25 | int32 value1, 26 | int32 value2) cil managed 27 | { 28 | .maxstack 2 29 | .locals init ([0] int32 V_0) // Local int variable V_0. 30 | IL_0000: nop // Do nothing. 31 | IL_0001: ldarg.0 // Load first argument this. 32 | IL_0002: ldfld int32 Data::'value' // Load field this.value. 33 | IL_0007: ldarg.1 // Load second argument value1. 34 | IL_0008: add // Add this.value and value1. 35 | IL_0009: ldarg.2 // Load third argument value2. 36 | IL_000a: add // Add value2. 37 | IL_000b: stloc.0 // Set result to first local variable V_0. 38 | IL_000c: br.s IL_000e // Transfer control to IL_000e. 39 | IL_000e: ldloc.0 // Load first local variable V_0. 40 | IL_000f: ret // Return V_0. 41 | } 42 | 43 | // Other members. 44 | } 45 | -------------------------------------------------------------------------------- /Tutorial.Shared/Functional/TraceExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial 2 | { 3 | using System.Diagnostics; 4 | 5 | public static partial class TraceExtensions 6 | { 7 | public static T WriteLine(this T value) 8 | { 9 | Trace.WriteLine(value); 10 | return value; 11 | } 12 | 13 | public static T Write(this T value) 14 | { 15 | Trace.Write(value); 16 | return value; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Declarative.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.GettingStarted 2 | { 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | using Tutorial.Properties; 6 | 7 | public class Contact 8 | { 9 | [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = nameof(Resources.NameRequired))] 10 | [StringLength(maximumLength: 50, MinimumLength = 1, ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = nameof(Resources.NameInvalid))] 11 | public string Name { get; set; } 12 | 13 | [EmailAddress(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = nameof(Resources.EmailInvalid))] 14 | public string Email { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Functional.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.GettingStarted 2 | { 3 | using System; 4 | using System.IO; 5 | 6 | internal static partial class Overview 7 | { 8 | internal static FileInfo Download(Uri sourceUri, DirectoryInfo downloadDirectory) 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | 13 | internal static FileInfo Convert(FileInfo sourceFile, FileInfo templateFile) 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | internal static Func CreateDocumentBuilder( 19 | Func download, Func convert) 20 | { 21 | return (sourceUri, downloadDirectory, templateFile) => 22 | { 23 | FileInfo sourceFile = download(sourceUri, downloadDirectory); 24 | return convert(sourceFile, templateFile); 25 | }; 26 | } 27 | 28 | internal static void BuildDocumentWithFunctions(Uri sourceUri, DirectoryInfo downloadDirectory, FileInfo templateFile) 29 | { 30 | Func buildDocument = CreateDocumentBuilder(Download, Convert); 31 | FileInfo resultFile = buildDocument(sourceUri, downloadDirectory, templateFile); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToJson.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "status": 200, 4 | "msg": "OK" 5 | }, 6 | "response": { 7 | "blog": { 8 | "title": "Dixin Yan", 9 | "name": "dixinyan", 10 | "total_posts": 20, 11 | "posts": 20, 12 | "url": "http://dixinyan.tumblr.com/", 13 | "updated": 1487649099, 14 | "description": "Blog - https://weblog.asp.net/dixin", 15 | "is_nsfw": false, 16 | "ask": true, 17 | "ask_page_title": "Ask me anything", 18 | "ask_anon": true, 19 | "share_likes": false 20 | }, 21 | "posts": [ 22 | { 23 | "type": "photo", 24 | "blog_name": "dixinyan", 25 | "id": 94086491678, 26 | "post_url": "http://dixinyan.tumblr.com/post/94086491678/microsoft-way-microsoft-campus-microsoft-campus", 27 | "slug": "microsoft-way-microsoft-campus-microsoft-campus", 28 | "date": "2014-08-07 19:11:43 GMT", 29 | "timestamp": 1407438703, 30 | "state": "published", 31 | "format": "html", 32 | "reblog_key": "FZQVzcFD", 33 | "tags": [ "Microsoft" ], 34 | "short_url": "https://tmblr.co/Z_W6Et1Nd-UuU", 35 | "summary": "Microsoft Way, Microsoft Campus Microsoft Campus is the informal name of Microsoft's corporate headquarters, located at One...", 36 | "recommended_source": null, 37 | "recommended_color": null, 38 | "note_count": 4, 39 | "caption": "

Microsoft Way, Microsoft Campus

Microsoft Campus is the informal name of Microsoft’s corporate headquarters, located at One Microsoft Way in Redmond, Washington. Microsoft initially moved onto the grounds of the campus on February 26, 1986. en.wikipedia.org/wiki/Microsoft_Redmond_Campus\n\n

", 40 | "image_permalink": "http://dixinyan.tumblr.com/image/94086491678", 41 | "can_like": true, 42 | "can_reblog": true, 43 | "can_send_in_message": true, 44 | "can_reply": false, 45 | "display_avatar": true 46 | // More post info. 47 | } 48 | // More posts. 49 | ], 50 | "total_posts": 20 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.GettingStarted 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | 7 | using Microsoft.Azure.Documents.Client; 8 | 9 | using Newtonsoft.Json; 10 | 11 | public class Store 12 | { 13 | [JsonProperty(PropertyName = "id")] 14 | public string Id; 15 | 16 | public string Name; 17 | 18 | public Address Address; 19 | } 20 | 21 | public class Address 22 | { 23 | public string AddressType; 24 | 25 | public string AddressLine1; 26 | 27 | public Location Location; 28 | 29 | public string PostalCode; 30 | 31 | public string CountryRegionName; 32 | } 33 | 34 | public class Location 35 | { 36 | public string City; 37 | 38 | public string StateProvinceName; 39 | } 40 | 41 | internal static partial class Overview 42 | { 43 | internal static void LinqToNoSql(string key) 44 | { 45 | using (DocumentClient client = new DocumentClient( 46 | new Uri("https://dixin.documents.azure.com:443/"), key)) 47 | { 48 | IOrderedQueryable source = client.CreateDocumentQuery( 49 | UriFactory.CreateDocumentCollectionUri("dixin", "Store")); // Get source. 50 | IQueryable query = from store in source 51 | where store.Address.Location.City == "Seattle" 52 | orderby store.Name 53 | select store.Name; // Define query. 54 | // Equivalent to: 55 | // IQueryable query = source 56 | // .Where(store => store.Address.CountryRegionName == "United States") 57 | // .OrderBy(store => store.Address.PostalCode) 58 | // .Select(store => store.Name); 59 | foreach (string result in query) // Execute query. 60 | { 61 | Trace.WriteLine(result); 62 | } 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "1424", 4 | "Name": "Closeout Boutique", 5 | "Address": { 6 | "AddressType": "Main Office", 7 | "AddressLine1": "1050 Oak Street", 8 | "Location": { 9 | "City": "Seattle", 10 | "StateProvinceName": "Washington" 11 | }, 12 | "PostalCode": "98104", 13 | "CountryRegionName": "United States" 14 | } 15 | } 16 | // More documents. 17 | ] 18 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST(BusinessEntityID AS varchar) AS [Id], 3 | Name AS [Name], 4 | AddressType AS [Address.AddressType], 5 | AddressLine1 AS [Address.AddressLine1], 6 | City AS [Address.Location.City], 7 | StateProvinceName AS [Address.Location.StateProvinceName], 8 | PostalCode AS [Address.PostalCode], 9 | CountryRegionName AS [Address.CountryRegionName] 10 | FROM 11 | Sales.vStoreWithAddresses 12 | WHERE 13 | AddressType = N'Main Office' -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToObjects.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.GettingStarted 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Reflection; 8 | 9 | internal static partial class Linq 10 | { 11 | internal static void Dynamic() 12 | { 13 | IEnumerable source = new int[] { 4, 3, 2, 1, 0, -1 }; // Get source. 14 | IEnumerable query = 15 | from dynamic value in source 16 | where value.ByPass.Compiler.Check > 0 17 | orderby value.ByPass().Compiler().Check() 18 | select value & new object(); // Define query. 19 | foreach (dynamic result in query) // Execute query. 20 | { 21 | Trace.WriteLine(result); 22 | } 23 | } 24 | } 25 | 26 | internal static partial class Linq 27 | { 28 | internal static void DelegateTypesWithQueryExpression() 29 | { 30 | Assembly coreLibrary = typeof(object).Assembly; 31 | IEnumerable> delegateGroups = 32 | from type in coreLibrary.ExportedTypes 33 | where type.BaseType == typeof(MulticastDelegate) 34 | group type by type.Namespace into delegateGroup 35 | orderby delegateGroup.Count() descending, delegateGroup.Key 36 | select delegateGroup; 37 | 38 | foreach (IGrouping delegateGroup in delegateGroups) // Output. 39 | { 40 | Trace.Write(delegateGroup.Count() + " in " + delegateGroup.Key + ":"); 41 | foreach (Type delegateType in delegateGroup) 42 | { 43 | Trace.Write(" " + delegateType.Name); 44 | } 45 | Trace.Write(Environment.NewLine); 46 | } 47 | } 48 | } 49 | 50 | internal static partial class Linq 51 | { 52 | internal static void DelegateTypesWithQueryMethods() 53 | { 54 | Assembly coreLibrary = typeof(object).Assembly; 55 | IEnumerable> delegateGroups = coreLibrary.ExportedTypes 56 | .Where(type => type.BaseType == typeof(MulticastDelegate)) 57 | .GroupBy(type => type.Namespace) 58 | .OrderByDescending(delegateGroup => delegateGroup.Count()) 59 | .ThenBy(delegateGroup => delegateGroup.Key); 60 | 61 | foreach (IGrouping delegateGroup in delegateGroups) // Output. 62 | { 63 | Trace.Write(delegateGroup.Count() + " in " + delegateGroup.Key + ":"); 64 | foreach (Type delegateType in delegateGroup) 65 | { 66 | Trace.Write(" " + delegateType.Name); 67 | } 68 | Trace.Write(Environment.NewLine); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.LinqToXml.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Dixin's Blog 5 | https://weblogs.asp.net:443/dixin/ 6 | https://weblogs.asp.net:443/dixin/ 7 | 8 | EntityFramework.Functions: Code First Functions for Entity Framework 9 | https://weblogs.asp.net/dixin/entityframework.functions 10 | 11 | Mon Dec 17, 2015 06:27:56 GMT 12 | https://weblogs.asp.net/dixin/entityframework.functions 13 | .NET 14 | LINQ 15 | Entity Framework 16 | LINQ to Entities 17 | Code First 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Tutorial.Shared/GettingStarted/Overview.Linq.NetFX.cs: -------------------------------------------------------------------------------- 1 | #if NETFX 2 | namespace Tutorial.Shared.Introduction 3 | { 4 | using System.Data; 5 | using System.Data.Common; 6 | using System.Data.SqlClient; 7 | using System.Diagnostics; 8 | using System.Linq; 9 | using Tutorial.LinqToSql; 10 | 11 | internal static partial class Overview 12 | { 13 | internal static void LinqToDataSets(string connectionString) 14 | { 15 | using (DataSet dataSet = new DataSet()) 16 | using (DataAdapter dataAdapter = new SqlDataAdapter( 17 | @"SELECT [Name], [ListPrice], [ProductSubcategoryID] FROM [Production].[Product]", connectionString)) 18 | { 19 | dataAdapter.Fill(dataSet); 20 | EnumerableRowCollection source = dataSet.Tables[0].AsEnumerable(); // Get source. 21 | EnumerableRowCollection query = 22 | from product in source 23 | where product.Field("ProductSubcategoryID") == 1 24 | orderby product.Field("ListPrice") 25 | select product.Field("Name"); // Define query. 26 | // Equivalent to: 27 | // EnumerableRowCollection query = source 28 | // .Where(product => product.Field("ProductSubcategoryID") == 1) 29 | // .OrderBy(product => product.Field("ListPrice")) 30 | // .Select(product => product.Field("Name")); 31 | foreach (string result in query) // Execute query. 32 | { 33 | Trace.WriteLine(result); 34 | } 35 | } 36 | } 37 | 38 | internal static void LinqToSql() 39 | { 40 | using (AdventureWorks adventureWorks = new AdventureWorks()) 41 | { 42 | IQueryable source = adventureWorks.Products; // Get source. 43 | IQueryable query = from product in source 44 | where product.ProductSubcategory.ProductCategory.Name == "Bikes" 45 | orderby product.ListPrice 46 | select product.Name; // Define query. 47 | // Equivalent to: 48 | // IQueryable query = source 49 | // .Where(product => product.ProductSubcategory.ProductCategory.Name == "Bikes") 50 | // .OrderBy(product => product.ListPrice) 51 | // .Select(product => product.Name); 52 | foreach (string result in query) // Execute query. 53 | { 54 | Trace.WriteLine(result); 55 | } 56 | } 57 | } 58 | } 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/ChurchEncoding.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using static ChurchBoolean; 4 | 5 | public static partial class ChurchEncoding 6 | { 7 | // System.Boolean structure to Boolean function. 8 | public static Boolean Church(this bool boolean) => boolean ? True : False; 9 | 10 | // Boolean function to System.Boolean structure. 11 | public static bool Unchurch(this Boolean boolean) => boolean(true)(false); 12 | } 13 | 14 | public static partial class ChurchEncoding 15 | { 16 | public static Numeral Church(this uint n) => n == 0U ? ChurchNumeral.Zero : Church(n - 1U).Increase(); 17 | 18 | public static uint Unchurch(this Numeral numeral) => (uint)numeral(x => (uint)x + 1U)(0U); 19 | 20 | public static string Visualize(this Numeral numeral) => 21 | (string)numeral(x => string.Concat((string)x, "*"))(string.Empty); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/ChurchList.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | 5 | using static ChurchBoolean; 6 | 7 | // ListNode is the alias of Tuple>. 8 | public delegate dynamic ListNode(Boolean f); 9 | 10 | public static partial class ChurchList 11 | { 12 | // Create = value => next => (value, next) 13 | public static readonly Func, ListNode>> 14 | Create = value => next => new ListNode(ChurchTuple>.Create(value)(next)); 15 | 16 | // Value = node => node.Item1() 17 | public static readonly Func, T> 18 | Value = node => new Tuple>(node).Item1(); 19 | 20 | // Next = node => node.Item2() 21 | public static readonly Func, ListNode> 22 | Next = node => new Tuple>(node).Item2(); 23 | } 24 | 25 | public static partial class ChurchList 26 | { 27 | // Null = False; 28 | public static readonly ListNode 29 | Null = new ListNode(False); 30 | 31 | // IsNull = node => node(value => next => _ => False)(True) 32 | public static readonly Func, Boolean> 33 | IsNull = node => node(value => next => new Func(_ => False))(True); 34 | 35 | public static readonly Func, Func>> 36 | ListNodeAt = start => index => index(node => Next(node))(start); 37 | } 38 | 39 | public static class ListNodeExtensions 40 | { 41 | public static T Value(this ListNode node) => ChurchList.Value(node); 42 | 43 | public static ListNode Next(this ListNode node) => ChurchList.Next(node); 44 | 45 | public static Boolean IsNull(this ListNode node) => ChurchList.IsNull(node); 46 | 47 | public static ListNode ListNodeAt(this ListNode start, Numeral index) => ChurchList.ListNodeAt(start)(index); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/ChurchNestedList.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | 5 | using static ChurchBoolean; 6 | 7 | // ListNode2 is the alias of Tuple>>. 8 | public delegate object NestedListNode(Boolean f); 9 | 10 | public static partial class ChurchNestedList 11 | { 12 | // Null = f => True 13 | public static readonly NestedListNode 14 | Null = f => True; 15 | } 16 | 17 | public static partial class ChurchNestedList 18 | { 19 | // IsNull = node => node.Item1() 20 | public static readonly Func, Boolean> 21 | IsNull = node => new Tuple>>(node).Item1(); 22 | } 23 | 24 | public static partial class ChurchNestedList 25 | { 26 | // Create = value => next => ChurchTuple.Create(False)(ChurchTuple.Create(value)(next)) 27 | public static readonly Func, NestedListNode>> 28 | Create = value => next => new NestedListNode(ChurchTuple>>.Create 29 | (False) 30 | (ChurchTuple>.Create(value)(next))); 31 | } 32 | 33 | public static partial class ChurchNestedList 34 | { 35 | // Value = node => node.Item2().Item1() 36 | public static readonly Func, T> 37 | Value = node => new Tuple>>(node).Item2().Item1(); 38 | 39 | // Next = node => node.Item2().Item2() 40 | public static readonly Func, NestedListNode> 41 | Next = node => new Tuple>>(node).Item2().Item2(); 42 | } 43 | 44 | public static partial class ChurchNestedList 45 | { 46 | // NodeAt = start => index = index(Next)(start) 47 | public static readonly Func, Func>> 48 | NodeAt = start => index => (NestedListNode)index(node => Next((NestedListNode)node))(start); 49 | } 50 | 51 | public static partial class NestedListNodeExtensions 52 | { 53 | public static Boolean IsNull(this NestedListNode node) => ChurchNestedList.IsNull(node); 54 | 55 | public static T Value(this NestedListNode node) => ChurchNestedList.Value(node); 56 | 57 | public static NestedListNode Next(this NestedListNode node) => ChurchNestedList.Next(node); 58 | 59 | public static NestedListNode NodeAt(this NestedListNode start, Numeral index) => 60 | ChurchNestedList.NodeAt(start)(index); 61 | } 62 | } -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Combinators.Bckw.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | 5 | public static class BckwCombinators 6 | { 7 | public static readonly Func, Func, Func>> 8 | B = x => y => z => x(y(z)); 9 | 10 | public static readonly Func>, Func>> 11 | C = x => y => z => x(z)(y); 12 | } 13 | 14 | public static class BckwCombinators 15 | { 16 | public static readonly Func> 17 | K = x => y => x; 18 | 19 | public static readonly Func>, Func> 20 | W = x => y => x(y)(y); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Combinators.Iota.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | 5 | using static IotaCombinator; 6 | 7 | public static partial class IotaCombinator 8 | { 9 | public static readonly Func 10 | #pragma warning disable SA1307 // Accessible fields must begin with upper-case letter 11 | #pragma warning disable SA1311 // Static readonly fields must begin with upper-case letter 12 | ι = f => f 13 | #pragma warning restore SA1311 // Static readonly fields must begin with upper-case letter 14 | #pragma warning restore SA1307 // Accessible fields must begin with upper-case letter 15 | (new Func>>(x => y => z => x(z)(y(z)))) // S 16 | (new Func>(x => y => x)); // K 17 | } 18 | 19 | public static class IotaCalculus 20 | { 21 | public static readonly Func>> 22 | S = ι(ι(ι(ι(ι)))); 23 | 24 | public static readonly Func> 25 | K = ι(ι(ι(ι))); 26 | 27 | public static readonly Func 28 | I = ι(ι); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Combinators.Omega.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | #if DEMO 4 | public delegate TResult Func(?); 5 | 6 | public delegate TResult Func(Func self); 7 | #endif 8 | 9 | public delegate TResult SelfApplicableFunc(SelfApplicableFunc self); 10 | 11 | public static class OmegaCombinators 12 | { 13 | public static readonly SelfApplicableFunc 14 | #pragma warning disable SA1307 // Accessible fields must begin with upper-case letter 15 | #pragma warning disable SA1311 // Static readonly fields must begin with upper-case letter 16 | ω = f => f(f); 17 | #pragma warning restore SA1311 // Static readonly fields must begin with upper-case letter 18 | #pragma warning restore SA1307 // Accessible fields must begin with upper-case letter 19 | 20 | public static readonly TResult 21 | Ω = ω(ω); 22 | } 23 | } -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Equivalence.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | 5 | using static ChurchBoolean; 6 | 7 | public static partial class Functions 8 | { 9 | public static readonly Func> 10 | Sequence = value1 => value2 => value2; 11 | } 12 | 13 | internal static class Halting 14 | { 15 | // IsHalting = f => x => True if f halts with x; otherwise, False 16 | internal static readonly Func, Func> 17 | IsHalting = f => x => throw new NotImplementedException(); 18 | 19 | // IsNotHalting = f => If(IsHalting(f)(f))(_ => Sequence(Ω)(False))(_ => True) 20 | internal static readonly Func, Boolean> 21 | IsNotHalting = f => 22 | If(Halting, TResult>.IsHalting(new Func, TResult>(f))(f)) 23 | (_ => Functions.Sequence(OmegaCombinators.Ω)(False)) 24 | (_ => True); 25 | } 26 | 27 | internal static class Equivalence 28 | { 29 | // IsEquivalent = f1 => f2 => True if f1 and f2 are equivalent; otherwise, False 30 | internal static readonly Func, Func, Boolean>> 31 | IsEquivalent = f1 => f2 => throw new NotImplementedException(); 32 | 33 | // IsHalting = f => x => IsEquivalent(_ => Sequence(f(x))(True))(_ => True) 34 | internal static readonly Func, Func> 35 | IsHalting = f => x => Equivalence.IsEquivalent(_ => Functions.Sequence(f(x))(True))(_ => True); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Expressions.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | using System; 4 | using System.Linq; 5 | 6 | internal static class Expressions 7 | { 8 | #if DEMO 9 | internal static Func Variable(Func, T>> g, Func h) => 10 | x => g(x)(x => h(x)); 11 | #endif 12 | 13 | internal static Func Variable(Func, T>> g, Func h) => 14 | x => g(x)(y => h(y)); 15 | 16 | internal static void LinqQuery() 17 | { 18 | Func isEven = value => value % 2 == 0; 19 | Enumerable.Range(0, 5).Where(value => isEven(value)).ForEach(value => Console.WriteLine(value)); 20 | } 21 | 22 | internal static void EtaConversion() 23 | { 24 | Func isEven = x => x % 2 == 0; 25 | Enumerable.Range(0, 5).Where(isEven).ForEach(Console.WriteLine); 26 | } 27 | 28 | internal static void Compose() 29 | { 30 | Func sqrt = Math.Sqrt; 31 | Func abs = Math.Abs; 32 | 33 | Func absSqrt1 = sqrt.o(abs); // Composition: sqrt after abs. 34 | absSqrt1(-2D).WriteLine(); // 1.4142135623731 35 | } 36 | 37 | internal static void Associativity() 38 | { 39 | Func sqrt = Math.Sqrt; 40 | Func abs = Math.Abs; 41 | Func log = Math.Log; 42 | 43 | Func absSqrtLog1 = log.o(sqrt).o(abs); // Composition: (log o sqrt) o abs. 44 | absSqrtLog1(-2D).WriteLine(); // 0.34642256747438094 45 | Func absSqrtLog2 = log.o(sqrt.o(abs)); // Composition: log o (sqrt o abs). 46 | absSqrtLog2(-2D).WriteLine(); // 0.34642256747438094 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/Functions.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LambdaCalculus 2 | { 3 | // Unit is the alias of Func. 4 | public delegate T Unit(T value); 5 | 6 | public static partial class Functions 7 | { 8 | public static readonly Unit 9 | Id = x => x; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tutorial.Shared/LambdaCalculus/SkiCompiler.hs: -------------------------------------------------------------------------------- 1 | data Expression = Apply Expression Expression 2 | | Lambda String Expression 3 | | Variable String 4 | | S 5 | | K 6 | | I 7 | 8 | instance Show Expression where 9 | show expression = toSkiString expression False 10 | 11 | toSkiString (Apply e1 e2) parentheses = if parentheses then "(" ++ (toSkiString e1 False) ++ " " ++ (toSkiString e2 True) ++ ")" else (toSkiString e1 False) ++ " " ++ (toSkiString e2 True) 12 | toSkiString (Variable v) parentheses = v 13 | toSkiString S parentheses = "S" 14 | toSkiString K parentheses = "K" 15 | toSkiString I parentheses = "I" 16 | 17 | toSki (Apply v e) = Apply (toSki v) (toSki e) 18 | toSki (Lambda v e) | not $ isFree v e = Apply K (toSki e) 19 | toSki (Lambda v1 (Variable v2)) | v1 == v2 = I 20 | toSki (Lambda v1 (Lambda v2 e)) | isFree v1 e = toSki (Lambda v1 (toSki (Lambda v2 e))) 21 | toSki (Lambda v (Apply e1 e2)) = Apply (Apply S (toSki $ Lambda v e1)) (toSki $ Lambda v e2) 22 | toSki (Variable v) = Variable v 23 | toSki S = S 24 | toSki K = K 25 | toSki I = I 26 | 27 | isFree v (Apply e1 e2) = (isFree v e1) || (isFree v e2) 28 | isFree v1 (Lambda v2 e) = v1 /= v2 && (isFree v1 e) 29 | isFree v1 (Variable v2) = v1 == v2 30 | isFree v S = False 31 | isFree v K = False 32 | isFree v I = False 33 | 34 | createTuple = Lambda "x" $ Lambda "y" $ Lambda "f" $ (Variable "f") `Apply` (Variable "x") `Apply` (Variable "y") 35 | 36 | main = putStrLn $ show $ toSki createTuple 37 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Manipulation.UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | internal static partial class UnitOfWork 4 | { 5 | internal static void Dispose() 6 | { 7 | using (AdventureWorks adventureWorks = new AdventureWorks()) 8 | { 9 | // Unit of work. 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.ConnectionStrings.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | #if NETFX 4 | using System.Configuration; 5 | using System.Data.SqlClient; 6 | using System.IO; 7 | #else 8 | using System.IO; 9 | 10 | using Microsoft.Data.SqlClient; 11 | using Microsoft.Extensions.Configuration; 12 | #endif 13 | 14 | internal static class ConnectionStrings 15 | { 16 | internal static string AdventureWorks { get; } = 17 | #if NETFX 18 | ConfigurationManager.ConnectionStrings[nameof(AdventureWorks)].ConnectionString.FormatFilePath(); 19 | #elif WINDOWS_UWP 20 | ((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values[nameof(AdventureWorks)]).FormatFilePath(); 21 | #elif ANDROID || __IOS__ 22 | // ANDROID and IOS do not support encryption. 23 | @"Server=tcp:dixin.database.windows.net,1433;Initial Catalog=AdventureWorks;User ID=dixinyan;Password=...;MultipleActiveResultSets=False;Connection Timeout=30;"; 24 | #else 25 | new ConfigurationBuilder().AddJsonFile(@"D:\User\GitHub\Tutorial\Tutorial.Tests.Core\app.json").Build() 26 | .GetConnectionString(nameof(AdventureWorks)).FormatFilePath(); 27 | #endif 28 | 29 | private static string FormatFilePath(this string connectionString) 30 | { 31 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder() { ConnectionString = connectionString }; 32 | if (string.IsNullOrEmpty(builder.AttachDBFilename) || Path.IsPathRooted(builder.AttachDBFilename)) 33 | { 34 | return connectionString; 35 | } 36 | string directory = Path.GetDirectoryName(typeof(ConnectionStrings).Assembly.Location); 37 | builder.AttachDBFilename = Path.GetFullPath(Path.Combine(directory, builder.AttachDBFilename)); 38 | return builder.ConnectionString; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Database.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | public partial class AdventureWorks : DbContext { } 6 | 7 | #if DEMO 8 | public partial class AdventureWorks 9 | { 10 | public AdventureWorks(DbConnection connection = null) 11 | : base(GetDbContextOptions(connection)) 12 | { 13 | } 14 | 15 | private static DbContextOptions GetDbContextOptions( 16 | DbConnection connection = null) => 17 | new DbContextOptionsBuilder() 18 | .UseSqlServer( 19 | connection: connection ?? 20 | new SqlConnection(ConnectionStrings.AdventureWorks), 21 | sqlServerOptionsAction: options => options.EnableRetryOnFailure( 22 | maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), 23 | errorNumbersToAdd: null)) 24 | .Options; 25 | } 26 | #endif 27 | 28 | public partial class AdventureWorks 29 | { 30 | protected override void OnModelCreating(ModelBuilder modelBuilder) 31 | { 32 | base.OnModelCreating(modelBuilder); 33 | 34 | MapCompositePrimaryKey(modelBuilder); 35 | MapManyToMany(modelBuilder); 36 | MapDiscriminator(modelBuilder); 37 | } 38 | } 39 | } 40 | 41 | #if DEMO 42 | namespace Microsoft.EntityFrameworkCore 43 | { 44 | using System; 45 | 46 | using Microsoft.EntityFrameworkCore.Infrastructure; 47 | using Microsoft.EntityFrameworkCore.ChangeTracking; 48 | 49 | public class DbContext : IDisposable, IInfrastructure 50 | { 51 | public DbContext(DbContextOptions options); 52 | 53 | public virtual ChangeTracker ChangeTracker { get; } 54 | 55 | public virtual DatabaseFacade Database { get; } 56 | 57 | public virtual void Dispose(); 58 | 59 | public virtual int SaveChanges(); 60 | 61 | public virtual DbSet Set() where TEntity : class; 62 | 63 | protected internal virtual void OnModelCreating(ModelBuilder modelBuilder); 64 | 65 | // Other members. 66 | } 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Database.sql: -------------------------------------------------------------------------------- 1 | select cast(serverproperty('EngineEdition') as int) 2 | 3 | SELECT Count(*) 4 | FROM INFORMATION_SCHEMA.TABLES AS t 5 | WHERE t.TABLE_SCHEMA + '.' + t.TABLE_NAME IN ('Production.vProductAndDescription','Production.ProductCategory','Production.ProductSubcategory','Production.Product','Production.ProductProductPhoto','Production.ProductPhoto') 6 | OR t.TABLE_NAME = 'EdmMetadata' 7 | 8 | exec sp_executesql N'SELECT 9 | [GroupBy1].[A1] AS [C1] 10 | FROM ( SELECT 11 | COUNT(1) AS [A1] 12 | FROM [dbo].[__MigrationHistory] AS [Extent1] 13 | WHERE [Extent1].[ContextKey] = @p__linq__0 14 | ) AS [GroupBy1]',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'Dixin.Linq.EntityFramework.AdventureWorks' 15 | 16 | SELECT 17 | [GroupBy1].[A1] AS [C1] 18 | FROM ( SELECT 19 | COUNT(1) AS [A1] 20 | FROM [dbo].[__MigrationHistory] AS [Extent1] 21 | ) AS [GroupBy1] 22 | 23 | SELECT TOP (1) 24 | [Extent1].[Id] AS [Id], 25 | [Extent1].[ModelHash] AS [ModelHash] 26 | FROM [dbo].[EdmMetadata] AS [Extent1] 27 | ORDER BY [Extent1].[Id] DESC 28 | 29 | SELECT 30 | [Extent1].[ProductCategoryID] AS [ProductCategoryID], 31 | [Extent1].[Name] AS [Name] 32 | FROM [Production].[ProductCategory] AS [Extent1] 33 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Inheritance.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | using System; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | 7 | using Microsoft.EntityFrameworkCore; 8 | 9 | [Table(nameof(TransactionHistory), Schema = AdventureWorks.Production)] 10 | public abstract class TransactionHistory 11 | { 12 | [Key] 13 | public int TransactionID { get; set; } 14 | 15 | public int ProductID { get; set; } 16 | 17 | public DateTime TransactionDate { get; set; } 18 | 19 | public int Quantity { get; set; } 20 | 21 | public decimal ActualCost { get; set; } 22 | } 23 | 24 | public class PurchaseTransactionHistory : TransactionHistory { } 25 | 26 | public class SalesTransactionHistory : TransactionHistory { } 27 | 28 | public class WorkTransactionHistory : TransactionHistory { } 29 | 30 | public enum TransactionType { P, S, W } 31 | 32 | public partial class AdventureWorks 33 | { 34 | private static void MapDiscriminator(ModelBuilder modelBuilder) // Called by OnModelCreating. 35 | { 36 | modelBuilder.Entity() 37 | .HasDiscriminator(nameof(TransactionType)) 38 | .HasValue(nameof(TransactionType.P)) 39 | .HasValue(nameof(TransactionType.S)) 40 | .HasValue(nameof(TransactionType.W)); 41 | } 42 | } 43 | 44 | public partial class AdventureWorks 45 | { 46 | public DbSet Transactions { get; set; } 47 | 48 | public DbSet PurchaseTransactions { get; set; } 49 | 50 | public DbSet SalesTransactions { get; set; } 51 | 52 | public DbSet WorkTransactions { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Inheritance.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Production].[TransactionHistory]( 2 | [TransactionID] int IDENTITY(100000,1) NOT NULL 3 | CONSTRAINT [PK_TransactionHistory_TransactionID] PRIMARY KEY CLUSTERED, 4 | 5 | [ProductID] int NOT NULL 6 | CONSTRAINT [FK_TransactionHistory_Product_ProductID] FOREIGN KEY 7 | REFERENCES [Production].[Product] ([ProductID]), 8 | 9 | [TransactionDate] datetime NOT NULL, 10 | 11 | [TransactionType] nchar(1) NOT NULL 12 | CONSTRAINT [CK_Product_Style] 13 | CHECK (UPPER([TransactionType]) = N'P' OR UPPER([TransactionType]) = N'S' OR UPPER([TransactionType]) = N'W'), 14 | 15 | [Quantity] int NOT NULL, 16 | 17 | [ActualCost] money NOT NULL 18 | 19 | /* Other columns. */); 20 | GO 21 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Tables.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | public partial class AdventureWorks 9 | { 10 | public const string Production = nameof(Production); 11 | } 12 | 13 | [Table(nameof(ProductCategory), Schema = AdventureWorks.Production)] 14 | public partial class ProductCategory 15 | { 16 | [Key] 17 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 18 | public int ProductCategoryID { get; set; } 19 | 20 | [MaxLength(50)] 21 | [Required] 22 | public string Name { get; set; } 23 | 24 | // Other columns are ignored. 25 | } 26 | 27 | #if DEMO 28 | [Table(nameof(ProductCategory), Schema = AdventureWorks.Production)] 29 | public partial class ProductCategory 30 | { 31 | public ProductCategory(int productCategoryID, string name) => 32 | (this.ProductCategoryID, this.Name) = (productCategoryID, name); 33 | 34 | [Key] 35 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 36 | public int ProductCategoryID { get; private set; } 37 | 38 | [MaxLength(50)] 39 | [Required] 40 | public string Name { get; private set; } 41 | } 42 | #endif 43 | 44 | public partial class AdventureWorks 45 | { 46 | public DbSet ProductCategories { get; set; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Views.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToEntities 2 | { 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | [Table(nameof(vEmployee), Schema = AdventureWorks.HumanResources)] 9 | public class vEmployee 10 | { 11 | [Key] 12 | public int BusinessEntityID { get; set; } 13 | 14 | public string FirstName { get; set; } 15 | 16 | public string LastName { get; set; } 17 | 18 | public string JobTitle { get; set; } 19 | } 20 | 21 | public partial class AdventureWorks 22 | { 23 | public DbSet vEmployees { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Modeling.Views.sql: -------------------------------------------------------------------------------- 1 | CREATE VIEW [HumanResources].[vEmployee] 2 | AS 3 | SELECT 4 | e.[BusinessEntityID], 5 | p.[FirstName], 6 | p.[LastName], 7 | e.[JobTitle] 8 | -- Other columns. 9 | FROM [HumanResources].[Employee] e 10 | INNER JOIN [Person].[Person] p 11 | ON p.[BusinessEntityID] = e.[BusinessEntityID] 12 | /* Other tables. */; 13 | GO 14 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/Performance.sql: -------------------------------------------------------------------------------- 1 | ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE; 2 | 3 | -- Shows query plans including itself. 4 | SELECT 5 | sys.syscacheobjects.cacheobjtype, 6 | sys.dm_exec_cached_plans.usecounts, 7 | sys.syscacheobjects.[sql], 8 | sys.dm_exec_query_plan.query_plan 9 | FROM sys.syscacheobjects 10 | INNER JOIN sys.dm_exec_cached_plans ON sys.syscacheobjects.bucketid = sys.dm_exec_cached_plans.bucketid 11 | CROSS APPLY sys.dm_exec_query_plan(sys.dm_exec_cached_plans.plan_handle) 12 | 13 | -- Shows query plans excluding itself. 14 | SELECT 15 | sys.syscacheobjects.cacheobjtype, 16 | sys.dm_exec_query_stats.execution_count, 17 | sys.syscacheobjects.sql, 18 | sys.dm_exec_query_plan.query_plan 19 | FROM sys.dm_exec_query_stats 20 | INNER JOIN sys.dm_exec_cached_plans ON sys.dm_exec_query_stats.plan_handle = sys.dm_exec_cached_plans.plan_handle 21 | INNER JOIN sys.syscacheobjects ON sys.syscacheobjects.bucketid = sys.dm_exec_cached_plans.bucketid 22 | CROSS APPLY sys.dm_exec_query_plan(sys.dm_exec_query_stats.plan_handle) 23 | 24 | -- Equivalent to: 25 | SELECT 26 | sys.syscacheobjects.cacheobjtype, 27 | sys.dm_exec_query_stats.execution_count, 28 | sys.dm_exec_sql_text.text, 29 | sys.dm_exec_query_plan.query_plan 30 | FROM sys.dm_exec_query_stats 31 | INNER JOIN sys.dm_exec_cached_plans ON sys.dm_exec_query_stats.plan_handle = sys.dm_exec_cached_plans.plan_handle 32 | INNER JOIN sys.syscacheobjects ON sys.syscacheobjects.bucketid = sys.dm_exec_cached_plans.bucketid 33 | CROSS APPLY sys.dm_exec_query_plan(sys.dm_exec_query_stats.plan_handle) 34 | CROSS APPLY sys.dm_exec_sql_text(sys.dm_exec_query_stats.sql_handle) 35 | 36 | SELECT [product].[ProductID], [product].[ListPrice], [product].[Name], [product].[ProductSubcategoryID], [product].[RowVersion] 37 | FROM [Production].[Product] AS [product] 38 | WHERE LEN([product].[Name]) >= 1 39 | 40 | SELECT [product].[ProductID], [product].[ListPrice], [product].[Name], [product].[ProductSubcategoryID], [product].[RowVersion] 41 | FROM [Production].[Product] AS [product] 42 | WHERE LEN([product].[Name]) >= 10 43 | 44 | exec sp_executesql N'SELECT [product].[ProductID], [product].[ListPrice], [product].[Name], [product].[ProductSubcategoryID], [product].[RowVersion] 45 | FROM [Production].[Product] AS [product] 46 | WHERE LEN([product].[Name]) >= @__minLength_0',N'@__minLength_0 int',@__minLength_0=1 47 | 48 | exec sp_executesql N'SELECT [product].[ProductID], [product].[ListPrice], [product].[Name], [product].[ProductSubcategoryID], [product].[RowVersion] 49 | FROM [Production].[Product] AS [product] 50 | WHERE LEN([product].[Name]) >= @__minLength_0',N'@__minLength_0 int',@__minLength_0=10 51 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToEntities/RemoteQuery.sql: -------------------------------------------------------------------------------- 1 | exec sp_executesql N'SELECT ((@a * @a) + (@b * @b))',N'@a float,@b float',@a=1,@b=2 2 | 3 | exec sp_executesql N'SELECT (((@a + @b) - ((@c * @d) / 2)) + (@e * 3))',N'@a float,@b float,@c float,@d float,@e float',@a=1,@b=2,@c=3,@d=4,@e=5 -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToObjects/Grouping`2.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToObjects 2 | { 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | public class Grouping : IGrouping 8 | { 9 | private readonly List values = new List(); 10 | 11 | public Grouping(TKey key) => this.Key = key; 12 | 13 | public TKey Key { get; } 14 | 15 | public IEnumerator GetEnumerator() => this.values.GetEnumerator(); 16 | 17 | IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); 18 | 19 | internal void Add(TElement value) => this.values.Add(value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToObjects/HashSet`1.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToObjects 2 | { 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | public partial class HashSet : IEnumerable 7 | { 8 | private readonly IEqualityComparer equalityComparer; 9 | 10 | private readonly Dictionary dictionary = new Dictionary(); 11 | 12 | public HashSet(IEqualityComparer equalityComparer = null) => 13 | this.equalityComparer = equalityComparer ?? EqualityComparer.Default; 14 | 15 | public IEnumerator GetEnumerator() => this.dictionary.Values.GetEnumerator(); 16 | 17 | IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); 18 | } 19 | 20 | public partial class HashSet 21 | { 22 | private int GetHashCode(T value) => value == null 23 | ? -1 24 | : this.equalityComparer.GetHashCode(value) & int.MaxValue; 25 | // int.MaxValue is ‭0b01111111_11111111_11111111_11111111‬, so the result of & is always > -1. 26 | 27 | public bool Add(T value) 28 | { 29 | int hashCode = this.GetHashCode(value); 30 | if (this.dictionary.ContainsKey(hashCode)) 31 | { 32 | return false; 33 | } 34 | this.dictionary.Add(hashCode, value); 35 | return true; 36 | } 37 | 38 | public HashSet AddRange(IEnumerable values) 39 | { 40 | foreach (T value in values) 41 | { 42 | this.Add(value); 43 | } 44 | return this; 45 | } 46 | } 47 | 48 | public partial class HashSet 49 | { 50 | public bool Remove(T value) 51 | { 52 | int hashCode = this.GetHashCode(value); 53 | if (this.dictionary.ContainsKey(hashCode)) 54 | { 55 | this.dictionary.Remove(hashCode); 56 | return true; 57 | } 58 | return false; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToObjects/Lookup`1.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToObjects 2 | { 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | public partial class Lookup : ILookup 9 | { 10 | private readonly Dictionary> groups = 11 | new Dictionary>(); 12 | 13 | private readonly IEqualityComparer equalityComparer; 14 | 15 | public Lookup(IEqualityComparer equalityComparer = null) => 16 | this.equalityComparer = equalityComparer ?? EqualityComparer.Default; 17 | 18 | public int Count => this.groups.Count; 19 | 20 | private int GetHashCode(TKey key) => key == null 21 | ? -1 22 | : this.equalityComparer.GetHashCode(key) & int.MaxValue; 23 | // int.MaxValue is 0b_01111111_11111111_11111111_11111111. So the hash code of non-null key is always > -1. 24 | 25 | public bool Contains(TKey key) => this.groups.ContainsKey(this.GetHashCode(key)); 26 | 27 | public IEnumerable this[TKey key] => 28 | this.groups.TryGetValue(this.GetHashCode(key), out Grouping group) 29 | ? (IEnumerable)group 30 | : Array.Empty(); 31 | 32 | public IEnumerator> GetEnumerator() => this.groups.Values.GetEnumerator(); 33 | 34 | IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); 35 | } 36 | 37 | public partial class Lookup 38 | { 39 | public Lookup AddRange( 40 | IEnumerable source, 41 | Func keySelector, 42 | Func elementSelector, 43 | bool skipNullKey = false) 44 | { 45 | foreach (TSource value in source) 46 | { 47 | TKey key = keySelector(value); 48 | if (key == null && skipNullKey) 49 | { 50 | continue; 51 | } 52 | int hashCode = this.GetHashCode(key); 53 | if (this.groups.TryGetValue(hashCode, out Grouping group)) 54 | { 55 | group.Add(elementSelector(value)); 56 | } 57 | else 58 | { 59 | this.groups.Add(hashCode, new Grouping(key) { elementSelector(value) }); 60 | } 61 | } 62 | return this; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToObjects/QueryMethods.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.LinqToObjects 2 | { 3 | using System.Collections.Generic; 4 | 5 | internal static partial class QueryMethods 6 | { 7 | internal static void EmptyIfNull(IEnumerable source1, IEnumerable source2) 8 | { 9 | IEnumerable positive = source1.EmptyIfNull() 10 | .Union(source2.EmptyIfNull()) 11 | .Where(int32 => int32 > 0); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToObjects/TraceExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | 7 | public static partial class TraceExtensions 8 | { 9 | public static void WriteLines(this IEnumerable values, Func messageFactory = null) 10 | { 11 | if (messageFactory != null) 12 | { 13 | foreach (T value in values) 14 | { 15 | Trace.WriteLine(messageFactory(value)); 16 | } 17 | } 18 | else 19 | { 20 | foreach (T value in values) 21 | { 22 | Trace.WriteLine(value); 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/AspNetRss.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | LINQ via C# 5 | https://weblogs.asp.net/dixin/linq-via-csharp 6 | 7 |

This is a tutorial of LINQ and functional programming. Hope it helps.

8 |
9 | Mon, 07 Sep 2009 00:00:00 GMT 10 | https://weblogs.asp.net/dixin/linq-via-csharp 11 | C# 12 | LINQ 13 | 14 | https://github.com/Dixin/CodeSnippets/tree/master/Dixin/Linq 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/AspNetRss.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/FlickrRss.dc.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/FlickrRss.flickr.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/FlickrRss.media.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Tutorial.Shared/LinqToXml/FlickrRss.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Microsoft Way, Microsoft Campus 6 | 2011-11-02T16:45:54-08:00 7 | nobody@flickr.com (Dixin Yan) 8 | 9 | Microsoft Way, Microsoft Campus 10 | 11 |

Microsoft Campus is the informal name of Microsoft's corporate headquarters, located at One Microsoft Way in Redmond, Washington. Microsoft initially moved onto the grounds of the campus on February 26, 1986. en.wikipedia.org/wiki/Microsoft_Redmond_Campus

12 |
13 | 14 | Dixin Yan 15 | microsoft 16 | 17 |
18 | 19 |
20 |
21 | -------------------------------------------------------------------------------- /Tutorial.Shared/NetStandard.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial 2 | { 3 | using System; 4 | using System.Reflection; 5 | 6 | internal static class NetStandard 7 | { 8 | internal static Assembly Assembly { get; } = Assembly.LoadFrom( 9 | @"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.6\netstandard.dll"); 10 | // Linux: /usr/share/dotnet/shared/Microsoft.NETCore.App/2.1.6/netstandard.dll 11 | // macOS: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.1.6/netstandard.dll 12 | 13 | // internal static Type[] Types => Assembly.GetForwardedTypes(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Tutorial.Shared/ParallelLinq/Partitioning.txt: -------------------------------------------------------------------------------- 1 | Index: 0 1 2 3 4 5 6 7 8 9 10 11 2 | Partition: A A A, B B B, C C C, D D D 3 | -------------------------------------------------------------------------------- /Tutorial.Shared/ParallelLinq/Visualizer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Shared/ParallelLinq/Visualizer.cs -------------------------------------------------------------------------------- /Tutorial.Shared/Tutorial.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | cac237a8-c000-4521-a31d-d9a7c68639a4 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Tutorial.Tests.Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Android 2 | { 3 | using System.Reflection; 4 | using global::Android.App; 5 | using global::Android.OS; 6 | using Xamarin.Android.NUnitLite; 7 | 8 | [Activity(Label = "Tutorial.Tests.Android", MainLauncher = true, Icon = "@drawable/icon")] 9 | public class MainActivity : TestSuiteActivity 10 | { 11 | protected override void OnCreate(Bundle bundle) 12 | { 13 | // tests can be inside the main assembly 14 | this.AddTest(Assembly.GetExecutingAssembly()); 15 | // or in any reference assemblies 16 | // AddTest (typeof (Your.Library.TestClass).Assembly); 17 | 18 | // Once you called base.OnCreate(), you cannot add more assemblies. 19 | base.OnCreate(bundle); 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Tutorial.Tests.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Tutorial.Tests.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Tests.Android")] 4 | -------------------------------------------------------------------------------- /Tutorial.Tests.Android/Resources/drawable/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Android/Resources/drawable/Icon.png -------------------------------------------------------------------------------- /Tutorial.Tests.Android/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello World, Click Me! 4 | Tutorial.Tests.Android 5 | 6 | -------------------------------------------------------------------------------- /Tutorial.Tests.Android/Tests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Android 2 | { 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class Tests 7 | { 8 | [Test] 9 | public void Test() => MSTest.Run(); 10 | } 11 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Core/Tutorial.Tests.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | Tutorial.Tests 6 | 7 | Dixin Yan 8 | Tutorial 9 | 10 | 11 | 12 | latest 13 | 14 | 15 | 16 | latest 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Tutorial.Tests.Core/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | // "AdventureWorks": "Server=tcp:dixin.database.windows.net,1433;Initial Catalog=AdventureWorks;Persist Security Info=False;User ID=dixinyan;Password=...;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" 4 | "AdventureWorks": "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=..\\..\\..\\..\\Data\\AdventureWorks_Data.mdf;Integrated Security=True;Connect Timeout=30" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Core/Tutorial.Tests.External.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | Tutorial.Tests 6 | 7 | Dixin Yan 8 | Tutorial 9 | 10 | 11 | 12 | latest 13 | 14 | 15 | 16 | latest 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Tests.External.Net")] 4 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Net/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/ActiveIssueAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using Xunit.Sdk; 7 | 8 | namespace Xunit 9 | { 10 | /// 11 | /// Apply this attribute to your test method to specify an active issue. 12 | /// 13 | [TraitDiscoverer("Xunit.NetCore.Extensions.ActiveIssueDiscoverer", "Xunit.NetCore.Extensions")] 14 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 15 | public class ActiveIssueAttribute : Attribute, ITraitAttribute 16 | { 17 | public ActiveIssueAttribute(int issueNumber, TestPlatforms platforms = TestPlatforms.Any) { } 18 | public ActiveIssueAttribute(string issue, TestPlatforms platforms = TestPlatforms.Any) { } 19 | } 20 | } -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/LinqToObjects/AsEnumerableTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using Xunit; 7 | 8 | using static Tutorial.LinqToObjects.EnumerableExtensions; 9 | 10 | // namespace System.Linq.Tests 11 | namespace Tutorial.Tests.LinqToObjects 12 | { 13 | public class AsEnumerableTests 14 | { 15 | [Fact] 16 | public void SameResultsRepeatCallsIntQuery() 17 | { 18 | var q = from x in new[] { 9999, 0, 888, -1, 66, -777, 1, 2, -12345 } 19 | where x > Int32.MinValue 20 | select x; 21 | 22 | Assert.Equal(q.AsEnumerable(), q.AsEnumerable()); 23 | } 24 | 25 | [Fact] 26 | public void SameResultsRepeatCallsStringQuery() 27 | { 28 | var q = from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", String.Empty } 29 | where !String.IsNullOrEmpty(x) 30 | select x; 31 | 32 | Assert.Equal(q.AsEnumerable(), q.AsEnumerable()); 33 | } 34 | 35 | [Fact] 36 | public void NullSourceAllowed() 37 | { 38 | int[] source = null; 39 | 40 | Assert.Null(source.AsEnumerable()); 41 | } 42 | 43 | [Fact] 44 | public void OneElement() 45 | { 46 | int[] source = { 2 }; 47 | 48 | Assert.Equal(source, source.AsEnumerable()); 49 | } 50 | 51 | [Fact] 52 | public void SomeElements() 53 | { 54 | int?[] source = { -5, 0, 1, -4, 3, null, 10 }; 55 | 56 | Assert.Equal(source, source.AsEnumerable()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/LinqToObjects/EmptyEnumerable.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using Xunit; 8 | 9 | using Enumerable = Tutorial.LinqToObjects.EnumerableExtensions; 10 | using static Tutorial.LinqToObjects.EnumerableExtensions; 11 | 12 | // namespace System.Linq.Tests 13 | namespace Tutorial.Tests.LinqToObjects 14 | { 15 | public class EmptyEnumerableTest : EnumerableTests 16 | { 17 | private void TestEmptyCached() 18 | { 19 | var enumerable1 = Enumerable.Empty(); 20 | var enumerable2 = Enumerable.Empty(); 21 | 22 | Assert.Same(enumerable1, enumerable2); // Enumerable.Empty is not cached if not the same. 23 | } 24 | 25 | [Fact] 26 | public void EmptyEnumerableCachedTest() 27 | { 28 | TestEmptyCached(); 29 | TestEmptyCached(); 30 | TestEmptyCached(); 31 | TestEmptyCached(); 32 | } 33 | 34 | private void TestEmptyEmpty() 35 | { 36 | Assert.Equal(new T[0], Enumerable.Empty()); 37 | Assert.Equal(0, Enumerable.Empty().Count()); 38 | Assert.Same(Enumerable.Empty().GetEnumerator(), ((IList)Enumerable.Empty()).GetEnumerator()); 39 | } 40 | 41 | [Fact] 42 | public void EmptyEnumerableIsIndeedEmpty() 43 | { 44 | TestEmptyEmpty(); 45 | TestEmptyEmpty(); 46 | TestEmptyEmpty(); 47 | TestEmptyEmpty(); 48 | } 49 | 50 | [Fact] 51 | public void CastToIList() 52 | { 53 | var emptyEnumerable = Enumerable.Empty(); 54 | Assert.Same(emptyEnumerable, (IList)emptyEnumerable); 55 | } 56 | 57 | [Fact] 58 | public void CastToIListGeneric() 59 | { 60 | var emptyEnumerable = Enumerable.Empty(); 61 | Assert.Same(emptyEnumerable, (IList)emptyEnumerable); 62 | } 63 | 64 | [Fact] 65 | public void CastToArray() 66 | { 67 | var emptyEnumerable = Enumerable.Empty(); 68 | Assert.Same(emptyEnumerable, (object[])emptyEnumerable); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/LinqToObjects/Shuffler.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | 9 | using Enumerable = Tutorial.LinqToObjects.EnumerableExtensions; 10 | using static Tutorial.LinqToObjects.EnumerableExtensions; 11 | 12 | // namespace System.Linq.Tests 13 | namespace Tutorial.Tests.LinqToObjects 14 | { 15 | public static class Shuffler 16 | { 17 | public static IEnumerable Shuffle(this IEnumerable source, int seed) 18 | { 19 | return new ShuffledEnumerable(source, seed); 20 | } 21 | 22 | public static IEnumerable Shuffle(this IEnumerable source) 23 | { 24 | return new ShuffledEnumerable(source); 25 | } 26 | 27 | private class ShuffledEnumerable : IEnumerable 28 | { 29 | private IEnumerable _source; 30 | private int? _seed; 31 | 32 | public ShuffledEnumerable(IEnumerable source) 33 | { 34 | _source = source; 35 | } 36 | 37 | public ShuffledEnumerable(IEnumerable source, int seed) 38 | : this(source) 39 | { 40 | _seed = seed; 41 | } 42 | 43 | public IEnumerator GetEnumerator() 44 | { 45 | Random rnd = _seed.HasValue ? new Random(_seed.GetValueOrDefault()) : new Random(); 46 | T[] array = _source.ToArray(); 47 | int count = array.Length; 48 | for (int i = array.Length - 1; i > 0; --i) 49 | { 50 | int j = rnd.Next(0, i + 1); 51 | if (i != j) 52 | { 53 | T swapped = array[i]; 54 | array[i] = array[j]; 55 | array[j] = swapped; 56 | } 57 | } 58 | return ((IEnumerable)array).GetEnumerator(); 59 | } 60 | 61 | IEnumerator IEnumerable.GetEnumerator() 62 | { 63 | return GetEnumerator(); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/TestPlatforms.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | 7 | namespace Xunit 8 | { 9 | [Flags] 10 | public enum TestPlatforms 11 | { 12 | Windows = 1, 13 | Linux = 2, 14 | OSX = 4, 15 | FreeBSD = 8, 16 | NetBSD = 16, 17 | AnyUnix = FreeBSD | Linux | NetBSD | OSX, 18 | Any = ~0 19 | } 20 | } -------------------------------------------------------------------------------- /Tutorial.Tests.External.Shared/Tutorial.Tests.External.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ddb90975-45f0-4214-8e73-66b854b8781f 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Tutorial.Tests.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Tests.Net")] 4 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/CategoryTheory/BifunctorTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.CategoryTheory 2 | { 3 | using System; 4 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | using Tutorial.CategoryTheory; 8 | 9 | [TestClass] 10 | public class BifunctorTests 11 | { 12 | [TestMethod] 13 | public void LazyTest() 14 | { 15 | bool isExecuted1 = false; 16 | bool isExecuted2 = false; 17 | Tutorial.CategoryTheory.Lazy lazyBinaryFunctor = new Tutorial.CategoryTheory.Lazy(() => (1, "abc")); 18 | Func selector1 = x => { isExecuted1 = true; return x > 0; }; 19 | Func selector2 = x => { isExecuted2 = true; return x.Length; }; 20 | 21 | Tutorial.CategoryTheory.Lazy query = lazyBinaryFunctor.Select(selector1, selector2); 22 | Assert.IsFalse(isExecuted1); // Deferred and lazy. 23 | Assert.IsFalse(isExecuted2); // Deferred and lazy. 24 | 25 | Assert.AreEqual(true, query.Value1); // Execution. 26 | Assert.AreEqual("abc".Length, query.Value2); // Execution. 27 | Assert.IsTrue(isExecuted1); 28 | Assert.IsTrue(isExecuted2); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/CategoryTheory/CategoryTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.CategoryTheory 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | using Tutorial.CategoryTheory; 8 | using Tutorial.Tests.LinqToObjects; 9 | 10 | [TestClass] 11 | public class CategoryTests 12 | { 13 | [TestMethod] 14 | public void DotNetCategoryObjectsTest() 15 | { 16 | IEnumerable types = DotNetCategory.Objects; 17 | EnumerableAssert.Multiple(types); 18 | } 19 | 20 | [TestMethod] 21 | public void DotNetCategoryComposeTest() 22 | { 23 | Func function1 = int32 => Math.Sqrt(int32); 24 | Func function2 = @double => @double.ToString("0.00"); 25 | Delegate function = DotNetCategory.Compose(function2, function1); 26 | Assert.AreEqual("1.41", function.DynamicInvoke(2)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/CategoryTheory/LinqHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.CategoryTheory 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | internal static class LinqHelper 8 | { 9 | internal static IEnumerable Where( 10 | this IEnumerable source, Func predicate) => Enumerable.Where(source, predicate); 11 | 12 | internal static TSource[] ToArray( 13 | this IEnumerable source) => Enumerable.ToArray(source); 14 | 15 | internal static bool Any( 16 | this IEnumerable source) => Enumerable.Any(source); 17 | 18 | internal static TSource Single( 19 | this IEnumerable source) => Enumerable.Single(source); 20 | 21 | internal static TSource Last( 22 | this IEnumerable source) => Enumerable.Last(source); 23 | 24 | internal static IEnumerable Concat( 25 | this IEnumerable first, IEnumerable second) => Enumerable.Concat(first, second); 26 | 27 | internal static IEnumerable Skip( 28 | this IEnumerable source, int count) => Enumerable.Skip(source, count); 29 | } 30 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/CategoryTheory/PerformanceTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.CategoryTheory 2 | { 3 | using System.Diagnostics; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.CategoryTheory; 6 | 7 | [TestClass] 8 | public class PerformanceTests 9 | { 10 | [TestMethod] 11 | public void SortTest() 12 | { 13 | Trace.WriteLine(nameof(Sort.Int32Array)); 14 | Sort.Int32Array(); 15 | 16 | Trace.WriteLine(nameof(Sort.StringArray)); 17 | Sort.StringArray(); 18 | 19 | Trace.WriteLine(nameof(Sort.ValueTypeArray)); 20 | Sort.ValueTypeArray(); 21 | 22 | Trace.WriteLine(nameof(Sort.ReferenceTypeArray)); 23 | Sort.ReferenceTypeArray(); 24 | } 25 | 26 | [TestMethod] 27 | public void FilterTest() 28 | { 29 | Trace.WriteLine(nameof(Filter.Int32Sequence)); 30 | Filter.Int32Sequence(); 31 | 32 | Trace.WriteLine(nameof(Filter.StringSequence)); 33 | Filter.StringSequence(); 34 | 35 | Trace.WriteLine(nameof(Filter.ValueTypeSequence)); 36 | Filter.ValueTypeSequence(); 37 | 38 | Trace.WriteLine(nameof(Filter.ReferenceTypeSequence)); 39 | Filter.ReferenceTypeSequence(); 40 | } 41 | 42 | [TestMethod] 43 | public void LambdaTest() 44 | { 45 | Trace.WriteLine(nameof(Filter.ByPredicate)); 46 | Filter.ByPredicate(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/AsynchronousFunctionTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using System.Threading.Tasks; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.Functional; 6 | 7 | [TestClass] 8 | public class AsyncTests 9 | { 10 | [TestMethod] 11 | public async Task AsyncAwaitTest() 12 | { 13 | object value = new object(); 14 | object result = await AsyncFunctions.CompiledAsync(value); 15 | Assert.AreEqual(value, result); 16 | } 17 | 18 | [TestMethod] 19 | public async Task FuncAwaitableTest() 20 | { 21 | int result = await AsyncFunctions.AsyncFunctionWithFuncAwaitable(1); 22 | Assert.AreEqual(1, result); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/CovarianceContravarianceTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | using Tutorial.Functional; 6 | 7 | [TestClass] 8 | public class VariancesTests 9 | { 10 | [TestMethod] 11 | public void GetTypesWithVarianceTest() 12 | { 13 | Variances.TypesWithVariance(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/DelegateTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.Functional; 5 | 6 | [TestClass] 7 | public class DelegatesTests 8 | { 9 | [TestMethod] 10 | public void DelegateTest() 11 | { 12 | Delegates.StaticMethod(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/ImmutabilityTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.Functional; 5 | 6 | [TestClass] 7 | public class ImmutabilityTests 8 | { 9 | [TestMethod] 10 | public void FibonacciTest() 11 | { 12 | Assert.AreEqual(0, Immutability.Fibonacci(0)); 13 | Assert.AreEqual(1, Immutability.Fibonacci(1)); 14 | Assert.AreEqual(1, Immutability.Fibonacci(2)); 15 | Assert.AreEqual(2, Immutability.Fibonacci(3)); 16 | Assert.AreEqual(3, Immutability.Fibonacci(4)); 17 | Assert.AreEqual(5, Immutability.Fibonacci(5)); 18 | Assert.AreEqual(55, Immutability.Fibonacci(10)); 19 | Assert.AreEqual(6765, Immutability.Fibonacci(20)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/InputOutputTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.Functional; 5 | 6 | [TestClass] 7 | public class ParametersTests 8 | { 9 | [TestMethod] 10 | public void ParameterTest() 11 | { 12 | InputOutput.CallInputByCopy(); 13 | InputOutput.CallInputByAlias(); 14 | InputOutput.CallOutputParameter(); 15 | InputOutput.OutVariable(); 16 | } 17 | 18 | [TestMethod] 19 | public void CallerInfoTest() 20 | { 21 | InputOutput.CallTraceWithCaller(); 22 | } 23 | 24 | [TestMethod] 25 | public void ReturnTest() 26 | { 27 | InputOutput.OutputByCopy(); 28 | InputOutput.OutputByAlias(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/LambdaTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using System; 4 | using System.Linq.Expressions; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Tutorial.Functional; 7 | 8 | [TestClass] 9 | public class LambdaTests 10 | { 11 | [TestMethod] 12 | public void VisitBodyTest() 13 | { 14 | Expression> expression = 15 | (a, b, c, d, e) => a + b - c * d / 2D + e * 3D; 16 | Assert.AreEqual("Add(Subtract(Add(a, b), Divide(Multiply(c, d), 2)), Multiply(e, 3))", expression.PreOrderOutput()); 17 | } 18 | 19 | [TestMethod] 20 | public void CompileTest() 21 | { 22 | Expression> expression = 23 | (a, b, c, d, e) => a + b - c * d / 2D + e * 3D; 24 | 25 | Func expected = expression.Compile(); 26 | #if !__IOS__ 27 | Func actual = expression.CompileToCil(); 28 | Assert.AreEqual(expected(1, 2, 3, 4, 5), actual(1, 2, 3, 4, 5)); 29 | #endif 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Functional/LocalFunctionTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Functional 2 | { 3 | using System.Linq; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.Functional; 6 | 7 | [TestClass] 8 | public class LocalFunctionTests 9 | { 10 | [TestMethod] 11 | public void BinarySearchTest() 12 | { 13 | Assert.AreEqual(-1, Enumerable.Empty().ToArray().BinarySearch(0)); 14 | Assert.AreEqual(-1, Enumerable.Range(0, 10).ToArray().BinarySearch(-1)); 15 | Assert.AreEqual(-1, Enumerable.Range(0, 10).ToArray().BinarySearch(10)); 16 | Enumerable.Range(0, 10).ForEach(int32 => Assert.AreEqual(int32, Enumerable.Range(0, 10).ToArray().BinarySearch(int32))); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/GettingStarted/BasicsTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.GettingStarted 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.GettingStarted; 5 | 6 | [TestClass] 7 | public class BasicsTests 8 | { 9 | [TestMethod] 10 | public void TypeTest() 11 | { 12 | Basics.LocalVariable(); 13 | Basics.Default(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/GettingStarted/OverviewTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.GettingStarted 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Tutorial.GettingStarted; 8 | 9 | [TestClass] 10 | public partial class OverviewTests 11 | { 12 | [TestMethod] 13 | public void StackTest() 14 | { 15 | Stack stack = new Stack(); 16 | stack.Push(1); 17 | Assert.AreEqual(1, stack.Pop()); 18 | stack.Push(2); 19 | stack.Push(3); 20 | Assert.AreEqual(3, stack.Pop()); 21 | stack.Push(4); 22 | Assert.AreEqual(4, stack.Pop()); 23 | Assert.AreEqual(2, stack.Pop()); 24 | try 25 | { 26 | stack.Pop(); 27 | Assert.Fail(); 28 | } 29 | catch (InvalidOperationException exception) 30 | { 31 | Trace.WriteLine(exception); 32 | } 33 | } 34 | 35 | [TestMethod] 36 | public void LinqToJsonTest() 37 | { 38 | Overview.LinqToJson("fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Lambda/ChurchAggregateListTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LambdaCalculus 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.LambdaCalculus; 5 | 6 | [TestClass] 7 | public class ChurchAggregateListTests 8 | { 9 | [TestMethod] 10 | public void CreateValueNextTest() 11 | { 12 | AggregateListNode node1 = ChurchAggregateList.Create(1)(ChurchAggregateList.Null); 13 | AggregateListNode node2 = ChurchAggregateList.Create(2)(node1); 14 | AggregateListNode node3 = ChurchAggregateList.Create(3)(node2); 15 | Assert.AreEqual(1, node1.Value()); 16 | Assert.IsTrue(node1.Next().IsNull().Unchurch()); 17 | Assert.AreEqual(2, node2.Value()); 18 | Assert.AreEqual(node1.Value(), node2.Next().Value()); 19 | Assert.AreEqual(3, node3.Value()); 20 | Assert.AreEqual(node2.Value(), node3.Next().Value()); 21 | Assert.AreEqual(node1.Value(), node3.Next().Next().Value()); 22 | Assert.IsTrue(node3.Next().Next().Next().IsNull().Unchurch()); 23 | } 24 | 25 | [TestMethod] 26 | public void IsNullTest() 27 | { 28 | AggregateListNode node1 = ChurchAggregateList.Create(1)(ChurchAggregateList.Null); 29 | AggregateListNode node2 = ChurchAggregateList.Create(2)(node1); 30 | AggregateListNode node3 = ChurchAggregateList.Create(3)(node2); 31 | Assert.IsTrue(ChurchAggregateList.Null.IsNull().Unchurch()); 32 | Assert.IsFalse(node1.IsNull().Unchurch()); 33 | Assert.IsFalse(node2.IsNull().Unchurch()); 34 | Assert.IsFalse(node3.IsNull().Unchurch()); 35 | Assert.IsTrue(node1.Next().IsNull().Unchurch()); 36 | Assert.IsFalse(node2.Next().IsNull().Unchurch()); 37 | Assert.IsFalse(node3.Next().IsNull().Unchurch()); 38 | } 39 | 40 | [TestMethod] 41 | public void IndexTest() 42 | { 43 | AggregateListNode node1 = ChurchAggregateList.Create(1)(ChurchAggregateList.Null); 44 | AggregateListNode node2 = ChurchAggregateList.Create(2)(node1); 45 | AggregateListNode node3 = ChurchAggregateList.Create(3)(node2); 46 | Assert.AreEqual(node3.Value(), node3.ListNodeAt(0U.Church()).Value()); 47 | Assert.AreEqual(node2.Value(), node3.ListNodeAt(1U.Church()).Value()); 48 | Assert.AreEqual(node1.Value(), node3.ListNodeAt(2U.Church()).Value()); 49 | Assert.IsTrue(node3.ListNodeAt(3U.Church()).IsNull().Unchurch()); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Lambda/ChurchAggregateListWrapperTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LambdaCalculus 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.LambdaCalculus; 5 | 6 | [TestClass] 7 | public class ChurchAggregateListWrapperTests 8 | { 9 | [TestMethod] 10 | public void CreateValueNextTest() 11 | { 12 | AggregateListNodeWrapper node1 = AggregateListNodeWrapper.Create(1)(AggregateListNodeWrapper.Null); 13 | AggregateListNodeWrapper node2 = AggregateListNodeWrapper.Create(2)(node1); 14 | AggregateListNodeWrapper node3 = AggregateListNodeWrapper.Create(3)(node2); 15 | Assert.AreEqual(1, node1.Value()); 16 | Assert.AreEqual(AggregateListNodeWrapper.Null, node1.Next()); 17 | Assert.AreEqual(2, node2.Value()); 18 | Assert.AreEqual(node1.Value(), node2.Next().Value()); 19 | Assert.AreEqual(3, node3.Value()); 20 | Assert.AreEqual(node2.Value(), node3.Next().Value()); 21 | Assert.IsTrue(AggregateListNodeWrapper.Null.Next().IsNull().Unchurch()); 22 | } 23 | 24 | [TestMethod] 25 | public void IsNullTest() 26 | { 27 | AggregateListNodeWrapper node1 = AggregateListNodeWrapper.Create(1)(AggregateListNodeWrapper.Null); 28 | AggregateListNodeWrapper node2 = AggregateListNodeWrapper.Create(2)(node1); 29 | AggregateListNodeWrapper node3 = AggregateListNodeWrapper.Create(3)(node2); 30 | Assert.IsTrue(AggregateListNodeWrapper.Null.IsNull().Unchurch()); 31 | Assert.IsFalse(node1.IsNull().Unchurch()); 32 | Assert.IsFalse(node2.IsNull().Unchurch()); 33 | Assert.IsFalse(node3.IsNull().Unchurch()); 34 | Assert.IsTrue(node1.Next().IsNull().Unchurch()); 35 | Assert.IsFalse(node2.Next().IsNull().Unchurch()); 36 | Assert.IsFalse(node3.Next().IsNull().Unchurch()); 37 | } 38 | 39 | [TestMethod] 40 | public void IndexTest() 41 | { 42 | AggregateListNodeWrapper node1 = AggregateListNodeWrapper.Create(1)(AggregateListNodeWrapper.Null); 43 | AggregateListNodeWrapper node2 = AggregateListNodeWrapper.Create(2)(node1); 44 | AggregateListNodeWrapper node3 = AggregateListNodeWrapper.Create(3)(node2); 45 | Assert.AreEqual(node3.Value(), node3.Index(0U.Church()).Value()); 46 | Assert.AreEqual(node2.Value(), node3.Index(1U.Church()).Value()); 47 | Assert.AreEqual(node1.Value(), node3.Index(2U.Church()).Value()); 48 | Assert.IsTrue(node3.Index(3U.Church()).IsNull().Unchurch()); 49 | Assert.IsTrue(node3.Index(4U.Church()).IsNull().Unchurch()); 50 | Assert.IsTrue(node3.Index(5U.Church()).IsNull().Unchurch()); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Lambda/CombinatorTests.FixedPoint.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LambdaCalculus 2 | { 3 | using System; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.LambdaCalculus; 6 | 7 | [TestClass] 8 | public class FixedPointCombinatorTests 9 | { 10 | [TestMethod] 11 | public void FactorialTest() 12 | { 13 | Func factorial = null; // Must have to be compiled. 14 | factorial = x => x == 0 ? 1U : x * factorial(x - 1U); 15 | 16 | Assert.AreEqual(factorial(0U), 0U.Church().Factorial().Unchurch()); 17 | Assert.AreEqual(factorial(1U), 1U.Church().Factorial().Unchurch()); 18 | Assert.AreEqual(factorial(2U), 2U.Church().Factorial().Unchurch()); 19 | Assert.AreEqual(factorial(3U), 3U.Church().Factorial().Unchurch()); 20 | Assert.AreEqual(factorial(7U), 7U.Church().Factorial().Unchurch()); 21 | } 22 | 23 | [TestMethod] 24 | public void FibonacciTest() 25 | { 26 | Func fibonacci = null; // Must have. So that fibonacci can recursively refer itself. 27 | fibonacci = x => x > 1U ? fibonacci(x - 1) + fibonacci(x - 2) : x; 28 | 29 | Assert.AreEqual(fibonacci(0U), 0U.Church().Fibonacci().Unchurch()); 30 | Assert.AreEqual(fibonacci(1U), 1U.Church().Fibonacci().Unchurch()); 31 | Assert.AreEqual(fibonacci(2U), 2U.Church().Fibonacci().Unchurch()); 32 | Assert.AreEqual(fibonacci(3U), 3U.Church().Fibonacci().Unchurch()); 33 | Assert.AreEqual(fibonacci(8U), 8U.Church().Fibonacci().Unchurch()); 34 | } 35 | 36 | [TestMethod] 37 | public void DivideByTest() 38 | { 39 | Assert.AreEqual(1U / 1U, 1U.Church().DivideBy(1U.Church()).Unchurch()); 40 | Assert.AreEqual(1U / 2U, 1U.Church().DivideBy(2U.Church()).Unchurch()); 41 | Assert.AreEqual(2U / 2U, 2U.Church().DivideBy(2U.Church()).Unchurch()); 42 | Assert.AreEqual(2U / 1U, 2U.Church().DivideBy(1U.Church()).Unchurch()); 43 | Assert.AreEqual(8U / 3U, 8U.Church().DivideBy(3U.Church()).Unchurch()); 44 | Assert.AreEqual(3U / 8U, 3U.Church().DivideBy(8U.Church()).Unchurch()); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Lambda/CombinatorTests.Iota.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LambdaCalculus 2 | { 3 | using System; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.LambdaCalculus; 6 | 7 | [TestClass] 8 | public class IotaCombinatorTests 9 | { 10 | [TestMethod] 11 | public void SkiTests() 12 | { 13 | Func> x1 = a => b => a + b; 14 | Func y1 = a => a + 1; 15 | int z1 = 1; 16 | Assert.AreEqual((int)SkiCombinators.S(x1)(y1)(z1), (int)IotaCalculus.S(x1)(y1)(z1)); 17 | Assert.AreEqual((Func>)SkiCombinators.K(x1)(y1), (Func>)IotaCalculus.K(x1)(y1)); 18 | Assert.AreEqual((Func>)SkiCombinators.I(x1), (Func>)IotaCalculus.I(x1)); 19 | Assert.AreEqual((Func)SkiCombinators.I(y1), (Func)IotaCalculus.I(y1)); 20 | Assert.AreEqual((int)SkiCombinators.I(z1), (int)IotaCalculus.I(z1)); 21 | 22 | string x2 = "a"; 23 | int y2 = 1; 24 | Assert.AreEqual((string)SkiCombinators.K(x2)(y2), (string)IotaCalculus.K(x2)(y2)); 25 | Assert.AreEqual((string)SkiCombinators.I(x2), (string)IotaCalculus.I(x2)); 26 | Assert.AreEqual((int)SkiCombinators.I(y2), (int)IotaCalculus.I(y2)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Lambda/CombinatorsTests.Ski.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LambdaCalculus 2 | { 3 | using System; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.LambdaCalculus; 6 | 7 | [TestClass] 8 | public class SkiCombinatorsTests 9 | { 10 | [TestMethod] 11 | public void SkiTests() 12 | { 13 | Func> x1 = a => b => a + b; 14 | Func y1 = a => a + 1; 15 | int z1 = 1; 16 | Assert.AreEqual(x1(z1)(y1(z1)), (int)SkiCombinators.S(x1)(y1)(z1)); 17 | Assert.AreEqual(x1, (Func>)SkiCombinators.K(x1)(y1)); 18 | Assert.AreEqual(x1, (Func>)SkiCombinators.I(x1)); 19 | Assert.AreEqual(y1, (Func)SkiCombinators.I(y1)); 20 | 21 | string x2 = "a"; 22 | int y2 = 1; 23 | Assert.AreEqual(x2, (string)SkiCombinators.K(x2)(y2)); 24 | Assert.AreEqual(x2, (string)SkiCombinators.I(x2)); 25 | Assert.AreEqual(y2, (int)SkiCombinators.I(y2)); 26 | } 27 | 28 | [TestMethod] 29 | public void BooleanTests() 30 | { 31 | Func> t1 = a => b => a + b; 32 | int f1 = 1; 33 | Assert.AreEqual(ChurchBoolean.True(t1)(f1), SkiCalculus.True(t1)(f1)); 34 | Assert.AreEqual(ChurchBoolean.False(t1)(f1), SkiCalculus.False(t1)(f1)); 35 | 36 | Func t2 = a => a + 1; 37 | int f2 = 2; 38 | Assert.AreEqual(ChurchBoolean.True(t2)(f2), SkiCalculus.True(t2)(f2)); 39 | Assert.AreEqual(ChurchBoolean.False(t2)(f2), SkiCalculus.False(t2)(f2)); 40 | } 41 | 42 | [TestMethod] 43 | public void NumeralTests() 44 | { 45 | Assert.AreEqual(0U, SkiCalculus.UnchurchNumeral(SkiCalculus.Zero)); 46 | Assert.AreEqual(1U, SkiCalculus.UnchurchNumeral(SkiCalculus.One)); 47 | Assert.AreEqual(2U, SkiCalculus.UnchurchNumeral(SkiCalculus.Two)); 48 | Assert.AreEqual(3U, SkiCalculus.UnchurchNumeral(SkiCalculus.Three)); 49 | Assert.AreEqual(4U, SkiCalculus.UnchurchNumeral(SkiCalculus.Increase(SkiCalculus.Three))); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/LoadingTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | 8 | using Tutorial.LinqToEntities; 9 | 10 | [TestClass] 11 | public class LoadingTests 12 | { 13 | [TestMethod] 14 | public void DisposableTest() 15 | { 16 | try 17 | { 18 | Loading.UI.RenderCategoryProducts("Bikes"); 19 | Assert.Fail(); 20 | } 21 | catch (InvalidOperationException exception) 22 | { 23 | Trace.WriteLine(exception); 24 | } 25 | } 26 | 27 | [TestMethod] 28 | public void DeferredExecutionTest() 29 | { 30 | Loading.DeferredExecution(new AdventureWorks()); 31 | } 32 | 33 | [TestMethod] 34 | public void ExplicitLoadingTest() 35 | { 36 | Loading.ExplicitLoading(new AdventureWorks()); 37 | Loading.ExplicitLoadingWithQuery(new AdventureWorks()); 38 | } 39 | 40 | [TestMethod] 41 | public void LazyLoadingTest() 42 | { 43 | Loading.LazyLoading(new AdventureWorks()); 44 | Loading.MultipleLazyLoading(new AdventureWorks()); 45 | } 46 | 47 | [TestMethod] 48 | public void EagerLoadingTest() 49 | { 50 | Loading.EagerLoadingWithInclude(new AdventureWorks()); 51 | Loading.EagerLoadingMultipleLevels(new AdventureWorks()); 52 | Loading.EagerLoadingWithSelect(new AdventureWorks()); 53 | try 54 | { 55 | Loading.ConditionalEagerLoadingWithInclude(new AdventureWorks()); 56 | Assert.Fail(); 57 | } 58 | catch (InvalidOperationException exception) 59 | { 60 | Trace.WriteLine(exception); 61 | } 62 | Loading.ConditionalEagerLoadingWithJoin(new AdventureWorks()); 63 | } 64 | 65 | [TestMethod] 66 | public void DisableLazyLoadingTest() 67 | { 68 | Loading.DisableLazyLoading(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/Manipulation.ChangesTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using Microsoft.EntityFrameworkCore; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Tutorial.LinqToEntities; 8 | 9 | [TestClass] 10 | public class ChangesTests 11 | { 12 | [TestMethod] 13 | public void TrackingTest() 14 | { 15 | Tracking.EntitiesFromSameDbContext(new AdventureWorks()); 16 | Tracking.ObjectsFromSameDbContext(new AdventureWorks()); 17 | Tracking.EntitiesFromMultipleDbContexts(); 18 | Tracking.EntityChanges(new AdventureWorks()); 19 | Tracking.Attach(new AdventureWorks()); 20 | Tracking.RelationshipChanges(new AdventureWorks()); 21 | Tracking.AsNoTracking(new AdventureWorks()); 22 | Tracking.DetectChanges(new AdventureWorks()); 23 | } 24 | 25 | [TestMethod] 26 | public void ChangesTest() 27 | { 28 | ProductCategory category = Changes.Create(); 29 | Changes.Update(category.ProductCategoryID, category.ProductSubcategories.Single().ProductSubcategoryID); 30 | Changes.SaveNoChanges(1); 31 | Changes.UpdateWithoutRead(category.ProductCategoryID); 32 | Changes.Delete(category.ProductSubcategories.Single().ProductSubcategoryID); 33 | Changes.DeleteWithoutRead(category.ProductCategoryID); 34 | try 35 | { 36 | Changes.DeleteWithRelationship(1); 37 | Assert.Fail(); 38 | } 39 | catch (DbUpdateException exception) 40 | { 41 | Trace.WriteLine(exception); 42 | } 43 | category = Changes.Create(); 44 | Changes.DeleteCascade(category.ProductCategoryID); 45 | try 46 | { 47 | Changes.UntrackedChanges(); 48 | Assert.Fail(); 49 | } 50 | catch (DbUpdateException exception) 51 | { 52 | Trace.WriteLine(exception); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/Manipulation.ConcurrencyTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System.Diagnostics; 4 | 5 | using Microsoft.EntityFrameworkCore; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | 8 | using Tutorial.LinqToEntities; 9 | 10 | using static TransactionHelper; 11 | using DbReaderWriter = Tutorial.LinqToEntities.Concurrency.DbReaderWriter; 12 | 13 | [TestClass] 14 | public class ConcurrencyTests 15 | { 16 | [TestMethod] 17 | public void DetectConflictTest() 18 | { 19 | Rollback((adventureWorks1, adventureWorks2, adventureWorks3) => Concurrency.NoCheck(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2), new DbReaderWriter(adventureWorks3))); 20 | Rollback((adventureWorks1, adventureWorks2) => 21 | { 22 | try 23 | { 24 | Concurrency.ConcurrencyCheck(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2)); 25 | Assert.Fail(); 26 | } 27 | catch (DbUpdateConcurrencyException exception) 28 | { 29 | Trace.WriteLine(exception); 30 | } 31 | }); 32 | Rollback((adventureWorks1, adventureWorks2) => 33 | { 34 | try 35 | { 36 | Concurrency.RowVersion(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2)); 37 | Assert.Fail(); 38 | } 39 | catch (DbUpdateConcurrencyException exception) 40 | { 41 | Trace.WriteLine(exception); 42 | } 43 | }); 44 | } 45 | 46 | [TestMethod] 47 | public void UpdateConflictTest() 48 | { 49 | Rollback((adventureWorks1, adventureWorks2, adventureWorks3) => 50 | Concurrency.DatabaseWins(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2), new DbReaderWriter(adventureWorks3))); 51 | Rollback((adventureWorks1, adventureWorks2, adventureWorks3) => 52 | Concurrency.ClientWins(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2), new DbReaderWriter(adventureWorks3))); 53 | Rollback((adventureWorks1, adventureWorks2, adventureWorks3) => 54 | Concurrency.MergeClientAndDatabase(new DbReaderWriter(adventureWorks1), new DbReaderWriter(adventureWorks2), new DbReaderWriter(adventureWorks3))); 55 | Rollback((adventureWorks1, adventureWorks2) => 56 | Concurrency.SaveChanges(adventureWorks1, adventureWorks2)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/Manipulation.TransactionTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | using Tutorial.LinqToEntities; 6 | 7 | [TestClass] 8 | public class TransactionTests 9 | { 10 | [TestMethod] 11 | public void TransactionTest() 12 | { 13 | Transactions.Default(new AdventureWorks()); 14 | Transactions.DbContextTransaction(new AdventureWorks()); 15 | Transactions.DbTransaction(); 16 | Transactions.TransactionScope(new AdventureWorks()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/Modeling.ConnectionStringsTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using Microsoft.Data.SqlClient; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Tutorial.LinqToEntities; 6 | 7 | [TestClass] 8 | public class ConnectionTests 9 | { 10 | [TestMethod] 11 | public void LoadConnectionStringsTest() 12 | { 13 | string connectionString = ConnectionStrings.AdventureWorks; 14 | Assert.IsFalse(string.IsNullOrWhiteSpace(connectionString)); 15 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder() 16 | { 17 | ConnectionString = ConnectionStrings.AdventureWorks 18 | }; 19 | if (!string.IsNullOrWhiteSpace(builder.AttachDBFilename)) 20 | { 21 | Assert.IsFalse(builder.AttachDBFilename.Contains("..")); 22 | } 23 | } 24 | 25 | [TestMethod] 26 | public void OpenConnectionStringsTest() 27 | { 28 | string connectionString = ConnectionStrings.AdventureWorks; 29 | using (SqlConnection connection = new SqlConnection(connectionString)) 30 | { 31 | connection.Open(); 32 | Assert.IsFalse(string.IsNullOrWhiteSpace(connection.ServerVersion)); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/PerformanceTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System.Threading.Tasks; 4 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | using Tutorial.LinqToEntities; 8 | 9 | [TestClass] 10 | public class PerformanceTests 11 | { 12 | [TestMethod] 13 | public void PerformanceTest() 14 | { 15 | Performance.AddRange(); 16 | Performance.RemoveRange(); 17 | } 18 | 19 | [TestMethod] 20 | public void CacheTest() 21 | { 22 | Performance.CachedEntity(new AdventureWorks()); 23 | Performance.UncachedEntity(new AdventureWorks()); 24 | Performance.Find(new AdventureWorks()); 25 | Performance.TranslationCache(new AdventureWorks()); 26 | Performance.UnreusedTranslationCache(new AdventureWorks()); 27 | Performance.ReusedTranslationCache(new AdventureWorks()); 28 | Performance.CompiledReusedTranslationCache(new AdventureWorks()); 29 | Performance.Translation(); 30 | Performance.UnreusedSkipTakeTranslationCache(new AdventureWorks()); 31 | } 32 | 33 | [TestMethod] 34 | public async Task AsyncTransactionTest() 35 | { 36 | await Performance.DbContextTransactionAsync(new AdventureWorks()); 37 | await Performance.DbTransactionAsync(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/QueryExpressionTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.LinqToEntities; 5 | 6 | [TestClass] 7 | public class QueryExpressionTests 8 | { 9 | [TestMethod] 10 | public void JoinTest() 11 | { 12 | QueryExpressions.InnerJoinWithJoin(new AdventureWorks()); 13 | QueryExpressions.InnerJoinWithSelect(new AdventureWorks()); 14 | QueryExpressions.InnerJoinWithSelectMany(new AdventureWorks()); 15 | QueryExpressions.InnerJoinWithSelectAndRelationship(new AdventureWorks()); 16 | QueryExpressions.InnerJoinWithSelectManyAndRelationship(new AdventureWorks()); 17 | QueryExpressions.LeftOuterJoinWithSelectMany(new AdventureWorks()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/QueryTracingTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | using Tutorial.LinqToEntities; 6 | 7 | [TestClass] 8 | public class TracingTests 9 | { 10 | [TestMethod] 11 | public void TracingTest() 12 | { 13 | Tracing.Logger(); 14 | Tracing.TagWith(new AdventureWorks()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/RemoteQueryTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System; 4 | using System.Linq.Expressions; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Tutorial.LinqToEntities; 7 | 8 | [TestClass] 9 | public class BinaryArithmeticTranslatorTests 10 | { 11 | [TestMethod] 12 | public void TranslateToSql() 13 | { 14 | RemoteQueries.Infix(); 15 | 16 | Expression> expression1 = (a, b) => a * a + b * b; 17 | Assert.AreEqual("SELECT ((@a * @a) + (@b * @b));", expression1.InOrder()); 18 | 19 | Expression> expression2 = 20 | (a, b, c, d, e) => a + b - c * d / 2D + e * 3D; 21 | Assert.AreEqual("SELECT (((@a + @b) - ((@c * @d) / 2)) + (@e * 3));", expression2.InOrder()); 22 | } 23 | 24 | [TestMethod] 25 | public void ExecuteSql() 26 | { 27 | RemoteQueries.TranslateAndExecute(); 28 | 29 | Expression> expression1 = (a, b) => a * a + b * b; 30 | Func local1 = expression1.Compile(); 31 | #if !__IOS__ 32 | Func remote1 = expression1.TranslateToSql(ConnectionStrings.AdventureWorks); 33 | Assert.AreEqual(local1(1, 2), remote1(1, 2)); 34 | #endif 35 | 36 | Expression> expression2 = 37 | (a, b, c, d, e) => a + b - c * d / 2D + e * 3D; 38 | Func local2 = expression2.Compile(); 39 | #if !__IOS__ 40 | Func remote2 = expression2.TranslateToSql(ConnectionStrings.AdventureWorks); 41 | Assert.AreEqual(local2(1, 2, 3, 4, 5), remote2(1, 2, 3, 4, 5)); 42 | #endif 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToEntities/TranslationTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToEntities 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | using Tutorial.LinqToEntities; 8 | 9 | [TestClass] 10 | public class TranslationTests 11 | { 12 | [TestMethod] 13 | public void WhereAndSelectTest() 14 | { 15 | Translation.WhereAndSelect(new AdventureWorks()); 16 | Translation.WhereAndSelectLinqExpressions(new AdventureWorks()); 17 | Translation.CompileWhereAndSelectExpressions(new AdventureWorks()); 18 | Translation.WhereAndSelectDatabaseExpressions(new AdventureWorks()); 19 | Translation.WhereAndSelectSql(new AdventureWorks()); 20 | } 21 | 22 | [TestMethod] 23 | public void SelectAndFirstTest() 24 | { 25 | Translation.SelectAndFirst(new AdventureWorks()); 26 | Translation.SelectAndFirstLinqExpressions(new AdventureWorks()); 27 | Translation.CompileSelectAndFirstExpressions(new AdventureWorks()); 28 | Translation.SelectAndFirstDatabaseExpressions(new AdventureWorks()); 29 | Translation.SelectAndFirstSql(new AdventureWorks()); 30 | } 31 | 32 | [TestMethod] 33 | public void ApiTranslationTest() 34 | { 35 | try 36 | { 37 | Translation.WhereAndSelectWithCustomPredicate(new AdventureWorks()); 38 | Assert.Fail(); 39 | } 40 | catch (InvalidOperationException exception) 41 | { 42 | Trace.WriteLine(exception); 43 | } 44 | Translation.WhereAndSelectWithLocalPredicate(new AdventureWorks()); 45 | Translation.DatabaseFunction(new AdventureWorks()); 46 | Translation.DatabaseOperator(new AdventureWorks()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToObjects/DeferredExecutionTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToObjects 2 | { 3 | using System; 4 | using System.Linq; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Tutorial.LinqToObjects; 7 | 8 | [TestClass] 9 | public class DeferredExecutionTests 10 | { 11 | [TestMethod] 12 | public void ReverseTest() 13 | { 14 | int[] enumerable = new int[] { 0, 1, 2 }; 15 | EnumerableAssert.AreSequentialEqual( 16 | Enumerable.Reverse(enumerable), 17 | DeferredExecution.CompiledReverseGenerator(enumerable)); 18 | 19 | enumerable = Array.Empty(); 20 | EnumerableAssert.AreSequentialEqual( 21 | Enumerable.Reverse(enumerable), 22 | DeferredExecution.CompiledReverseGenerator(enumerable)); 23 | } 24 | 25 | [TestMethod] 26 | public void QueryTest() 27 | { 28 | DeferredExecution.CallWhereAndSelect(); 29 | DeferredExecution.CallSelectAndReverse(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToObjects/IteratorPatternTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToObjects 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | using Tutorial.LinqToObjects; 6 | 7 | using Enumerable = System.Linq.Enumerable; 8 | using EnumerableEx = System.Linq.EnumerableEx; 9 | 10 | [TestClass] 11 | public class IteratorPatternTests 12 | { 13 | [TestMethod] 14 | public void EnumerableTest() 15 | { 16 | EnumerableAssert.AreSequentialEqual( 17 | EnumerableEx.Return(1), 18 | Generator.FromValue(1)); 19 | 20 | object value = new object(); 21 | EnumerableAssert.AreSequentialEqual( 22 | EnumerableEx.Return(value), 23 | Generator.FromValue(value)); 24 | } 25 | 26 | [TestMethod] 27 | public void RepeatTest() 28 | { 29 | EnumerableAssert.AreSequentialEqual( 30 | Enumerable.Repeat(1, 5), 31 | Generator.Repeat(1, 5)); 32 | EnumerableAssert.AreSequentialEqual( 33 | Enumerable.Repeat(1, 0), 34 | Generator.Repeat(1, 0)); 35 | EnumerableAssert.AreSequentialEqual( 36 | Enumerable.Repeat(1, 1), 37 | Generator.Repeat(1, 1)); 38 | 39 | object value = new object(); 40 | EnumerableAssert.AreSequentialEqual( 41 | Enumerable.Repeat(value, 10), 42 | Generator.Repeat(value, 10)); 43 | } 44 | 45 | [TestMethod] 46 | public void SelectTest() 47 | { 48 | int[] enumerable = new int[] { 0, 1, 2 }; 49 | EnumerableAssert.AreSequentialEqual( 50 | Enumerable.Select(enumerable, x => x.ToString()), 51 | Generator.Select(enumerable, x => x.ToString())); 52 | 53 | enumerable = new int[] { }; 54 | EnumerableAssert.AreSequentialEqual( 55 | Enumerable.Select(enumerable, x => x.ToString()), 56 | Generator.Select(enumerable, x => x.ToString())); 57 | } 58 | 59 | [TestMethod] 60 | public void WhereTest() 61 | { 62 | int[] enumerable = new int[] { 0, 1, 2 }; 63 | EnumerableAssert.AreSequentialEqual( 64 | Enumerable.Where(enumerable, x => x > 0), 65 | Generator.Where(enumerable, x => x > 0)); 66 | 67 | enumerable = new int[] { }; 68 | EnumerableAssert.AreSequentialEqual( 69 | Enumerable.Where(enumerable, x => x > 0), 70 | Generator.Where(enumerable, x => x > 0)); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToObjects/LinkedListSequenceTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToObjects 2 | { 3 | using System.Collections.Generic; 4 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | using Tutorial.LinqToObjects; 8 | 9 | [TestClass] 10 | public class LinkedListSequenceTests 11 | { 12 | [TestMethod] 13 | public void EmptyTest() 14 | { 15 | IteratorPattern.LinkedListNode head = null; 16 | IteratorPattern.LinkedListSequence sequence = new IteratorPattern.LinkedListSequence(head); 17 | List list = new List(); 18 | foreach (int value in sequence) 19 | { 20 | list.Add(value); 21 | } 22 | 23 | Assert.IsFalse(list.Any()); 24 | } 25 | 26 | [TestMethod] 27 | public void SingleTest() 28 | { 29 | IteratorPattern.LinkedListNode head = new IteratorPattern.LinkedListNode(1); 30 | IteratorPattern.LinkedListSequence sequence = new IteratorPattern.LinkedListSequence(head); 31 | List list = new List(); 32 | foreach (int value in sequence) 33 | { 34 | list.Add(value); 35 | } 36 | 37 | Assert.AreEqual(1, list.Single()); 38 | } 39 | 40 | [TestMethod] 41 | public void MultipleTest() 42 | { 43 | IteratorPattern.LinkedListNode head = new IteratorPattern.LinkedListNode(0, new IteratorPattern.LinkedListNode(1, new IteratorPattern.LinkedListNode(2, new IteratorPattern.LinkedListNode(3)))); 44 | IteratorPattern.LinkedListSequence sequence = new IteratorPattern.LinkedListSequence(head); 45 | List list = new List(); 46 | foreach (int value in sequence) 47 | { 48 | list.Add(value); 49 | } 50 | 51 | EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, list); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToXml/ManipulationTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToXml 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.LinqToXml; 5 | 6 | [TestClass] 7 | public class ManipulationTests 8 | { 9 | [TestMethod] 10 | public void CloneTest() 11 | { 12 | Manipulation.ExplicitClone(); 13 | Manipulation.ImplicitClone(); 14 | } 15 | 16 | [TestMethod] 17 | public void ManipulationTest() 18 | { 19 | Manipulation.Manipulate(); 20 | Manipulation.SetAttributeValue(); 21 | Manipulation.SetElementValue(); 22 | Manipulation.Annotation(); 23 | } 24 | 25 | [TestMethod] 26 | public void TransformTest() 27 | { 28 | Manipulation.XslTransform(); 29 | Manipulation.Transform(); 30 | } 31 | 32 | [TestMethod] 33 | public void ValidateTest() 34 | { 35 | Manipulation.InferSchemas(); 36 | Manipulation.Validate(); 37 | Manipulation.GetSchemaInfo(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToXml/ModelingTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToXml 2 | { 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Xml; 7 | using System.Xml.Linq; 8 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; 10 | using Tutorial.LinqToXml; 11 | 12 | [TestClass] 13 | public class ModelingTests 14 | { 15 | [TestMethod] 16 | public void CreateAndSerializeTest() 17 | { 18 | Modeling.CreateAndSerializeWithDom(); 19 | Modeling.CreateAndSerializeWithLinq(); 20 | Modeling.Construction(); 21 | } 22 | 23 | [TestMethod] 24 | public void ApiTest() 25 | { 26 | Modeling.Name(); 27 | Modeling.Namespace(); 28 | Modeling.Element(); 29 | Modeling.Attribute(); 30 | Modeling.DeepEquals(); 31 | } 32 | 33 | [TestMethod] 34 | public void ReadWriteTest() 35 | { 36 | try 37 | { 38 | Modeling.Read(); 39 | Assert.Fail(); 40 | } 41 | catch (XmlException exception) 42 | { 43 | Trace.WriteLine(exception); 44 | } 45 | IEnumerable items = Modeling.RssItems("https://weblogs.asp.net/dixin/rss"); 46 | Assert.IsTrue(items.Any()); 47 | Modeling.XNodeToString(); 48 | Modeling.Write(); 49 | } 50 | 51 | [TestMethod] 52 | public void StreamingTest() 53 | { 54 | Modeling.StreamingElementWithChildElements(); 55 | Modeling.StreamingElementWithChildElementModification(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/LinqToXml/QueryMethodsTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.LinqToXml 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Xml.XPath; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Tutorial.LinqToXml; 8 | 9 | [TestClass] 10 | public class QueryMethodsTests 11 | { 12 | [TestMethod] 13 | public void NavigationTest() 14 | { 15 | QueryMethods.ParentAndAncestors(); 16 | QueryMethods.ChildElements(); 17 | QueryMethods.ChildrenAndDescendants(); 18 | QueryMethods.ResultReferences(); 19 | } 20 | 21 | [TestMethod] 22 | public void OrderingTest() 23 | { 24 | QueryMethods.DocumentOrder(); 25 | try 26 | { 27 | QueryMethods.CommonAncestor(); 28 | } 29 | catch (InvalidOperationException exception) 30 | { 31 | Trace.WriteLine(exception); 32 | } 33 | } 34 | 35 | [TestMethod] 36 | public void XPathTest() 37 | { 38 | QueryMethods.XPathNavigator(); 39 | QueryMethods.XPathQuery(); 40 | try 41 | { 42 | QueryMethods.XPathQueryWithNamespace(); 43 | Assert.Fail(); 44 | } 45 | catch (XPathException exception) 46 | { 47 | Trace.WriteLine(exception); 48 | } 49 | QueryMethods.XPathEvaluateValue(); 50 | QueryMethods.XPathEvaluateSequence(); 51 | QueryMethods.XPathEvaluateSequenceWithNamespace(); 52 | QueryMethods.GenerateXPath(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/MSTest.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Reflection; 8 | using Microsoft.VisualStudio.TestTools.UnitTesting; 9 | using Tutorial.Tests.Introduction; 10 | 11 | public static class MSTest 12 | { 13 | public static void Run(bool stopWhenFail = false) 14 | { 15 | new OverviewTests().EmailValidationTest(); 16 | List<(MethodInfo, Exception, double)> failed = new List<(MethodInfo, Exception, double)>(); 17 | typeof(MSTest).Assembly.GetTypes() 18 | .Where(type => Attribute.GetCustomAttribute(type, typeof(TestClassAttribute)) != null) 19 | .ForEach(type => 20 | { 21 | Stopwatch stopwatch = Stopwatch.StartNew(); 22 | object instance = Activator.CreateInstance(type); 23 | type.GetMethods(BindingFlags.Public | BindingFlags.Instance) 24 | .Where(method => Attribute.GetCustomAttribute(method, typeof(TestMethodAttribute)) != null) 25 | .ForEach(method => 26 | { 27 | Trace.WriteLine($"Test starts: {type.Name}.{method.Name}".WriteLine()); 28 | try 29 | { 30 | method.Invoke(instance, Array.Empty()); 31 | stopwatch.Stop(); 32 | Trace.WriteLine($"Test passed: {type.Name}.{method.Name} {stopwatch.Elapsed.TotalSeconds}".WriteLine()); 33 | } 34 | catch (Exception exception) 35 | { 36 | stopwatch.Stop(); 37 | failed.Add((method, exception, stopwatch.Elapsed.TotalSeconds)); 38 | Trace.WriteLine($"Test failed: {type.Name}.{method.Name} {stopwatch.Elapsed.TotalSeconds}: {exception} {exception.GetBaseException()}".WriteLine()); 39 | if (stopWhenFail) 40 | { 41 | throw; 42 | } 43 | } 44 | }); 45 | }); 46 | if (failed.Any()) 47 | { 48 | $"Failed tests: {failed.Count}.".WriteLine(); 49 | failed.ForEach(test => $"{test.Item1.DeclaringType.Name}.{test.Item1.Name} {test.Item3}: {test.Item2} {test.Item2.GetBaseException()}".WriteLine()); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/ParallelLinq/PerformanceTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.ParallelLinq 2 | { 3 | using System.Collections.Concurrent; 4 | using System.Linq; 5 | using System.Threading; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Tutorial.ParallelLinq; 8 | 9 | [TestClass] 10 | public class PerformanceTests 11 | { 12 | [TestMethod] 13 | public void ComputingTest() 14 | { 15 | Performance.OrderByTestForSourceCount(); 16 | Performance.OrderByTestForKeySelector(); 17 | } 18 | 19 | [TestMethod] 20 | public void IOTest() 21 | { 22 | Performance.RunDownloadTestWithSmallFiles(); 23 | Performance.RunDownloadTestWithLargeFiles(); 24 | } 25 | 26 | [TestMethod] 27 | public void ForceParallelTest() 28 | { 29 | ConcurrentBag threadIds = new ConcurrentBag(); 30 | int forcedDegreeOfParallelism = 5; 31 | Enumerable.Range(0, forcedDegreeOfParallelism * 10).ForceParallel( 32 | value => threadIds.Add(Thread.CurrentThread.ManagedThreadId + Visualizer.ComputingWorkload()), 33 | forcedDegreeOfParallelism); 34 | Assert.AreEqual(forcedDegreeOfParallelism, threadIds.Distinct().Count()); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/ParallelLinq/QueryMethodsTests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.ParallelLinq 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Tutorial.ParallelLinq; 7 | 8 | [TestClass] 9 | public partial class QueryMethodsTests 10 | { 11 | [TestMethod] 12 | public void QueryTest() 13 | { 14 | QueryMethods.Generation(); 15 | QueryMethods.AsParallelAsSequential(); 16 | QueryMethods.QueryExpression(); 17 | QueryMethods.ForEachForAll(); 18 | QueryMethods.RenderForEachForAllSpans(); 19 | QueryMethods.VisualizeForEachForAll(); 20 | QueryMethods.VisualizeWhereSelect(); 21 | } 22 | 23 | [TestMethod] 24 | public void CancelTest() 25 | { 26 | QueryMethods.Cancel(); 27 | } 28 | 29 | [TestMethod] 30 | public void DegreeOfParallelismTest() 31 | { 32 | QueryMethods.DegreeOfParallelism(); 33 | } 34 | 35 | [TestMethod] 36 | public void ExecutionModeTest() 37 | { 38 | QueryMethods.ExecutionMode(); 39 | } 40 | 41 | [TestMethod] 42 | public void MergeTest() 43 | { 44 | QueryMethods.MergeForSelect(); 45 | QueryMethods.MergeForOrderBy(); 46 | } 47 | 48 | [TestMethod] 49 | public void AggregateTest() 50 | { 51 | QueryMethods.CommutativeAssociative(); 52 | QueryMethods.AggregateCorrectness(); 53 | QueryMethods.VisualizeAggregate(); 54 | QueryMethods.MergeForAggregate(); 55 | } 56 | [TestMethod] 57 | public void OrderingTest() 58 | { 59 | QueryMethods.AsOrdered(); 60 | QueryMethods.AsUnordered(); 61 | QueryMethods.OrderBy(); 62 | QueryMethods.Correctness(); 63 | } 64 | 65 | [TestMethod] 66 | public void PartitionerTest() 67 | { 68 | try 69 | { 70 | Partitioning.QueryOrderablePartitioner(); 71 | Assert.Fail(); 72 | } 73 | catch (InvalidOperationException exception) 74 | { 75 | Trace.WriteLine(exception); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Tutorial.Tests.Shared/Tutorial.Tests.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 70f0418d-8422-4bf5-b539-e9a2d3b2e190 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/AppConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.Uwp 2 | { 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Tutorial.LinqToEntities; 5 | 6 | [TestClass] 7 | public class AppConfig 8 | { 9 | [AssemblyInitialize] 10 | public static void ConnectionString(TestContext _) 11 | { 12 | // UWP does not support LocalDB. 13 | Windows.Storage.ApplicationData.Current.LocalSettings.Values[nameof(AdventureWorks)] = "Server=tcp:dixin.database.windows.net,1433;Initial Catalog=AdventureWorks;Persist Security Info=False;User ID=dixinyan;Password=...;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/StoreLogo.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.Uwp/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | Tutorial.Tests.Uwp 16 | dixin 17 | Assets\StoreLogo.png 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Tests.Uwp")] 4 | -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/Properties/UnitTestApp.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Tutorial.Tests.Uwp/UnitTestApp.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.iOS 2 | { 3 | using Foundation; 4 | using UIKit; 5 | using MonoTouch.NUnit.UI; 6 | 7 | // The UIApplicationDelegate for the application. This class is responsible for launching the 8 | // User Interface of the application, as well as listening (and optionally responding) to 9 | // application events from iOS. 10 | [Register("AppDelegate")] 11 | public partial class AppDelegate : UIApplicationDelegate 12 | { 13 | // class-level declarations 14 | UIWindow window; 15 | TouchRunner runner; 16 | 17 | // 18 | // This method is invoked when the application has loaded and is ready to run. In this 19 | // method you should instantiate the window, load the UI into it and then make the window 20 | // visible. 21 | // 22 | // You have 17 seconds to return from this method, or iOS will terminate your application. 23 | // 24 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 25 | { 26 | // create a new window instance based on the screen size 27 | window = new UIWindow(UIScreen.MainScreen.Bounds); 28 | runner = new TouchRunner(window); 29 | 30 | // register every tests included in the main application/assembly 31 | runner.Add(System.Reflection.Assembly.GetExecutingAssembly()); 32 | 33 | window.RootViewController = new UINavigationController(runner.GetViewController()); 34 | 35 | // make the window visible 36 | window.MakeKeyAndVisible(); 37 | 38 | return true; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | Tutorial.Tests.iOS 7 | CFBundleIdentifier 8 | com.your-company.Tutorial.Tests.iOS 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | UIDeviceFamily 14 | 15 | 1 16 | 2 17 | 18 | UISupportedInterfaceOrientations 19 | 20 | UIInterfaceOrientationPortrait 21 | UIInterfaceOrientationLandscapeLeft 22 | UIInterfaceOrientationLandscapeRight 23 | 24 | UISupportedInterfaceOrientations~ipad 25 | 26 | UIInterfaceOrientationPortrait 27 | UIInterfaceOrientationPortraitUpsideDown 28 | UIInterfaceOrientationLandscapeLeft 29 | UIInterfaceOrientationLandscapeRight 30 | 31 | MinimumOSVersion 32 | 10.0 33 | NSAppTransportSecurity 34 | 35 | NSAllowsArbitraryLoads 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace Tutorial.Tests.iOS 4 | { 5 | public class Application 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, "AppDelegate"); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Tutorial.Tests.iOS")] 4 | 5 | -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.iOS/Resources/Default.png -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Tests.iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /Tutorial.Tests.iOS/Tests.cs: -------------------------------------------------------------------------------- 1 | namespace Tutorial.Tests.iOS 2 | { 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class Tests 7 | { 8 | [Test] 9 | public void Test() => MSTest.Run(); 10 | } 11 | } -------------------------------------------------------------------------------- /Tutorial.Uwp/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/StoreLogo.png -------------------------------------------------------------------------------- /Tutorial.Uwp/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dixin/FunctionalProgramming-LINQ/58d2f2a9976da5ce62694588327e16c001cfb46f/Tutorial.Uwp/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /Tutorial.Uwp/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 |