Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net interview tech assessments #271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ build/
# Package Files #
*.jar

*.log
*.log
/dot-net/UnitTesting/.vs/WriteUnitTest/v15/Server/sqlite3
/dot-net/UnitTesting/WriteUnitTest/obj/Debug
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using WriteUnitTest.Services;
using WriteUnitTest.Entities;

namespace WriteUnitTest.UnitTests.Services
{
[TestClass]
public class LessonServiceUnitTests
{
[TestMethod]
public void UpdateLessonGrade_Test()
private LessonService service = null;

public LessonServiceUnitTests()
{
this.service = new LessonService();
}

[Theory]
[InlineData(12, 80.0d, true)]
[InlineData(46, 65.0d, false)]
public void UpdateLessonGrade_Validate_IsPassed_Test(int lessonId, double grade, bool expected)
{
var lesson = this.service.UpdateLessonGrade(lessonId, grade);

Assert.Equal(expected, lesson.IsPassed);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props" Condition="Exists('..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props')" />
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -16,6 +19,8 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -35,26 +40,47 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Services\LessonServiceUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WriteUnitTest\WriteUnitTest.csproj">
<Project>{00a40a05-8314-4f25-a444-46ddeac3497e}</Project>
<Name>WriteUnitTest</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand All @@ -75,6 +101,16 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
12 changes: 12 additions & 0 deletions dot-net/UnitTesting/WriteUnitTest.UnitTests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.4.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
<package id="xunit.assert" version="2.4.1" targetFramework="net461" />
<package id="xunit.core" version="2.4.1" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net461" />
<package id="xunit.runner.console" version="2.4.1" targetFramework="net461" developmentDependency="true" />
<package id="xunit.runner.visualstudio" version="2.4.1" targetFramework="net461" developmentDependency="true" />
</packages>
1 change: 1 addition & 0 deletions dot-net/UnitTesting/WriteUnitTest/Entities/Lesson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class Lesson
{
public int ModuleId;
public int LessonId;
public double Grade;
public bool IsPassed;
Expand Down
12 changes: 11 additions & 1 deletion dot-net/UnitTesting/WriteUnitTest/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ Background Information:
written and run by software developers to ensure that code meets its design
and behaves as intended.

Module - a collection of lessons
Module - a collection of lessons

NOTES:
* Installed xUnit. It's more robust and modern.
* Can write/run parameterized tests. Numerous test methods, each for different parameters, are not needed and consequently simplifies test writing.
* Removed Lesson list from Module. Added ModuleId to Lesson. This was done to
centralize data for this simple scenario.
* For a real-world application, the service, repositories and entities need to be
fleshed out using interfaces and dependency injection. Each area of concern placed
in their separate components.
* Interfaces would allow for use of mock repositories and db contexts within unit tests.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public LessonRepository()
{
new Lesson
{
ModuleId = 873,
LessonId = 12,
Grade = 63.7d,
IsPassed = false
},
new Lesson
{
ModuleId = 873,
LessonId = 46,
Grade = 0.0d,
IsPassed = false
Expand Down
21 changes: 3 additions & 18 deletions dot-net/UnitTesting/WriteUnitTest/Repositories/ModuleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,14 @@ public ModuleRepository()
new Module
{
ModuleId = 873,
MinimumPassingGrade = 80,
Lessons = new List<Lesson>
{
new Lesson
{
LessonId = 12,
Grade = 63.7d,
IsPassed = false
},
new Lesson
{
LessonId = 86,
Grade = 88.2d,
IsPassed = true
}
}
MinimumPassingGrade = 80
}
};
}

public Module GetModule(int lessonId)
public Module GetModule(int moduleId)
{
return moduleList.FirstOrDefault(x => x.Lessons.Any(y => y.LessonId == lessonId));
return moduleList.FirstOrDefault(x => x.ModuleId == moduleId);
}
}
}
16 changes: 6 additions & 10 deletions dot-net/UnitTesting/WriteUnitTest/Services/LessonService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WriteUnitTest.Repositories;
using WriteUnitTest.Entities;

namespace WriteUnitTest.Services
{
Expand All @@ -8,7 +9,7 @@ public LessonService()
{
}

public void UpdateLessonGrade(int lessonId, double grade)
public Lesson UpdateLessonGrade(int lessonId, double grade)
{
var lessonRepo = new LessonRepository();
var lesson = lessonRepo.GetLesson(lessonId);
Expand All @@ -18,17 +19,12 @@ public void UpdateLessonGrade(int lessonId, double grade)
if (!lesson.IsPassed)
{
var moduleRepository = new ModuleRepository();
var module = moduleRepository.GetModule(lessonId);
var module = moduleRepository.GetModule(lesson.ModuleId);

if (grade >= module.MinimumPassingGrade)
{
lesson.IsPassed = true;
}
else
{
lesson.IsPassed = false;
}
lesson.IsPassed = (grade >= module.MinimumPassingGrade);
}

return lesson;
}
}
}
12 changes: 11 additions & 1 deletion dot-net/WhatWouldYouChange/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@


Suggested Changes:

* Program.cs
* Missing dot in file name
* ExampleClass.cs
* Check if file exists before attempting to open/read.
* Use using statement for `fs` and `streamReader` to ensure resources are disposed and the file is closed.
* For `File.Open`, use `FileShare.Read` to allow multiple opening of the file by the current process or other processes.
* In catch statement, use either the `@` symbol (verbatim string) or StringBuilder. Preferably use verbatim for ease of development and readability. Also, verbatim would be more performant than standard string concatenation. However, if remaining with string concatenation, use `+=` for ease of development.
* When setting `exampleText`, use `this.` to indicate it's scope as a class property.
* Create an async version of `ExampleMethod` to read a potentially large file asynchronously which would improve performance. Use `ReadToEndAsync` along with async/await and use TPL in Program.cs.
* Place the `catch` text into either a const variable, resource file or config file to centralize the string and prevent duplicate code.
* If `exampleText` is not going to be utilized elsewhere, return the text result from `ExampleMethod` instead because `exampleText` is unnecessarily using resources.
2 changes: 2 additions & 0 deletions javascript/SMART-on-FHIR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Notes
From a terminal, cd to the chrisdeyloff-smart-fhir-api dir run `npm install` and run `npm start`, it will run on port 3000. Then cd to to chrisdeyloff-smart-fhir dir run `npm install` and run `npm start`, it will start the react ui in a browser which will run on port 3001.
27 changes: 0 additions & 27 deletions javascript/SMART-on-FHIR/Test.md

This file was deleted.

16 changes: 16 additions & 0 deletions javascript/SMART-on-FHIR/chrisdeyloff-smart-fhir-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Design Notes

I used various existing libraries, such as, express and axios. The code files are somewhat organized but could be improved for real-world app. Axios and async/await are used to streamline http requests to FHIR. Error handling is very simplistic as well and would need to be built out for a real-world app. Unit tests would need to written. Express CORS is initialized to allow the front-end to access the API.

## Project Notes

This project was created using [express-generator].

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
The API will run on [http://localhost:3000](http://localhost:3000).
42 changes: 42 additions & 0 deletions javascript/SMART-on-FHIR/chrisdeyloff-smart-fhir-api/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//SET DEBUG=chrisdeyloff-smart-fhir-api:* & npm start
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var patientRouter = require('./routes/patient');

var app = express();


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.use('/patient', patientRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.send('error');
});

module.exports = app;
Loading