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

21, Allow preservation of explicitly-set Object value #39

Open
wants to merge 2 commits into
base: main
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>BuilderGenerator.IntegrationTests.Net60</_Parameter1>
<_Parameter1>BuilderGenerator.Tests.Integration.Net60</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>BuilderGenerator.IntegrationTests.Net60</_Parameter1>
<_Parameter1>BuilderGenerator.Tests.Integration.Net60</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public abstract class AuditableEntity : Entity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public class CollectionTypesSample
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public abstract class Entity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using BuilderGenerator.IntegrationTests.Core.Models.Enums;
using BuilderGenerator.Tests.Core.Models.Enums;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public class Order : AuditableEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public class OrderItem : AuditableEntity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

using System.Collections.Generic;

namespace BuilderGenerator.IntegrationTests.Core.Models.Entities;
namespace BuilderGenerator.Tests.Core.Models.Entities;

public partial class User : AuditableEntity
{
public string FirstName { get; set; }

Check warning on line 9 in src/BuilderGenerator.Tests.Core/Models/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string LastName { get; set; }

Check warning on line 10 in src/BuilderGenerator.Tests.Core/Models/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string? MiddleName { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BuilderGenerator.IntegrationTests.Core.Models.Enums;
namespace BuilderGenerator.Tests.Core.Models.Enums;

public enum OrderStatus
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BuilderGenerator.Tests.Core\BuilderGenerator.Tests.Core.csproj" />
<ProjectReference Include="..\BuilderGenerator.Tests.Unit\BuilderGenerator.Tests.Unit.csproj" />
<ProjectReference Include="..\BuilderGenerator\BuilderGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Shouldly" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BuilderGenerator.IntegrationTests.Core\BuilderGenerator.IntegrationTests.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using BuilderGenerator.Tests.Core.Models.Entities;

namespace BuilderGenerator.Tests.Integration.Net60.Builders;

[BuilderFor(typeof(CollectionTypesSample))]
public partial class CollectionTypeSampleBuilder
{
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.Tests.Core.Models.Entities;

namespace BuilderGenerator.IntegrationTests.Net60.Builders;
namespace BuilderGenerator.Tests.Integration.Net60.Builders;

[BuilderFor(typeof(Order), true)]
public partial class OrderBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.Tests.Core.Models.Entities;

namespace BuilderGenerator.IntegrationTests.Net60.Builders;
namespace BuilderGenerator.Tests.Integration.Net60.Builders;

[BuilderFor(typeof(OrderItem))]
public partial class OrderItemBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.Tests.Core.Models.Entities;

namespace BuilderGenerator.IntegrationTests.Net60.Builders;
namespace BuilderGenerator.Tests.Integration.Net60.Builders;

[BuilderFor(typeof(User))]
public partial class UserBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.IntegrationTests.Net60.Builders;
using BuilderGenerator.Tests.Core.Models.Entities;
using BuilderGenerator.Tests.Integration.Net60.Builders;
using NUnit.Framework;
using Shouldly;

namespace BuilderGenerator.IntegrationTests.Net60.Tests;
namespace BuilderGenerator.Tests.Integration.Net60.Tests;

[TestFixture]
public class BuilderTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.IntegrationTests.Core.Models.Enums;
using BuilderGenerator.IntegrationTests.Net60.Builders;
using BuilderGenerator.Tests.Core.Models.Entities;
using BuilderGenerator.Tests.Core.Models.Enums;
using BuilderGenerator.Tests.Integration.Net60.Builders;
using NUnit.Framework;
using Shouldly;

namespace BuilderGenerator.IntegrationTests.Net60.Tests;
namespace BuilderGenerator.Tests.Integration.Net60.Tests;

[TestFixture]
public class OrderBuilderTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using BuilderGenerator.IntegrationTests.Core.Models.Entities;
using BuilderGenerator.IntegrationTests.Net60.Builders;
using BuilderGenerator.Tests.Core.Models.Entities;
using BuilderGenerator.Tests.Integration.Net60.Builders;
using NUnit.Framework;
using Shouldly;

namespace BuilderGenerator.IntegrationTests.Net60.Tests;
namespace BuilderGenerator.Tests.Integration.Net60.Tests;

[TestFixture]
public class UserBuilderTests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Examples\Input.cs" />
<Compile Remove="Examples\Output.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Examples\Input.cs" />
<EmbeddedResource Include="Examples\Output.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BuilderGenerator\BuilderGenerator.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="Shouldly" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
</ItemGroup>

<ItemGroup>
<None Remove="Examples\.editorconfig" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Examples\.editorconfig" />
<EmbeddedResource Include="Examples\InputWithInternals.cs" />
<EmbeddedResource Include="Examples\InputWithoutInternals.cs" />
<EmbeddedResource Include="Examples\OutputWithInternals.cs" />
Expand All @@ -32,18 +37,7 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=examples/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
16 changes: 16 additions & 0 deletions src/BuilderGenerator.Tests.Unit/Examples/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root=true
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
# When specifying tool-specific properties, such as ReSharper's extended properties (https://www.jetbrains.com/help/resharper/EditorConfig_Index.html)
# Use the most generically-named version of the property (i.e. choose "brace_style" over "csharp_brace_style" or "resharper_csharp_brace_style")
# Hopefully, these settings become supported by Visual Studio, or add-ins liks CodeMaid.


# This file is the top-most EditorConfig file

# All Files (Unless overridden elsewhere)
[*]
charset=utf-8
end_of_line=crlf
indent_size=4
indent_style=space
insert_final_newline=false
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable disable

using System.CodeDom.Compiler;
using BuilderGenerator;

Expand All @@ -15,24 +13,32 @@ public override BuilderGenerator.UnitTests.Person Build()
{
if (Object?.IsValueCreated != true)
{
Object = new System.Lazy<BuilderGenerator.UnitTests.Person>(() =>
{
var result = new BuilderGenerator.UnitTests.Person
{
FirstName = FirstName.Value,
InternalString = InternalString.Value,
LastName = LastName.Value,
};

return result;
});

PostProcess(Object.Value);
Object = new System.Lazy<BuilderGenerator.UnitTests.Person>(new BuilderGenerator.UnitTests.Person());
}

Object.Value.FirstName = FirstName.Value;
Object.Value.InternalString = InternalString.Value;
Object.Value.LastName = LastName.Value;

PostProcess(Object.Value);

return Object.Value;
}

/// <summary>Sets the object to be returned by this instance.</summary>
/// <param name="value">The object to be returned.</param>
/// <returns>A reference to this builder instance.</returns>
public override Builder<BuilderGenerator.UnitTests.Person> WithObject(BuilderGenerator.UnitTests.Person value)
{
base.WithObject(value);

WithFirstName(value.FirstName);
WithInternalString(value.InternalString);
WithLastName(value.LastName);

return this;
}

public PersonBuilderWithInternals WithFirstName(string value)
{
return WithFirstName(() => value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable disable

using System.CodeDom.Compiler;
using BuilderGenerator;

Expand All @@ -14,23 +12,30 @@ public override BuilderGenerator.UnitTests.Person Build()
{
if (Object?.IsValueCreated != true)
{
Object = new System.Lazy<BuilderGenerator.UnitTests.Person>(() =>
{
var result = new BuilderGenerator.UnitTests.Person
{
FirstName = FirstName.Value,
LastName = LastName.Value,
};
Object = new System.Lazy<BuilderGenerator.UnitTests.Person>(new BuilderGenerator.UnitTests.Person());
}

return result;
});
Object.Value.FirstName = FirstName.Value;
Object.Value.LastName = LastName.Value;

PostProcess(Object.Value);
}
PostProcess(Object.Value);

return Object.Value;
}

/// <summary>Sets the object to be returned by this instance.</summary>
/// <param name="value">The object to be returned.</param>
/// <returns>A reference to this builder instance.</returns>
public override Builder<BuilderGenerator.UnitTests.Person> WithObject(BuilderGenerator.UnitTests.Person value)
{
base.WithObject(value);

WithFirstName(value.FirstName);
WithLastName(value.LastName);

return this;
}

public PersonBuilderWithoutInternals WithFirstName(string value)
{
return WithFirstName(() => value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

// ReSharper disable InconsistentNaming

namespace BuilderGenerator.UnitTests;
namespace BuilderGenerator.Tests.Unit;

public abstract class Given_a_BuilderGenerator
{
public static string GetResourceAsString(Assembly assembly, string resourceName)
{
var manifestResourceNames = assembly.GetManifestResourceNames();
resourceName = manifestResourceNames.Single(x => x.Equals($"BuilderGenerator.UnitTests.Examples.{resourceName}", StringComparison.OrdinalIgnoreCase));
resourceName = manifestResourceNames.Single(x => x.Equals($"BuilderGenerator.Tests.Unit.Examples.{resourceName}", StringComparison.OrdinalIgnoreCase));

using (var stream = assembly.GetManifestResourceStream(resourceName))
{
Expand Down
Loading
Loading