Skip to content

Commit d3eeb73

Browse files
committed
Add test for immutable with complex struct as field type
Demonstrates bug #80
1 parent a9b40bc commit d3eeb73

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<Generator>MSBuild:GenerateCodeFromAttributes</Generator>
6767
</Compile>
6868
<Compile Include="TestSources\ImmutableDictionaryHelpers.Tests.cs" />
69+
<Compile Include="TestSources\ImmutableWithComplexStructField.cs">
70+
<Generator>MSBuild:GenerateCodeFromAttributes</Generator>
71+
</Compile>
72+
<Compile Include="TestSources\ImmutableWithComplexStructField.Tests.cs" />
6973
<Compile Include="TestSources\MSBuild.cs">
7074
<Generator>MSBuild:GenerateCodeFromAttributes</Generator>
7175
</Compile>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace ImmutableObjectGraph.Generation.Tests.TestSources
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Xunit;
9+
10+
public class ImmutableWithComplexStructFieldTests
11+
{
12+
[Fact]
13+
public void AssignVariousValues()
14+
{
15+
var originalStruct = new SomeStructWithMultipleFields(5, 0);
16+
var structWithModifiedSecondField = new SomeStructWithMultipleFields(5, 1);
17+
var v1 = ImmutableWithComplexStructField.Create(someStructField: originalStruct);
18+
var v2 = v1.With(someStructField: structWithModifiedSecondField);
19+
Assert.Equal(structWithModifiedSecondField.Field2, v2.SomeStructField.Field2);
20+
}
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace ImmutableObjectGraph.Generation.Tests.TestSources
2+
{
3+
[GenerateImmutable]
4+
partial class ImmutableWithComplexStructField
5+
{
6+
readonly SomeStructWithMultipleFields someStructField;
7+
}
8+
9+
struct SomeStructWithMultipleFields
10+
{
11+
internal SomeStructWithMultipleFields(int field1, int field2)
12+
{
13+
this.Field1 = field1;
14+
this.Field2 = field2;
15+
}
16+
17+
internal int Field1 { get; }
18+
19+
internal int Field2 { get; }
20+
}
21+
}

0 commit comments

Comments
 (0)