Skip to content
Merged
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
28 changes: 28 additions & 0 deletions dotnet/.editorconfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
; EditorConfig to support per-solution formatting.
; Use the EditorConfig VS add-in to make this work.
; http://editorconfig.org/
;
; Here are some resources for what's supported for .NET/C#
; https://kent-boogaart.com/blog/editorconfig-reference-for-c-developers
; https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
;
; Be **careful** editing this because some of the rules don't support adding a severity level
; For instance if you change to `dotnet_sort_system_directives_first = true:warning` (adding `:warning`)
; then the rule will be silently ignored.

; This is the default for the codeline.
root = true

[*]
indent_style = space
charset = utf-8-bom
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[*.{cs,sln}]
indent_size = 4
dotnet_sort_system_directives_first = true

[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks,json,md,ts,csroj}]
indent_size = 2
4 changes: 4 additions & 0 deletions dotnet/.gitignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
.vs/
Debug/
Release/
obj/
32 changes: 32 additions & 0 deletions dotnet/CodeCoverage.runsettings
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*KeepTrack\..*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*KeepTrack.*Tests\.dll$</ModulePath>
<ModulePath>.*Moq.*</ModulePath>
</Exclude>
</ModulePaths>
<Attributes>
<Exclude>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
61 changes: 61 additions & 0 deletions dotnet/KeepTrack.sln
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29409.12
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dal.MongoDb", "src\Dal.MongoDb\Dal.MongoDb.csproj", "{6A10979B-FBAE-488A-B5BC-0E45716DFE88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{215584EC-8DFC-4DAD-B3A0-D419CEC24260}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Applications", "Applications", "{61C528CD-816E-4FC5-ADFA-C5C25A3C4052}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{59B2BDBC-F7DE-47F8-880E-248202630B1A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Car", "Car", "{A52EF787-A7DD-4F2F-99B1-9A62CBE1DE5B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Movie", "Movie", "{A6A8275A-6360-43E7-AB5A-D8A1E96BED06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "src\ConsoleApp\ConsoleApp.csproj", "{09DBB876-546F-40EF-B1D8-D0FDAE02E80D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarComponent.Domain", "src\CarComponent.Domain\CarComponent.Domain.csproj", "{A2193B19-8191-4A28-9E64-23D9083A0531}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarComponent.Infrastructure.MongoDb", "src\CarComponent.Infrastructure.MongoDb\CarComponent.Infrastructure.MongoDb.csproj", "{F7250DAA-718B-44FB-990B-AD7DFC488AA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6A10979B-FBAE-488A-B5BC-0E45716DFE88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A10979B-FBAE-488A-B5BC-0E45716DFE88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A10979B-FBAE-488A-B5BC-0E45716DFE88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A10979B-FBAE-488A-B5BC-0E45716DFE88}.Release|Any CPU.Build.0 = Release|Any CPU
{09DBB876-546F-40EF-B1D8-D0FDAE02E80D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09DBB876-546F-40EF-B1D8-D0FDAE02E80D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09DBB876-546F-40EF-B1D8-D0FDAE02E80D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09DBB876-546F-40EF-B1D8-D0FDAE02E80D}.Release|Any CPU.Build.0 = Release|Any CPU
{A2193B19-8191-4A28-9E64-23D9083A0531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2193B19-8191-4A28-9E64-23D9083A0531}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2193B19-8191-4A28-9E64-23D9083A0531}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2193B19-8191-4A28-9E64-23D9083A0531}.Release|Any CPU.Build.0 = Release|Any CPU
{F7250DAA-718B-44FB-990B-AD7DFC488AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7250DAA-718B-44FB-990B-AD7DFC488AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7250DAA-718B-44FB-990B-AD7DFC488AA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7250DAA-718B-44FB-990B-AD7DFC488AA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6A10979B-FBAE-488A-B5BC-0E45716DFE88} = {215584EC-8DFC-4DAD-B3A0-D419CEC24260}
{A52EF787-A7DD-4F2F-99B1-9A62CBE1DE5B} = {59B2BDBC-F7DE-47F8-880E-248202630B1A}
{A6A8275A-6360-43E7-AB5A-D8A1E96BED06} = {59B2BDBC-F7DE-47F8-880E-248202630B1A}
{09DBB876-546F-40EF-B1D8-D0FDAE02E80D} = {61C528CD-816E-4FC5-ADFA-C5C25A3C4052}
{A2193B19-8191-4A28-9E64-23D9083A0531} = {A52EF787-A7DD-4F2F-99B1-9A62CBE1DE5B}
{F7250DAA-718B-44FB-990B-AD7DFC488AA7} = {A52EF787-A7DD-4F2F-99B1-9A62CBE1DE5B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {876333E7-72D4-4F43-B6F9-9432CA2B7425}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions dotnet/src/CarComponent.Domain/CarComponent.Domain.csproj
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>KeepTrack.CarComponent.Domain</AssemblyName>
<RootNamespace>KeepTrack.CarComponent.Domain</RootNamespace>
<ProjectGuid>{A2193B19-8191-4A28-9E64-23D9083A0531}</ProjectGuid>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

</Project>
11 changes: 11 additions & 0 deletions dotnet/src/CarComponent.Domain/CarHistoryModel.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
using System;

namespace KeepTrack.CarComponent.Domain
{
public class CarHistoryModel
{
public string Id { get; set; }
public string CarId { get; set; }
public DateTime HistoryDate { get; set; }
}
}
13 changes: 13 additions & 0 deletions dotnet/src/CarComponent.Domain/CarModel.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
namespace KeepTrack.CarComponent.Domain
{
public class CarModel
{
public string Id { get; set; }
public string Name { get; set; }

public override string ToString()
{
return $"Car ID=\"{Id}\", Name=\"{Name}\"";
}
}
}
11 changes: 11 additions & 0 deletions dotnet/src/CarComponent.Domain/ICarHistoryRepository.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace KeepTrack.CarComponent.Domain
{
public interface ICarHistoryRepository
{
Task<CarHistoryModel> FindOneAsync(string id);
Task<List<CarHistoryModel>> FindAllAsync(string carId);
}
}
9 changes: 9 additions & 0 deletions dotnet/src/CarComponent.Domain/ICarRepository.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace KeepTrack.CarComponent.Domain
{
public interface ICarRepository
{
Task<CarModel> FindOneAsync(string id);
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>KeepTrack.CarComponent.Infrastructure.MongoDb</AssemblyName>
<RootNamespace>KeepTrack.CarComponent.Infrastructure.MongoDb</RootNamespace>
<ProjectGuid>{F7250DAA-718B-44FB-990B-AD7DFC488AA7}</ProjectGuid>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Withywoods.Dal.MongoDb" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CarComponent.Domain\CarComponent.Domain.csproj" />
</ItemGroup>

</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace KeepTrack.CarComponent.Infrastructure.MongoDb.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddCarInfrastructureMongoDb(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

services.TryAddTransient<Domain.ICarRepository, Repositories.CarRepository>();
services.TryAddTransient<Domain.ICarHistoryRepository, Repositories.CarHistoryRepository>();

return services;
}
}
}
13 changes: 13 additions & 0 deletions dotnet/src/CarComponent.Infrastructure.MongoDb/Entities/Car.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace KeepTrack.CarComponent.Infrastructure.MongoDb.Entities
{
public class Car
{
[BsonId]
public string Id { get; set; }
[BsonElement("commercial_name")]
public string Name { get; set; }
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace KeepTrack.CarComponent.Infrastructure.MongoDb.Entities
{
public class CarHistory
{
[BsonId]
public ObjectId Id { get; set; }
[BsonElement("car_id")]
public string CarId { get; set; }
[BsonElement("history_date")]
public DateTime HistoryDate { get; set; }
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
using AutoMapper;

namespace KeepTrack.CarComponent.Infrastructure.MongoDb.MappingProfiles
{
public class CarMappingProfile : Profile
{
public override string ProfileName
{
get { return "KeepTrackCarInfrastructureMongoDbMappingProfile"; }
}

public CarMappingProfile()
{
CreateMap<Entities.Car, Domain.CarModel>();
CreateMap<Entities.CarHistory, Domain.CarHistoryModel>();
}
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using KeepTrack.CarComponent.Domain;
using KeepTrack.CarComponent.Infrastructure.MongoDb.Entities;
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Driver;
using Withywoods.Dal.MongoDb;
using Withywoods.Dal.MongoDb.Repositories;

namespace KeepTrack.CarComponent.Infrastructure.Repositories
{
public class CarHistoryRepository : RepositoryBase, ICarHistoryRepository
{
public CarHistoryRepository(IMongoDbContext mongoDbContext, ILogger<CarHistoryRepository> logger, IMapper mapper)
: base(mongoDbContext, logger, mapper)
{
}

protected override string CollectionName => "car_history";

public async Task<CarHistoryModel> FindOneAsync(string id)
{
if (!ObjectId.TryParse(id, out var objectId))
{
throw new System.Exception($"Cannot find the car history. \"{id}\" is not a valid id.");
}

var collection = GetCollection<CarHistory>();
var dbEntries = await collection.FindAsync(x => x.Id == objectId);
return Mapper.Map<CarHistoryModel>(dbEntries.FirstOrDefault());
}

public async Task<List<CarHistoryModel>> FindAllAsync(string carId)
{
var collection = GetCollection<CarHistory>();
var dbEntries = await collection.FindAsync(x => x.CarId == carId);
return Mapper.Map<List<CarHistoryModel>>(dbEntries.ToList());
}
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using AutoMapper;
using KeepTrack.CarComponent.Domain;
using KeepTrack.CarComponent.Infrastructure.MongoDb.Entities;
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Driver;
using Withywoods.Dal.MongoDb;
using Withywoods.Dal.MongoDb.Repositories;

namespace KeepTrack.CarComponent.Infrastructure.Repositories
{
public class CarRepository : RepositoryBase, ICarRepository
{
public CarRepository(IMongoDbContext mongoDbContext, ILogger<CarRepository> logger, IMapper mapper)
: base(mongoDbContext, logger, mapper)
{
}

protected override string CollectionName => "car";

public async Task<CarModel> FindOneAsync(string id)
{
if (string.IsNullOrEmpty(id))
{
throw new System.Exception($"Cannot find a car. \"{id}\" is not a valid id.");
}

var collection = GetCollection<Car>();
var dbEntries = await collection.FindAsync(x => x.Id == id);
return Mapper.Map<CarModel>(dbEntries.FirstOrDefault());
}
}
}
Loading