-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUpdateTests.cs
More file actions
87 lines (69 loc) · 2.21 KB
/
Copy pathUpdateTests.cs
File metadata and controls
87 lines (69 loc) · 2.21 KB
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
using Kepware.Api.Model;
using Microsoft.Extensions.Logging;
using Moq;
using Moq.Contrib.HttpClient;
using Shouldly;
using System.Net;
using System.Text.Json;
namespace Kepware.Api.TestIntg.ApiClient;
public class UpdateTests : TestApiClientBase
{
[Fact]
public async Task Update_Item_WhenSuccessful_ShouldReturnTrue()
{
// Arrange
var channel = await AddTestChannel();
channel.Description = "Updated Description";
// Act
var result = await _kepwareApiClient.GenericConfig.UpdateItemAsync(channel);
// Assert
result.ShouldBeTrue();
// Clean up
await DeleteAllChannelsAsync();
}
[Fact]
public async Task Update_Item_WhenNotFound_ShouldReturnFalse()
{
// Arrange
var channel = CreateTestChannel();
// Act
var result = await _kepwareApiClient.GenericConfig.UpdateItemAsync(channel);
// Assert
result.ShouldBeFalse();
// Clean up
await DeleteAllChannelsAsync();
}
[Fact]
public async Task Update_MultipleItems_ShouldUpdateAll()
{
// Arrange
var channel = await AddTestChannel();
var device = await AddTestDevice(channel);
var tagsAdded = await AddSimulatorTestTags(device);
var tags = new List<(Tag item, Tag? oldItem)>();
foreach (var tag in tagsAdded)
{
tags.Add((new Tag { Name = tag.Name, Description = "Updated Description" }, tag));
};
// Act
var results = await _kepwareApiClient.GenericConfig.UpdateItemsAsync<DeviceTagCollection, Tag>(tags, device);
// Assert
results.Length.ShouldBe(tags.Count);
results.ShouldAllBe(r => r == true);
// Clean up
await DeleteAllChannelsAsync();
}
[Fact]
public async Task Update_Item_WithHttpError_ShouldReturnFalse()
{
// Arrange
var channel = await AddTestChannel();
channel.SetDynamicProperty("InvalidProperty", "InvalidValue");
// Act
var result = await _kepwareApiClient.GenericConfig.UpdateItemAsync(channel);
// Assert
result.ShouldBeFalse();
// Clean up
await DeleteAllChannelsAsync();
}
}