Compare commits
25 Commits
2b07530bb3
...
a6172977f0
Author | SHA1 | Date |
---|---|---|
jason.zhu | a6172977f0 | |
jason.zhu | afb9c79906 | |
jason.zhu | ae5b27fd2f | |
jason.zhu | 3b7e226312 | |
jason.zhu | fe0727fb03 | |
jason.zhu | fc7844c6bc | |
jason.zhu | 15bd8fcbb5 | |
jason.zhu | 5ea0c1bd54 | |
jason.zhu | 8d917a0c57 | |
jason.zhu | bd3087bde2 | |
jason.zhu | 93db36a149 | |
jason.zhu | 3894e9370f | |
jason.zhu | 6442df3678 | |
jason.zhu | 48b6f32021 | |
jason.zhu | 4503e7f324 | |
jason.zhu | bab4544e8c | |
jason.zhu | 634850f8f6 | |
jason.zhu | eaa392ead4 | |
jason.zhu | b88985d236 | |
jason.zhu | eedc0c5329 | |
jason.zhu | 4fe8c1f2bb | |
jason.zhu | 0d8548d380 | |
jason.zhu | 0bb17c73ef | |
jason.zhu | 55d59b3fed | |
jason.zhu | f9b0331ecc |
|
@ -0,0 +1,23 @@
|
|||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/dotnet/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] .NET version: 5.0, 3.1, 2.1
|
||||
ARG VARIANT="5.0"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/dotnetcore:0-${VARIANT}
|
||||
|
||||
# [Option] Install Node.js
|
||||
ARG INSTALL_NODE="true"
|
||||
ARG NODE_VERSION="lts/*"
|
||||
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
||||
|
||||
# [Option] Install Azure CLI
|
||||
ARG INSTALL_AZURE_CLI="false"
|
||||
COPY library-scripts/azcli-debian.sh /tmp/library-scripts/
|
||||
RUN if [ "$INSTALL_AZURE_CLI" = "true" ]; then bash /tmp/library-scripts/azcli-debian.sh; fi \
|
||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
&& apt-get -y install --no-install-recommends tree
|
||||
|
||||
# [Optional] Uncomment this line to install global node packages.
|
||||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
|
@ -0,0 +1,58 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/dotnet
|
||||
{
|
||||
"name": "C# (.NET)",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"args": {
|
||||
// Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1, 5.0
|
||||
"VARIANT": "5.0",
|
||||
// Options
|
||||
"INSTALL_NODE": "true",
|
||||
"NODE_VERSION": "lts/*",
|
||||
"INSTALL_AZURE_CLI": "false"
|
||||
}
|
||||
},
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/bash"
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-dotnettools.csharp"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [5000, 5001],
|
||||
|
||||
// [Optional] To reuse of your local HTTPS dev cert:
|
||||
//
|
||||
// 1. Export it locally using this command:
|
||||
// * Windows PowerShell:
|
||||
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
|
||||
// * macOS/Linux terminal:
|
||||
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
|
||||
//
|
||||
// 2. Uncomment these 'remoteEnv' lines:
|
||||
// "remoteEnv": {
|
||||
// "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere",
|
||||
// "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx",
|
||||
// },
|
||||
//
|
||||
// 3. Do one of the following depending on your scenario:
|
||||
// * When using GitHub Codespaces and/or Remote - Containers:
|
||||
// 1. Start the container
|
||||
// 2. Drag ~/.aspnet/https/aspnetapp.pfx into the root of the file explorer
|
||||
// 3. Open a terminal in VS Code and run "mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https"
|
||||
//
|
||||
// * If only using Remote - Containers with a local container, uncomment this line instead:
|
||||
// "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "dotnet restore",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "vscode"
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/azcli.md
|
||||
#
|
||||
# Syntax: ./azcli-debian.sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install curl, apt-transport-https, lsb-release, or gpg if missing
|
||||
if ! dpkg -s apt-transport-https curl ca-certificates lsb-release > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then
|
||||
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
|
||||
apt-get update
|
||||
fi
|
||||
apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release gnupg2
|
||||
fi
|
||||
|
||||
# Install the Azure CLI
|
||||
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list
|
||||
curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT)
|
||||
apt-get update
|
||||
apt-get install -y azure-cli
|
||||
echo "Done!"
|
|
@ -0,0 +1,738 @@
|
|||
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,executable,csharp,aspnetcore,visualstudio
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,macos,linux,executable,csharp,aspnetcore,visualstudio
|
||||
|
||||
### ASPNETCore ###
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/
|
||||
|
||||
### Csharp ###
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
|
||||
# NUnit
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_h.h
|
||||
*.iobj
|
||||
*.ipdb
|
||||
*_wpftmp.csproj
|
||||
|
||||
# Chutzpah Test files
|
||||
|
||||
# Visual C++ cache files
|
||||
|
||||
# Visual Studio profiler
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
|
||||
# TeamCity is a build add-in
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*[.json, .xml, .info]
|
||||
|
||||
# Visual Studio code coverage results
|
||||
|
||||
# NCrunch
|
||||
|
||||
# MightyMoose
|
||||
|
||||
# Web workbench (sass)
|
||||
|
||||
# Installshield output folder
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
|
||||
# Click-Once directory
|
||||
|
||||
# Publish Web Output
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
|
||||
# NuGet Packages
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
|
||||
# Windows Store app package directories and files
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
|
||||
# RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
|
||||
# Visual Studio 6 build log
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
|
||||
# Paket dependency manager
|
||||
|
||||
# FAKE - F# Make
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
### Executable ###
|
||||
*.app
|
||||
*.bat
|
||||
*.cgi
|
||||
*.com
|
||||
*.exe
|
||||
*.gadget
|
||||
*.jar
|
||||
*.pif
|
||||
*.vb
|
||||
*.wsf
|
||||
|
||||
### Linux ###
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
*.code-workspace
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### VisualStudio ###
|
||||
|
||||
# User-specific files
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
|
||||
# Mono auto generated files
|
||||
|
||||
# Build results
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
|
||||
# MSTest test Results
|
||||
|
||||
# NUnit
|
||||
|
||||
# Build Results of an ATL Project
|
||||
|
||||
# Benchmark Results
|
||||
|
||||
# .NET Core
|
||||
|
||||
# StyleCop
|
||||
|
||||
# Files built by Visual Studio
|
||||
|
||||
# Chutzpah Test files
|
||||
|
||||
# Visual C++ cache files
|
||||
|
||||
# Visual Studio profiler
|
||||
|
||||
# Visual Studio Trace Files
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
|
||||
# TeamCity is a build add-in
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
|
||||
# Visual Studio code coverage results
|
||||
|
||||
# NCrunch
|
||||
|
||||
# MightyMoose
|
||||
|
||||
# Web workbench (sass)
|
||||
|
||||
# Installshield output folder
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
|
||||
# Click-Once directory
|
||||
|
||||
# Publish Web Output
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
|
||||
# NuGet Packages
|
||||
# NuGet Symbol Packages
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
# except build/, which is used as an MSBuild target.
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
|
||||
# Windows Store app package directories and files
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
# but keep track of directories ending in .cache
|
||||
|
||||
# Others
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
|
||||
# RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
|
||||
# SQL Server files
|
||||
|
||||
# Business Intelligence projects
|
||||
|
||||
# Microsoft Fakes
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
|
||||
# Visual Studio 6 build log
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
|
||||
# Paket dependency manager
|
||||
|
||||
# FAKE - F# Make
|
||||
|
||||
# CodeRush personal settings
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
|
||||
# BizTalk build output
|
||||
|
||||
# OpenCover UI analysis results
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
|
||||
# Local History for Visual Studio
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,executable,csharp,aspnetcore,visualstudio
|
||||
|
||||
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"OS-COMMENT1": "Use IntelliSense to find out which attributes exist for C# debugging",
|
||||
"OS-COMMENT2": "Use hover for the description of the existing attributes",
|
||||
"OS-COMMENT3": "For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md",
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"OS-COMMENT4": "If you have changed target frameworks, make sure to update the program path.",
|
||||
"program": "${workspaceFolder}/gradebook/src/GradeBook/bin/Debug/net5.0/GradeBook.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/gradebook/src/GradeBook",
|
||||
"OS-COMMENT5": "For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console",
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/gradebook/src/GradeBook/GradeBook.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/gradebook/src/GradeBook/GradeBook.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/gradebook/src/GradeBook/GradeBook.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
# GradeBook
|
||||
|
||||
Requirement from PM:
|
||||
|
||||
> We need an electronic grade book to read the scores of an individual student and then compute some simple statistics from the scores.
|
||||
> The grades are entered as floating point numbers from 0 to 100, and the statistics show us the highest grade, the lowest grade, and the average grade.
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{41D689B9-3B52-432B-97EF-63FB665C1AA7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBook", "src\GradeBook\GradeBook.csproj", "{B67A3D2F-4755-46E6-960C-8746BADB002C}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C32AB033-6E6D-4451-9194-0F6933BC383D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBook.Tests", "test\GradeBook.Tests\GradeBook.Tests.csproj", "{203083CF-9050-48AC-87CC-53AF6F8F79BE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{B67A3D2F-4755-46E6-960C-8746BADB002C} = {41D689B9-3B52-432B-97EF-63FB665C1AA7}
|
||||
{203083CF-9050-48AC-87CC-53AF6F8F79BE} = {C32AB033-6E6D-4451-9194-0F6933BC383D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GradeBook
|
||||
{
|
||||
public delegate void GradeAddedDelegate(object sender, EventArgs args);
|
||||
|
||||
public class Book
|
||||
{
|
||||
private List<double> grades;
|
||||
|
||||
readonly string category;
|
||||
|
||||
private string name;
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Book(string name)
|
||||
{
|
||||
Name = name;
|
||||
grades = new List<double>();
|
||||
}
|
||||
|
||||
public void AddGrade(double grade)
|
||||
{
|
||||
if (grade <= 100 && grade >= 0)
|
||||
{
|
||||
this.grades.Add(grade);
|
||||
|
||||
if (GradeAdded != null)
|
||||
{
|
||||
// Somebody is listening/subscribing
|
||||
GradeAdded(this, new EventArgs()); // sender = this, pass; Raising event
|
||||
}
|
||||
} else
|
||||
{
|
||||
throw new ArgumentException($"Invalid {nameof(grade)}");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddGrade(char letter)
|
||||
{
|
||||
switch (letter)
|
||||
{
|
||||
case 'A':
|
||||
AddGrade(90);
|
||||
break;
|
||||
case 'B':
|
||||
AddGrade(80);
|
||||
break;
|
||||
case 'C':
|
||||
AddGrade(70);
|
||||
break;
|
||||
default:
|
||||
AddGrade(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public event GradeAddedDelegate GradeAdded;
|
||||
|
||||
public Statistics GetStatistics()
|
||||
{
|
||||
var result = new Statistics();
|
||||
result.Average = 0.0;
|
||||
result.highGrade = double.MinValue;
|
||||
result.lowGrade = double.MaxValue;
|
||||
|
||||
foreach (var grade in this.grades)
|
||||
{
|
||||
result.lowGrade = Math.Min(grade, result.lowGrade);
|
||||
result.highGrade = Math.Max(grade, result.highGrade);
|
||||
result.Average += grade;
|
||||
}
|
||||
|
||||
result.Average /= grades.Count;
|
||||
|
||||
switch (result.Average)
|
||||
{
|
||||
case var d when d >= 90.0:
|
||||
result.Letter = 'A';
|
||||
break;
|
||||
case var d when d >= 80.0:
|
||||
result.Letter = 'B';
|
||||
break;
|
||||
case var d when d >= 70.0:
|
||||
result.Letter = 'C';
|
||||
break;
|
||||
case var d when d >= 60.0:
|
||||
result.Letter = 'D';
|
||||
break;
|
||||
default:
|
||||
result.Letter = 'F';
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GradeBook
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
// var book = new Book("Scott's Grade Book");
|
||||
// book.AddGrade(89.1);
|
||||
// book.AddGrade(90.5);
|
||||
// book.AddGrade(87.2);
|
||||
|
||||
var book = new Book("Jason's Grade Book");
|
||||
book.GradeAdded += OnGradeAdded;
|
||||
book.GradeAdded += OnGradeAdded;
|
||||
book.GradeAdded -= OnGradeAdded;
|
||||
book.GradeAdded -= OnGradeAdded;
|
||||
|
||||
string input;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("Give input: ");
|
||||
input = Console.ReadLine();
|
||||
if (input == "Q" || input == "q")
|
||||
{
|
||||
Console.WriteLine("Receiving termination signal; Termiate program");
|
||||
break;
|
||||
} else
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"Received: {input}");
|
||||
book.AddGrade(Convert.ToDouble(input));
|
||||
// book.AddGrade('A');
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Will always run for all catch scenario
|
||||
Console.WriteLine("Always Done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var stats = book.GetStatistics();
|
||||
|
||||
Console.WriteLine($"The lowest grade is {stats.lowGrade}");
|
||||
Console.WriteLine($"The highesst grade is {stats.highGrade}");
|
||||
Console.WriteLine($"The average grade is {stats.Average:N1}");
|
||||
}
|
||||
|
||||
static void OnGradeAdded(object sender, EventArgs e)
|
||||
{
|
||||
// Main is static, so it can only call static methods, hence return type is static
|
||||
Console.WriteLine("A line has added");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace GradeBook
|
||||
{
|
||||
public class Statistics
|
||||
{
|
||||
public double Average;
|
||||
public double highGrade;
|
||||
public double lowGrade;
|
||||
public char Letter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace GradeBook.Tests
|
||||
{
|
||||
public class BookTests
|
||||
{
|
||||
[Fact]
|
||||
public void BookCalculateAnAverageGrade()
|
||||
{
|
||||
// arrange
|
||||
var book = new Book("");
|
||||
book.AddGrade(89.1);
|
||||
book.AddGrade(90.5);
|
||||
book.AddGrade(77.3);
|
||||
|
||||
// act
|
||||
var result = book.GetStatistics();
|
||||
|
||||
// assert
|
||||
Assert.Equal(85.6, result.Average, 1);
|
||||
Assert.Equal(90.5, result.highGrade);
|
||||
Assert.Equal(77.3, result.lowGrade);
|
||||
Assert.Equal('B', result.Letter);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\GradeBook\GradeBook.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace GradeBook.Tests
|
||||
{
|
||||
using GradeBook;
|
||||
|
||||
public delegate string WriteLogDelegate(string logMessage);
|
||||
|
||||
public class TypeTests
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
[Fact]
|
||||
public void WriteLogDelegateCanPointToMethod()
|
||||
{
|
||||
string msg = "test";
|
||||
|
||||
WriteLogDelegate log = new WriteLogDelegate(ReturnMessage); // Instantiate a delegate
|
||||
log += ReturnMessage2; // Multi-cast delegate
|
||||
var result = log(msg); // Invoking a delegate
|
||||
Assert.Equal(result, msg);
|
||||
Assert.Equal(count, 2);
|
||||
}
|
||||
|
||||
string ReturnMessage(string message)
|
||||
{
|
||||
count += 1;
|
||||
return message;
|
||||
}
|
||||
string ReturnMessage2(string message)
|
||||
{
|
||||
count += 1;
|
||||
return message;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValueTypesAlsoPassByValue()
|
||||
{
|
||||
var x = GetInt();
|
||||
Assert.Equal(3,x);
|
||||
|
||||
SetInt(ref x);
|
||||
Assert.Equal(42, x);
|
||||
}
|
||||
|
||||
private void SetInt(ref int x)
|
||||
{
|
||||
x = 42;
|
||||
}
|
||||
|
||||
private int GetInt()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringsBehaveLikeValueTypes()
|
||||
{
|
||||
string name = "Jason";
|
||||
MakeUppserCase(name); // try to change String like a reference
|
||||
|
||||
Assert.Equal("Jason", name); // ToUpper does not work on String, although it's reference. It's copied as value
|
||||
}
|
||||
|
||||
private void MakeUppserCase(string arg)
|
||||
{
|
||||
arg.ToUpper();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCanPassByReference()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
GetBookSetName(ref book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "New Name");
|
||||
}
|
||||
|
||||
private void GetBookSetName(ref Book book, string name)
|
||||
{
|
||||
book = new Book(name);
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpIsPassByValue()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
GetBookSetName(book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "Book1");
|
||||
}
|
||||
|
||||
private void GetBookSetName(Book book, string name)
|
||||
{
|
||||
book = new Book(name);
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSetNameFromReference()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
SetName(book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "New Name");
|
||||
}
|
||||
|
||||
private void SetName(Book book, string name)
|
||||
{
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetBookReturnsDifferentObjects()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
var book2 = GetBook("Book2");
|
||||
|
||||
Assert.Equal("Book1", book1.Name);
|
||||
Assert.Equal("Book2", book2.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoVarsCanReferenceSameObject()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
var book2 = book1;
|
||||
|
||||
Assert.Equal(book2.Name, book1.Name);
|
||||
Assert.True(Object.ReferenceEquals(book1, book2));
|
||||
}
|
||||
|
||||
|
||||
private Book GetBook(string name)
|
||||
{
|
||||
return new Book(name);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue