Skip to content

Commit 0265fe2

Browse files
authored
Merge pull request #193 from bingenito/improved-coverage
Increase test overage of core Fdc3 and AppDirectory packages
2 parents bd0d903 + 1155126 commit 0265fe2

File tree

11 files changed

+713
-0
lines changed

11 files changed

+713
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using System;
16+
using Xunit;
17+
18+
namespace Finos.Fdc3.AppDirectory.Tests;
19+
20+
public class AppChannelTests
21+
{
22+
[Fact]
23+
public void AppChannel_Constructor_SetsProperties()
24+
{
25+
// Arrange
26+
var id = "testChannel";
27+
28+
// Act
29+
var channel = new AppChannel(id);
30+
31+
// Assert
32+
Assert.Equal(id, channel.ID);
33+
Assert.Null(channel.Description);
34+
Assert.Null(channel.Broadcasts);
35+
}
36+
37+
[Fact]
38+
public void AppChannel_Constructor_WithNullId_ThrowsArgumentNullException()
39+
{
40+
// Act & Assert
41+
Assert.Throws<ArgumentNullException>(() => new AppChannel(null!));
42+
}
43+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using System;
16+
using Xunit;
17+
18+
namespace Finos.Fdc3.AppDirectory.Tests;
19+
20+
public class AppDetailsTests
21+
{
22+
[Fact]
23+
public void WebAppDetails_Constructor_SetsProperties()
24+
{
25+
// Arrange
26+
var url = "https://example.com";
27+
28+
// Act
29+
var details = new WebAppDetails(url);
30+
31+
// Assert
32+
Assert.Equal(url, details.Url);
33+
}
34+
35+
[Fact]
36+
public void NativeAppDetails_Constructor_SetsProperties()
37+
{
38+
// Arrange
39+
var path = @"C:\Program Files\App\app.exe";
40+
var arguments = "--start";
41+
42+
// Act
43+
var details = new NativeAppDetails(path, arguments);
44+
45+
// Assert
46+
Assert.Equal(path, details.Path);
47+
Assert.Equal(arguments, details.Arguments);
48+
}
49+
50+
[Fact]
51+
public void OnlineNativeAppDetails_Constructor_SetsProperties()
52+
{
53+
// Arrange
54+
var url = "https://example.com";
55+
56+
// Act
57+
var details = new OnlineNativeAppDetails(url);
58+
59+
// Assert
60+
Assert.Equal(url, details.Url);
61+
}
62+
63+
[Fact]
64+
public void CitrixAppDetails_Constructor_SetsProperties()
65+
{
66+
// Arrange
67+
var alias = "citrix-app-alias";
68+
var arguments = "--start";
69+
70+
// Act
71+
var details = new CitrixAppDetails(alias, arguments);
72+
73+
// Assert
74+
Assert.Equal(alias, details.Alias);
75+
Assert.Equal(arguments, details.Arguments);
76+
}
77+
78+
[Fact]
79+
public void WebAppDetails_Constructor_WithNullUrl_ThrowsArgumentNullException()
80+
{
81+
// Act & Assert
82+
Assert.Throws<ArgumentNullException>(() => new WebAppDetails(null!));
83+
}
84+
85+
[Fact]
86+
public void NativeAppDetails_Constructor_WithNullPath_ThrowsArgumentNullException()
87+
{
88+
// Act & Assert
89+
Assert.Throws<ArgumentNullException>(() => new NativeAppDetails(null!, null));
90+
}
91+
92+
[Fact]
93+
public void CitrixAppDetails_Constructor_WithNullAlias_ThrowsArgumentNullException()
94+
{
95+
// Act & Assert
96+
Assert.Throws<ArgumentNullException>(() => new CitrixAppDetails(null!, null));
97+
}
98+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using System;
16+
using Xunit;
17+
18+
namespace Finos.Fdc3.AppDirectory.Tests;
19+
20+
public class Fdc3AppTests
21+
{
22+
[Fact]
23+
public void Fdc3App_Constructor_SetsProperties()
24+
{
25+
// Arrange
26+
var appId = "test-app";
27+
var name = "Test App";
28+
var type = AppType.Web;
29+
var details = new WebAppDetails("https://example.com");
30+
31+
// Act
32+
#pragma warning disable CS0618 // Type or member is obsolete
33+
var app = new Fdc3App(appId, name, type, details);
34+
35+
// Assert
36+
Assert.Equal(appId, app.AppId);
37+
Assert.Equal(name, app.Name);
38+
#pragma warning restore CS0618 // Type or member is obsolete
39+
Assert.Equal(type, app.Type);
40+
Assert.Equal(details, app.Details);
41+
}
42+
43+
[Fact]
44+
public void Fdc3App_Constructor_WithNullAppId_ThrowsArgumentNullException()
45+
{
46+
// Act & Assert
47+
Assert.Throws<ArgumentNullException>(() => new Fdc3App(
48+
null!,
49+
"Test App",
50+
AppType.Web,
51+
new WebAppDetails("https://example.com")));
52+
}
53+
54+
[Fact]
55+
public void Fdc3App_Constructor_WithNullName_ThrowsArgumentNullException()
56+
{
57+
// Act & Assert
58+
Assert.Throws<ArgumentNullException>(() => new Fdc3App(
59+
"test-app",
60+
null!,
61+
AppType.Web,
62+
new WebAppDetails("https://example.com")));
63+
}
64+
65+
[Fact]
66+
public void Fdc3App_Constructor_WithNullDetails_ThrowsArgumentNullException()
67+
{
68+
// Act & Assert
69+
Assert.Throws<ArgumentNullException>(() => new Fdc3App(
70+
"test-app",
71+
"Test App",
72+
AppType.Web,
73+
null!));
74+
}
75+
76+
[Fact]
77+
public void Fdc3App_GenericConstructor_SetsProperties()
78+
{
79+
// Arrange
80+
var appId = "test-app";
81+
var name = "Test App";
82+
var type = AppType.Web;
83+
var details = new WebAppDetails("https://example.com");
84+
85+
// Act
86+
#pragma warning disable CS0618 // Type or member is obsolete
87+
var app = new Fdc3App<WebAppDetails>(appId, name, type, details);
88+
89+
// Assert
90+
Assert.Equal(appId, app.AppId);
91+
Assert.Equal(name, app.Name);
92+
#pragma warning restore CS0618 // Type or member is obsolete
93+
Assert.Equal(type, app.Type);
94+
Assert.Equal(details, app.Details);
95+
}
96+
97+
[Fact]
98+
public void Fdc3App_GenericConstructor_WithWrongDetailsType_ThrowsInvalidCastException()
99+
{
100+
// Arrange
101+
var appId = "test-app";
102+
var name = "Test App";
103+
var type = AppType.Web;
104+
var details = new NativeAppDetails(@"C:\app.exe", null);
105+
106+
// Act & Assert
107+
var baseApp = new Fdc3App(appId, name, type, details);
108+
Assert.Throws<InvalidCastException>(() => _ = (WebAppDetails)baseApp.Details);
109+
}
110+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Xunit;
18+
19+
namespace Finos.Fdc3.AppDirectory.Tests;
20+
21+
public class IntentMetadataTests
22+
{
23+
[Fact]
24+
public void IntentMetadata_Constructor_SetsProperties()
25+
{
26+
// Arrange
27+
var name = "ViewChart";
28+
var displayName = "View Chart";
29+
var contexts = new[] { "fdc3.instrument", "fdc3.position" };
30+
31+
// Act
32+
#pragma warning disable CS0618 // Type or member is obsolete
33+
var metadata = new IntentMetadata(name, displayName, contexts);
34+
35+
// Assert
36+
Assert.Equal(name, metadata.Name);
37+
Assert.Equal(displayName, metadata.DisplayName);
38+
#pragma warning restore CS0618 // Type or member is obsolete
39+
Assert.Equal(contexts, metadata.Contexts);
40+
}
41+
42+
[Fact]
43+
public void IntentMetadata_Constructor_WithNullContexts_ThrowsArgumentNullException()
44+
{
45+
// Act & Assert
46+
Assert.Throws<ArgumentNullException>(() => new IntentMetadata("ViewChart", "View Chart", null!));
47+
}
48+
49+
[Fact]
50+
public void IntentMetadata_Constructor_WithEmptyContexts_Succeeds()
51+
{
52+
// Arrange & Act
53+
var metadata = new IntentMetadata("ViewChart", "View Chart", Array.Empty<string>());
54+
55+
// Assert
56+
Assert.NotNull(metadata.Contexts);
57+
Assert.Empty(metadata.Contexts);
58+
}
59+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using System.Collections.Generic;
16+
using Xunit;
17+
18+
namespace Finos.Fdc3.AppDirectory.Tests;
19+
20+
public class IntentsTests
21+
{
22+
[Fact]
23+
public void Intents_Properties_CanBeSetAndGet()
24+
{
25+
// Arrange
26+
var intents = new Intents();
27+
var listensFor = new Dictionary<string, IntentMetadata>
28+
{
29+
{ "ViewChart", new IntentMetadata("ViewChart", "View Chart", new[] { "fdc3.instrument" }) },
30+
{ "ViewContact", new IntentMetadata("ViewContact", "View Contact", new[] { "fdc3.contact" }) }
31+
};
32+
var raises = new Dictionary<string, IEnumerable<string>>
33+
{
34+
{ "StartChat", new[] { "fdc3.contact", "fdc3.organization" } },
35+
{ "ViewNews", new[] { "fdc3.instrument", "fdc3.organization" } }
36+
};
37+
38+
// Act
39+
intents.ListensFor = listensFor;
40+
intents.Raises = raises;
41+
42+
// Assert
43+
Assert.Equal(listensFor, intents.ListensFor);
44+
Assert.Equal(raises, intents.Raises);
45+
}
46+
47+
[Fact]
48+
public void Intents_Properties_CanBeNull()
49+
{
50+
// Arrange & Act
51+
var intents = new Intents();
52+
53+
// Assert
54+
Assert.Null(intents.ListensFor);
55+
Assert.Null(intents.Raises);
56+
}
57+
58+
[Fact]
59+
public void Intents_Properties_CanBeEmpty()
60+
{
61+
// Arrange
62+
var intents = new Intents();
63+
var emptyListensFor = new Dictionary<string, IntentMetadata>();
64+
var emptyRaises = new Dictionary<string, IEnumerable<string>>();
65+
66+
// Act
67+
intents.ListensFor = emptyListensFor;
68+
intents.Raises = emptyRaises;
69+
70+
// Assert
71+
Assert.Empty(intents.ListensFor);
72+
Assert.Empty(intents.Raises);
73+
}
74+
}

0 commit comments

Comments
 (0)