blob: d38146ff4038992cf826394c6782ed033e7aa03c (
plain) (
blame)
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
|
using AutoMapper;
using DevHive.Data;
using DevHive.Data.Models;
using DevHive.Data.Repositories;
using DevHive.Data.Repositories.Contracts;
using DevHive.Services.Models.Technology;
using DevHive.Services.Services;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using System.Threading.Tasks;
namespace DevHive.Services.Tests
{
[TestFixture]
public class TechnologyServiceTests
{
protected Mock<ITechnologyRepository> TechnologyRepositoryMock { get; set; }
protected Mock<IMapper> MapperMock { get; set; }
protected TechnologyService TechnologyService { get; set; }
[SetUp]
public void Setup()
{
this.TechnologyRepositoryMock = new Mock<ITechnologyRepository>();
this.MapperMock = new Mock<IMapper>();
this.TechnologyService = new TechnologyService(this.TechnologyRepositoryMock.Object, this.MapperMock.Object);
}
#region Create
[Test]
public void Create_ReturnsTrue_WhenEntityIsAddedSuccessfully()
{
Task.Run(async () =>
{
TechnologyServiceModel technologyServiceModel = new TechnologyServiceModel
{
Name = "Some name"
};
Technology technology = new Technology
{
Name = "Some name"
};
this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExist(It.IsAny<string>())).Returns(Task.FromResult(false));
this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Technology>())).Returns(Task.FromResult(true));
this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<TechnologyServiceModel>())).Returns(technology);
bool result = await this.TechnologyService.Create(technologyServiceModel);
Assert.IsTrue(result, "Create returns false when entity is created successfully");
}).GetAwaiter().GetResult();
}
#endregion
[Test]
public void Test()
{
Assert.IsTrue(true);
}
}
}
|