Skip to content

Commit 3dedcc6

Browse files
Merge pull request #548 from DigitalExcellence/develop
v.1.10.0-beta 16-12-2021
2 parents 79a975e + 698e6f4 commit 3dedcc6

40 files changed

+4240
-217
lines changed

API.Tests/Controllers/ProjectControllerTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
using Xunit;
99
using API.Tests.Enums;
1010
using API.Tests.Helpers;
11+
using API.Resources;
12+
using API.InputOutput.Tag;
13+
using System.Collections.Generic;
1114

1215
namespace API.Tests.Controllers
1316
{
@@ -112,5 +115,37 @@ public async Task CategorizeProject_Returns_Expected_Result_For_All_Roles(UserRo
112115
// Assert
113116
response.StatusCode.Should().Be(expectedResult);
114117
}
118+
119+
[Theory]
120+
[InlineData(UserRole.Admin, HttpStatusCode.OK)]
121+
[InlineData(UserRole.DataOfficer, HttpStatusCode.OK)]
122+
[InlineData(UserRole.PrUser, HttpStatusCode.OK)]
123+
[InlineData(UserRole.RegisteredUser, HttpStatusCode.OK)]
124+
public async Task Update_Tag_Returns_Expected_Result_For_All_Roles(UserRole role, HttpStatusCode expectedResult)
125+
{
126+
// Arrange
127+
await AuthenticateAs(role);
128+
ProjectInput projectInput = SeedUtility.RandomProjectInput();
129+
projectInput.Tags = new List<TagInput>() {
130+
new TagInput() { Name = "java" }
131+
};
132+
HttpResponseMessage postProjectResponse = await TestClient.PostAsJsonAsync("project", projectInput);
133+
string responseContent = await postProjectResponse.Content.ReadAsStringAsync();
134+
135+
int projectId = JsonConvert.DeserializeObject<Project>(responseContent).Id;
136+
137+
ProjectInput project = JsonConvert.DeserializeObject<ProjectInput>(responseContent);
138+
139+
project.Tags = new List<TagInput>() {
140+
new TagInput() { Name = "csharp" },
141+
new TagInput() { Name = "java" }
142+
};
143+
144+
// Act
145+
HttpResponseMessage response = await TestClient.PutAsJsonAsync("project/" + projectId, projectInput);
146+
147+
// Assert
148+
response.StatusCode.Should().Be(expectedResult);
149+
}
115150
}
116151
}

API.Tests/Helpers/SeedUtility.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Models;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using API.Resources;
910

1011
namespace API.Tests.Helpers
1112
{
@@ -14,18 +15,30 @@ public class SeedUtility
1415
public static Project RandomProject()
1516
{
1617
Faker<Project> projectToFake = new Faker<Project>()
17-
.RuleFor(p => p.UserId, 1)
18-
.RuleFor(p => p.Uri, f => f.Internet.Url())
19-
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
20-
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
21-
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
18+
.RuleFor(p => p.UserId, 1)
19+
.RuleFor(p => p.Uri, f => f.Internet.Url())
20+
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
21+
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
22+
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
2223
Project project = projectToFake.Generate();
2324
project.Created = DateTime.Now.AddDays(-2);
2425
project.Updated = DateTime.Now;
2526

2627
return project;
2728
}
2829

30+
public static ProjectInput RandomProjectInput()
31+
{
32+
Faker<ProjectInput> projectToFake = new Faker<ProjectInput>()
33+
.RuleFor(p => p.Uri, f => f.Internet.Url())
34+
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
35+
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
36+
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
37+
ProjectInput project = projectToFake.Generate();
38+
39+
return project;
40+
}
41+
2942
public static Category RandomCategory()
3043
{
3144
Faker<Category> categoryToFake = new Faker<Category>()
@@ -35,6 +48,22 @@ public static Category RandomCategory()
3548
return category;
3649
}
3750

51+
public static List<Tag> RandomTags()
52+
{
53+
List<Tag> tags = new List<Tag>();
54+
for(int i = 0; i < 3; i++)
55+
{
56+
Faker<Tag> tagToFake = new Faker<Tag>()
57+
.RuleFor(t => t.Name, f => f.Hacker.Adjective());
58+
59+
Tag tag = tagToFake.Generate();
60+
61+
tags.Add(tag);
62+
}
63+
64+
return tags;
65+
}
66+
3867
public static Highlight RandomHighlight()
3968
{
4069
Faker<Highlight> highlightToFake = new Faker<Highlight>()

API/Configuration/MappingProfile.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* If not, see https://www.gnu.org/licenses/lgpl-3.0.txt
1616
*/
1717

18+
using API.InputOutput.Tag;
1819
using API.Resources;
1920
using AutoMapper;
2021
using Models;
@@ -175,6 +176,13 @@ public MappingProfile()
175176
.ForMember(dest => dest.InstititutionName, opt => opt.MapFrom(src => src.Institution.Name))
176177
.ForMember(dest => dest.ProjectName, opt => opt.MapFrom(src => src.Project.Name));
177178

179+
CreateMap<Tag, TagOutput>();
180+
CreateMap<TagInput, Tag>();
181+
CreateMap<TagInput, ProjectTag>();
182+
CreateMap<ProjectTag, TagOutput>();
183+
CreateMap<ProjectTag, ProjectTagOutput>()
184+
.ForMember(q => q.Id, opt => opt.MapFrom(q => q.Tag.Id))
185+
.ForMember(q => q.Name, opt => opt.MapFrom(q => q.Tag.Name));
178186

179187
CreateExternalSourceMappingProfiles();
180188
}

0 commit comments

Comments
 (0)