|
| 1 | +// Copyright (C) 2021 Xtensive LLC. |
| 2 | +// This code is distributed under MIT license terms. |
| 3 | +// See the License.txt file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using NUnit.Framework; |
| 10 | +using Xtensive.Orm.Configuration; |
| 11 | +using Xtensive.Orm.Tests.Issues.IssueGithub0150_ClosureProblemModel; |
| 12 | + |
| 13 | +namespace Xtensive.Orm.Tests.Issues.IssueGithub0150_ClosureProblemModel |
| 14 | +{ |
| 15 | + [HierarchyRoot] |
| 16 | + public class TestOperation : Entity |
| 17 | + { |
| 18 | + [Key, Field] |
| 19 | + public long ID { get; private set; } |
| 20 | + |
| 21 | + [Field] |
| 22 | + [Association(OnOwnerRemove = OnRemoveAction.Clear, OnTargetRemove = OnRemoveAction.Deny, PairTo = "Operation")] |
| 23 | + public EntitySet<TestWorkOrder> WorkOrders { get; private set; } |
| 24 | + |
| 25 | + public string GetErpOrderReference() |
| 26 | + { |
| 27 | + var erpReferences = Session.Query.Execute(q => q.All<TestWorkOrder>() |
| 28 | + .Where(w => w.Operation == this) |
| 29 | + .Select(w => w.Str)); |
| 30 | + |
| 31 | + var result = string.Join(" / ", erpReferences.ToArray()); |
| 32 | + return result; |
| 33 | + } |
| 34 | + |
| 35 | + public TestOperation(TestWorkOrder wo) |
| 36 | + { |
| 37 | + if (wo == null) |
| 38 | + throw new ArgumentNullException(nameof(wo)); |
| 39 | + _ = WorkOrders.Add(wo); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + [HierarchyRoot] |
| 44 | + public class TestWorkOrder : Entity |
| 45 | + { |
| 46 | + [Key, Field] |
| 47 | + public long ID { get; private set; } |
| 48 | + |
| 49 | + [Field] |
| 50 | + public TestOperation Operation { get; private set; } |
| 51 | + |
| 52 | + [Field] |
| 53 | + public string Str { get; set; } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +namespace Xtensive.Orm.Tests.Issues |
| 58 | +{ |
| 59 | + public class IssueGithub0149_ParameterReplacerHandlesNullConstsIncorrectly : AutoBuildTest |
| 60 | + { |
| 61 | + protected override DomainConfiguration BuildConfiguration() |
| 62 | + { |
| 63 | + var config = base.BuildConfiguration(); |
| 64 | + config.Types.Register(typeof(TestWorkOrder)); |
| 65 | + config.Types.Register(typeof(TestOperation)); |
| 66 | + return config; |
| 67 | + } |
| 68 | + |
| 69 | + [Test] |
| 70 | + public void MainTest() |
| 71 | + { |
| 72 | + using(var session = Domain.OpenSession()) |
| 73 | + using(var tx = session.OpenTransaction()) { |
| 74 | + var wo = new TestWorkOrder { |
| 75 | + Str = "A" |
| 76 | + }; |
| 77 | + var op = new TestOperation(wo); |
| 78 | + var erpOrder = op.GetErpOrderReference(); |
| 79 | + Assert.AreEqual(wo.Str, erpOrder); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments