-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAssemblerTestFixture.cs
114 lines (91 loc) · 3.87 KB
/
AssemblerTestFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// -------------------------------------------------------------------------------------------------
// <copyright file="AssemblerTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2022-2025 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Dal.Tests
{
using System;
using System.Collections.Generic;
using NUnit.Framework;
using SysML2.NET.Dal;
/// <summary>
/// Suite of tests for the <see cref="Assembler"/> class
/// </summary>
[TestFixture]
public class AssemblerTestFixture
{
private IAssembler assembler;
private Lazy<Core.POCO.IElement> lazyPoco;
[SetUp]
public void Setup()
{
this.assembler = new Assembler();
}
[Test]
public void Verify_that_synchronize_Works_as_Expected()
{
var dtos = new List<Core.DTO.IElement>();
var packageDto = new Core.DTO.Package
{
Id = Guid.Parse("86082bb1-ac56-4080-9b04-2804be48cacb"),
DeclaredName = "a package",
ElementId = "86082bb1-ac56-4080-9b04-2804be48cacb",
};
var featureDto = new Core.DTO.Feature
{
Id = Guid.Parse("e1e89f3a-5863-4f7a-b9c5-5779d73630dd"),
DeclaredName = "some feature",
DeclaredShortName = "sf",
ElementId = "e1e89f3a-5863-4f7a-b9c5-5779d73630dd"
};
var membershipDto = new Core.DTO.Membership
{
Id = Guid.Parse("215054ad-eb1d-45f6-8537-d43a3470e73c"),
Source = new List<Guid> { packageDto.Id },
Target = new List<Guid> { featureDto.Id },
};
dtos.Add(packageDto);
dtos.Add(featureDto);
dtos.Add(membershipDto);
this.assembler.Synchronize(dtos);
Core.POCO.Feature featurePoco = null;
Core.POCO.Membership membershipPoco = null;
if (this.assembler.Cache.TryGetValue(featureDto.Id, out this.lazyPoco))
{
featurePoco = (Core.POCO.Feature)this.lazyPoco.Value;
}
Assert.That(featurePoco.Id, Is.EqualTo(featureDto.Id));
Assert.That(featurePoco.DeclaredName, Is.EqualTo(featureDto.DeclaredName));
Assert.That(featurePoco.DeclaredShortName, Is.EqualTo(featureDto.DeclaredShortName));
if (this.assembler.Cache.TryGetValue(membershipDto.Id, out this.lazyPoco))
{
membershipPoco = (Core.POCO.Membership)this.lazyPoco.Value;
}
Assert.That(membershipPoco.Target.Contains(featurePoco), Is.True);
dtos.Clear();
featureDto.DeclaredName = "some updated feature";
dtos.Add(featureDto);
this.assembler.Synchronize(dtos);
if (this.assembler.Cache.TryGetValue(featureDto.Id, out this.lazyPoco))
{
featurePoco = (Core.POCO.Feature)this.lazyPoco.Value;
}
Assert.That(featurePoco.DeclaredName, Is.EqualTo("some updated feature"));
}
}
}