Skip to content

Commit

Permalink
Merge pull request #548 from DigitalExcellence/develop
Browse files Browse the repository at this point in the history
v.1.10.0-beta 16-12-2021
  • Loading branch information
MeesvanStraten authored Dec 16, 2021
2 parents 79a975e + 698e6f4 commit 3dedcc6
Show file tree
Hide file tree
Showing 40 changed files with 4,240 additions and 217 deletions.
35 changes: 35 additions & 0 deletions API.Tests/Controllers/ProjectControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using Xunit;
using API.Tests.Enums;
using API.Tests.Helpers;
using API.Resources;
using API.InputOutput.Tag;
using System.Collections.Generic;

namespace API.Tests.Controllers
{
Expand Down Expand Up @@ -112,5 +115,37 @@ public async Task CategorizeProject_Returns_Expected_Result_For_All_Roles(UserRo
// Assert
response.StatusCode.Should().Be(expectedResult);
}

[Theory]
[InlineData(UserRole.Admin, HttpStatusCode.OK)]
[InlineData(UserRole.DataOfficer, HttpStatusCode.OK)]
[InlineData(UserRole.PrUser, HttpStatusCode.OK)]
[InlineData(UserRole.RegisteredUser, HttpStatusCode.OK)]
public async Task Update_Tag_Returns_Expected_Result_For_All_Roles(UserRole role, HttpStatusCode expectedResult)
{
// Arrange
await AuthenticateAs(role);
ProjectInput projectInput = SeedUtility.RandomProjectInput();
projectInput.Tags = new List<TagInput>() {
new TagInput() { Name = "java" }
};
HttpResponseMessage postProjectResponse = await TestClient.PostAsJsonAsync("project", projectInput);
string responseContent = await postProjectResponse.Content.ReadAsStringAsync();

int projectId = JsonConvert.DeserializeObject<Project>(responseContent).Id;

ProjectInput project = JsonConvert.DeserializeObject<ProjectInput>(responseContent);

project.Tags = new List<TagInput>() {
new TagInput() { Name = "csharp" },
new TagInput() { Name = "java" }
};

// Act
HttpResponseMessage response = await TestClient.PutAsJsonAsync("project/" + projectId, projectInput);

// Assert
response.StatusCode.Should().Be(expectedResult);
}
}
}
39 changes: 34 additions & 5 deletions API.Tests/Helpers/SeedUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Models;
using System.Collections.Generic;
using System.Linq;
using API.Resources;

namespace API.Tests.Helpers
{
Expand All @@ -14,18 +15,30 @@ public class SeedUtility
public static Project RandomProject()
{
Faker<Project> projectToFake = new Faker<Project>()
.RuleFor(p => p.UserId, 1)
.RuleFor(p => p.Uri, f => f.Internet.Url())
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
.RuleFor(p => p.UserId, 1)
.RuleFor(p => p.Uri, f => f.Internet.Url())
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
Project project = projectToFake.Generate();
project.Created = DateTime.Now.AddDays(-2);
project.Updated = DateTime.Now;

return project;
}

public static ProjectInput RandomProjectInput()
{
Faker<ProjectInput> projectToFake = new Faker<ProjectInput>()
.RuleFor(p => p.Uri, f => f.Internet.Url())
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
.RuleFor(p => p.Description, f => f.Lorem.Sentences(10))
.RuleFor(p => p.ShortDescription, f => f.Lorem.Sentences(1));
ProjectInput project = projectToFake.Generate();

return project;
}

public static Category RandomCategory()
{
Faker<Category> categoryToFake = new Faker<Category>()
Expand All @@ -35,6 +48,22 @@ public static Category RandomCategory()
return category;
}

public static List<Tag> RandomTags()
{
List<Tag> tags = new List<Tag>();
for(int i = 0; i < 3; i++)
{
Faker<Tag> tagToFake = new Faker<Tag>()
.RuleFor(t => t.Name, f => f.Hacker.Adjective());

Tag tag = tagToFake.Generate();

tags.Add(tag);
}

return tags;
}

public static Highlight RandomHighlight()
{
Faker<Highlight> highlightToFake = new Faker<Highlight>()
Expand Down
8 changes: 8 additions & 0 deletions API/Configuration/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* If not, see https://www.gnu.org/licenses/lgpl-3.0.txt
*/

using API.InputOutput.Tag;
using API.Resources;
using AutoMapper;
using Models;
Expand Down Expand Up @@ -175,6 +176,13 @@ public MappingProfile()
.ForMember(dest => dest.InstititutionName, opt => opt.MapFrom(src => src.Institution.Name))
.ForMember(dest => dest.ProjectName, opt => opt.MapFrom(src => src.Project.Name));

CreateMap<Tag, TagOutput>();
CreateMap<TagInput, Tag>();
CreateMap<TagInput, ProjectTag>();
CreateMap<ProjectTag, TagOutput>();
CreateMap<ProjectTag, ProjectTagOutput>()
.ForMember(q => q.Id, opt => opt.MapFrom(q => q.Tag.Id))
.ForMember(q => q.Name, opt => opt.MapFrom(q => q.Tag.Name));

CreateExternalSourceMappingProfiles();
}
Expand Down
Loading

0 comments on commit 3dedcc6

Please sign in to comment.