Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/System.Text.Json-7.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis authored Jan 16, 2024
2 parents fc43eb7 + 471539f commit 1e80a68
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 8 deletions.
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing to Ardalis.GuardClauses

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features

## We Develop with GitHub

Obviously...

## We Use Pull Requests

Mostly. But pretty much exclusively for non-maintainers. You'll need to fork the repo in order to submit a pull request. Here are the basic steps:

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

- [Pull Request Check List](https://ardalis.com/github-pull-request-checklist/)
- [Resync your fork with this upstream repo](https://ardalis.com/syncing-a-fork-of-a-github-repository-with-upstream/)

## Ask before adding a pull request

You can just add a pull request out of the blue if you want, but it's much better etitquette (and more likely to be accepted) if you open a new issue or comment in an existing issue stating you'd like to make a pull request.

## Getting Started

Look for [issues marked with 'help wanted'](https://github.com/ardalis/guardclauses/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) to find good places to start contributing.

## Any contributions you make will be under the MIT Software License

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers this project.

## Report bugs using Github's [issues](https://github.com/ardalis/guardclauses/issues)

We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/ardalis/GuardClauses/issues/new/choose); it's that easy!

## Sponsor us

If you don't have the time or expertise to contribute code, you can still support us by [sponsoring](https://github.com/sponsors/ardalis).
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Features>strict</Features>
</PropertyGroup>
<PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
<RepoRelativeProjectDir>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</RepoRelativeProjectDir>

<!-- Define useful flags based on project name conventions -->
Expand Down
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.17.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.4" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.10" />
<PackageVersion Include="Constant" Version="2.0.4" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="coverlet.msbuild" Version="3.2.0" />
<PackageVersion Include="Dapper" Version="2.0.123" />
<PackageVersion Include="Dapper" Version="2.1.15" />
<PackageVersion Include="Enums.NET" Version="4.0.1" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="MessagePack" Version="2.4.59" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Install-Package Ardalis.SmartEnum -Version 2.1.0

## Usage

Define your smart enum by inheriting from `SmartEnum<TEnum>` where `TEnum` is the type you're declaring. For [example](/src/SmartEnum.UnitTests/TestEnum.cs):
Define your smart enum by inheriting from `SmartEnum<TEnum>` where `TEnum` is the type you're declaring. For [example](/test/SmartEnum.UnitTests/TestEnum.cs):

```csharp
using Ardalis.SmartEnum;
Expand Down
6 changes: 5 additions & 1 deletion src/SmartEnum.EFCore/SmartEnumConverterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SmartEnum.EFCore
Expand All @@ -23,6 +25,7 @@ public static void ConfigureSmartEnum(this ModelConfigurationBuilder configurati
var propertyTypes = modelBuilder.Model.GetEntityTypes()
.SelectMany(e => e.ClrType.GetProperties())
.Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>)))
.Where(p => p.GetCustomAttribute<NotMappedAttribute>() == null)
.Select(p => p.PropertyType)
.Distinct();

Expand Down Expand Up @@ -52,7 +55,8 @@ public static void ConfigureSmartEnum(this ModelBuilder modelBuilder)
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
var properties = entityType.ClrType.GetProperties()
.Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>)));
.Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>)))
.Where(p => p.GetCustomAttribute<NotMappedAttribute>() == null);

foreach (var property in properties)
{
Expand Down
4 changes: 4 additions & 0 deletions test/SmartEnum.EFCore.IntegrationTests/Entities/SomeEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace SmartEnum.EFCore.IntegrationTests.Entities
{
Expand All @@ -24,6 +25,9 @@ public class SomeEntity

public List<SomeOwnedEntity> OwnedEntities { get; set; }

[NotMapped]
public TestEnum NotMappedTest { get; set; }

public class Configuration : IEntityTypeConfiguration<SomeEntity>
{
public void Configure(EntityTypeBuilder<SomeEntity> builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;

using System.ComponentModel.DataAnnotations.Schema;

namespace SmartEnum.EFCore.IntegrationTests.Entities
{
[Owned]
Expand All @@ -18,5 +20,8 @@ public class SomeOuterOwnedEntity
public TestBaseEnumWithDerivedValues Test4 { get; set; }

public SomeOwnedEntity InnerOwnedEntity { get; set; }

[NotMapped]
public TestEnum NotMappedTest { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;

using System.ComponentModel.DataAnnotations.Schema;

namespace SmartEnum.EFCore.IntegrationTests.Entities
{
[Owned]
Expand All @@ -16,5 +18,8 @@ public class SomeOwnedEntity
public TestStringEnum Test3 { get; set; }

public TestBaseEnumWithDerivedValues Test4 { get; set; }

[NotMapped]
public TestEnum NotMappedTest { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private static SomeEntity CreateEntity()
Test2 = TestDerivedEnum.One,
Test3 = TestStringEnum.One,
Test4 = DerivedTestEnumWithValues1.A,
NotMappedTest = TestEnum.One,
OwnedEntity = new SomeOwnedEntity
{
Value = 2,
Expand Down Expand Up @@ -143,27 +144,31 @@ private static void VerifyEntity(SomeEntity entity)
entity.Test2.Should().Be(TestDerivedEnum.One);
entity.Test3.Should().Be(TestStringEnum.One);
entity.Test4.Should().Be(DerivedTestEnumWithValues1.A);
entity.NotMappedTest.Should().BeNull();

entity.OwnedEntity.Value.Should().Be(2);
entity.OwnedEntity.Weekday.Should().Be(Weekday.Friday);
entity.OwnedEntity.Test1.Should().Be(TestEnum.Two);
entity.OwnedEntity.Test2.Should().Be(TestDerivedEnum.One);
entity.OwnedEntity.Test3.Should().Be(TestStringEnum.Two);
entity.OwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B);
entity.OwnedEntity.NotMappedTest.Should().BeNull();

entity.OuterOwnedEntity.Value.Should().Be(3);
entity.OuterOwnedEntity.Weekday.Should().Be(Weekday.Friday);
entity.OuterOwnedEntity.Test1.Should().Be(TestEnum.Two);
entity.OuterOwnedEntity.Test2.Should().Be(TestDerivedEnum.One);
entity.OuterOwnedEntity.Test3.Should().Be(TestStringEnum.Two);
entity.OuterOwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B);
entity.OuterOwnedEntity.NotMappedTest.Should().BeNull();

entity.OuterOwnedEntity.InnerOwnedEntity.Value.Should().Be(4);
entity.OuterOwnedEntity.InnerOwnedEntity.Weekday.Should().Be(Weekday.Friday);
entity.OuterOwnedEntity.InnerOwnedEntity.Test1.Should().Be(TestEnum.Two);
entity.OuterOwnedEntity.InnerOwnedEntity.Test2.Should().Be(TestDerivedEnum.One);
entity.OuterOwnedEntity.InnerOwnedEntity.Test3.Should().Be(TestStringEnum.Two);
entity.OuterOwnedEntity.InnerOwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B);
entity.OuterOwnedEntity.InnerOwnedEntity.NotMappedTest.Should().BeNull();

entity.OwnedEntities.Should().SatisfyRespectively(
o =>
Expand All @@ -174,6 +179,7 @@ private static void VerifyEntity(SomeEntity entity)
o.Test2.Should().Be(TestDerivedEnum.One);
o.Test3.Should().Be(TestStringEnum.Three);
o.Test4.Should().Be(DerivedTestEnumWithValues1.A);
o.NotMappedTest.Should().BeNull();
},
o =>
{
Expand All @@ -183,6 +189,7 @@ private static void VerifyEntity(SomeEntity entity)
o.Test2.Should().Be(TestDerivedEnum.One);
o.Test3.Should().Be(TestStringEnum.One);
o.Test4.Should().Be(DerivedTestEnumWithValues1.B);
o.NotMappedTest.Should().BeNull();
});
}
}
Expand Down

0 comments on commit 1e80a68

Please sign in to comment.