-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCustomExtensionTest.cs
More file actions
127 lines (105 loc) · 5.21 KB
/
Copy pathCustomExtensionTest.cs
File metadata and controls
127 lines (105 loc) · 5.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using AutoFixture;
using AutoFixture.AutoMoq;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.CustomExtension;
using Contentstack.Management.Core.Models.Fields;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Contentstack.Management.Core.Unit.Tests.Models
{
[TestClass]
public class CustomExtensionTest
{
private readonly IFixture _fixture = new Fixture()
.Customize(new AutoMoqCustomization());
[TestMethod]
public void Should_Throw_On_Filepath_Null()
{
Assert.ThrowsException<ArgumentNullException>(() => new CustomFieldModel(byteArray: null, "", "", ""));
Assert.ThrowsException<ArgumentNullException>(() => new CustomWidgetModel(byteArray: null, "", ""));
Assert.ThrowsException<ArgumentNullException>(() => new DashboardWidgetModel(byteArray: null, "", ""));
}
[TestMethod]
public void Should_Return_CustomFieldModel()
{
var title = _fixture.Create<string>();
var dataType = _fixture.Create<string>();
var contentType = "application/text";
CustomFieldModel customFieldModel = new CustomFieldModel("../../../../README.md", contentType, title, dataType);
Assert.AreEqual(title, customFieldModel.Title);
Assert.AreEqual(dataType, customFieldModel.DataType);
Assert.AreEqual(contentType, customFieldModel.ContentType);
}
[TestMethod]
public async Task Should_Return_CustomFieldModel_Multipart()
{
var title = _fixture.Create<string>();
var dataType = _fixture.Create<string>();
var tags = _fixture.Create<string>();
CustomFieldModel assetModel = new CustomFieldModel("../../../../README.md", "application/text", title, dataType, true, tags);
var content = assetModel.GetHttpContent();
var stringContent = await content.ReadAsStringAsync();
Assert.IsTrue(stringContent.Contains(title));
Assert.IsTrue(stringContent.Contains(dataType));
Assert.IsTrue(stringContent.Contains("true"));
Assert.IsTrue(stringContent.Contains(tags));
Assert.IsTrue(stringContent.Contains("field"));
Assert.IsFalse(stringContent.Contains("widget"));
Assert.IsFalse(stringContent.Contains("dashboard"));
}
[TestMethod]
public void Should_Return_CustomWidgetModel()
{
var title = _fixture.Create<string>();
var dataType = _fixture.Create<string>();
var contentType = "application/text";
CustomWidgetModel customFieldModel = new CustomWidgetModel("../../../../README.md", contentType, title);
Assert.AreEqual(title, customFieldModel.Title);
Assert.AreEqual(contentType, customFieldModel.ContentType);
}
[TestMethod]
public async Task Should_Return_CustomWidgetModel_Multipart()
{
var title = _fixture.Create<string>();
var tags = _fixture.Create<string>();
CustomWidgetModel assetModel = new CustomWidgetModel("../../../../README.md", "application/text", title, tags, _fixture.Create<ExtensionScope>());
var content = assetModel.GetHttpContent();
var stringContent = await content.ReadAsStringAsync();
Assert.IsTrue(stringContent.Contains(title));
Assert.IsTrue(stringContent.Contains(tags));
Assert.IsTrue(stringContent.Contains("widget"));
Assert.IsFalse(stringContent.Contains("dashboard"));
Assert.IsFalse(stringContent.Contains("field"));
}
[TestMethod]
public void Should_Return_DashboardWidgetModel()
{
var title = _fixture.Create<string>();
var dataType = _fixture.Create<string>();
var contentType = "application/text";
DashboardWidgetModel customFieldModel = new DashboardWidgetModel("../../../../README.md", contentType, title);
Assert.AreEqual(title, customFieldModel.Title);
Assert.AreEqual(contentType, customFieldModel.ContentType);
}
[TestMethod]
public async Task Should_Return_DashboardWidgetModel_Multipart()
{
var title = _fixture.Create<string>();
var tags = _fixture.Create<string>();
DashboardWidgetModel assetModel = new DashboardWidgetModel("../../../../README.md", "application/text", title, isEnable: true, defaultWidth: "half", tags: tags);
var content = assetModel.GetHttpContent();
var stringContent = await content.ReadAsStringAsync();
Assert.IsTrue(stringContent.Contains(title));
Assert.IsTrue(stringContent.Contains(tags));
Assert.IsTrue(stringContent.Contains("dashboard"));
Assert.IsTrue(stringContent.Contains("true"));
Assert.IsTrue(stringContent.Contains("half"));
Assert.IsFalse(stringContent.Contains("widget"));
Assert.IsFalse(stringContent.Contains("field"));
}
}
}