Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Icon in TechnologyModel is now of Type FileModel,added Technologi… #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions GdscBackend.Tests/TechnologiesControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AutoMapper;
using Faker;
Expand All @@ -19,10 +20,12 @@ namespace GdscBackend.Tests;
public class TechnologiesControllerTests : TestingBase
{
private readonly IMapper _mapper;
private readonly IEnumerable<TechnologyModel> _testData = _getTestData();

private static readonly List<FileModel> _testIcons = _getTestIcons();
private static readonly IEnumerable<TechnologyModel> _testData = _getTestData();

public TechnologiesControllerTests(ITestOutputHelper outputHelper) : base(outputHelper)
{

var mapconfig = new MapperConfiguration(cfg => cfg.AddProfile(new MappingProfiles()));
_mapper = mapconfig.CreateMapper();
}
Expand All @@ -36,13 +39,13 @@ public async void Post_ReturnsCreatedObject()
{
Name = Lorem.Words(3).ToString(),
Description = Lorem.Sentence(7),
Icon = Lorem.Words(1).ToString()
IconId = Lorem.Words(1).ToString()
};
var example2 = new TechnologyRequest
{
Name = Lorem.Words(3).ToString(),
Description = Lorem.Sentence(7),
Icon = Lorem.Words(1).ToString()
IconId = Lorem.Words(1).ToString()
};

var added1 = await controller.Post(example1);
Expand All @@ -60,14 +63,14 @@ public async void Post_ReturnsCreatedObject()
Assert.NotNull(entity1.Id);
Assert.Equal(StatusCodes.Status201Created, result1.StatusCode);
Assert.Equal(example1.Description, entity1.Description);
Assert.Equal(example1.Icon, entity1.Icon);
Assert.Equal(example1.IconId, entity1.Icon.Id);
Assert.Equal(example1.Name, entity1.Name);

Assert.NotNull(entity2);
Assert.NotNull(entity2.Id);
Assert.Equal(StatusCodes.Status201Created, result2.StatusCode);
Assert.Equal(example2.Description, entity2.Description);
Assert.Equal(example2.Icon, entity2.Icon);
Assert.Equal(example2.IconId, entity2.Icon.Id);
Assert.Equal(example2.Name, entity2.Name);
}

Expand Down Expand Up @@ -103,16 +106,38 @@ public async void Delete_ReturnsOkResult()
Assert.Equal(_testData.Count() - 1, repository.DbSet.Count());
}

private static List<FileModel> _getTestIcons()
{
var icons = new List<FileModel>();
for (var i = 0; i < 10; i++)
{
icons.Add(new FileModel
{
Id = Guid.NewGuid().ToString(),
Created = DateTime.UtcNow,
Updated = DateTime.UtcNow,
Name = Lorem.Words(1).ToString(),
Path = Lorem.Words(1).ToString(),
Extension = Lorem.Words(1).ToString(),
Size = RandomNumber.Next(long.MaxValue)
});
}

return icons;
}
private static IEnumerable<TechnologyModel> _getTestData()
{


var models = new List<TechnologyModel>();
for (var _ = 0; _ < 10; _++)
for (var i = 0; i < 10; i++)
models.Add(new TechnologyModel
{
Id = Guid.NewGuid().ToString(),
Name = Lorem.Words(1).ToString(),
Description = Lorem.Words(1).ToString(),
Icon = Lorem.Words(1).ToString()
Icon = _testIcons[i]

});

return models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public class TechnologyModel : Model
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public FileModel Icon { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class TechnologyRequest : Request

public string Description { get; set; }

public string Icon { get; set; }
public string IconId { get; set; }
}
11 changes: 11 additions & 0 deletions GdscBackend/Technologies/TechnologyResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GdscBackend.Technologies;

public class TechnologyResponse
{
public string Name { get; set; }

public string Description { get; set; }

public string Icon { get; set; }

}