forked from Azure/Commercial-Marketplace-SaaS-Accelerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OfferServicesTest.cs
123 lines (102 loc) · 3.26 KB
/
OfferServicesTest.cs
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
using System;
using System.Collections.Generic;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
using Marketplace.SaaS.Accelerator.DataAccess.Entities;
using Marketplace.SaaS.Accelerator.Services.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Marketplace.SaaS.Accelerator.Services.Test;
[TestClass]
public class OfferServicesTest
{
private OffersService offersService;
private int testOfferModelCount = 0;
[TestInitialize]
public void Initialize()
{
var mockOfferRepo = new Mock<IOffersRepository>();
mockOfferRepo
.Setup(x => x.GetOfferById(It.IsAny<Guid>()))
.Returns(CreateTestOfferEntity());
mockOfferRepo
.Setup(x => x.GetAll())
.Returns(CreateTestOfferEntities());
var mockAttributesRepo = new Mock<IOfferAttributesRepository>();
mockAttributesRepo.Setup(x => x.GetAllOfferAttributesByOfferId(It.IsAny<Guid>()))
.Returns(CreateOfferAttributes());
mockAttributesRepo.Setup(x => x.Add(It.IsAny<OfferAttributes>()))
.Returns(1)
.Verifiable();
offersService = new OffersService(mockOfferRepo.Object, mockAttributesRepo.Object);
}
[TestMethod]
public void CanGetAllOffers()
{
var offerEntites = offersService.GetOffers();
Assert.IsNotNull(offerEntites);
Assert.AreEqual(3, offerEntites.Count);
}
[TestMethod]
public void CanGetAnOfferById()
{
var offerEntity = offersService.GetOfferById(Guid.NewGuid());
Assert.IsNotNull(offerEntity);
}
private Offers CreateTestOfferEntity()
{
var offerId = Guid.NewGuid();
return new Offers()
{
CreateDate = DateTime.Now,
Id = testOfferModelCount,
OfferName = "OfferName",
OfferGuid = offerId,
OfferId = offerId.ToString(),
UserId = 1
};
}
private IEnumerable<Offers> CreateTestOfferEntities()
{
List<Offers> offers = new List<Offers>
{
CreateTestOfferEntity(),
CreateTestOfferEntity(),
CreateTestOfferEntity()
};
return offers;
}
private IEnumerable<OfferAttributes> CreateOfferAttributes()
{
var offerAttributes = new List<OfferAttributes>();
int idCounter = 1;
for (int i = 0; i < 3; i++)
{
var offerAttribute = CreateOfferAttribute(idCounter);
offerAttributes.Add(offerAttribute);
}
return offerAttributes;
}
private OfferAttributes CreateOfferAttribute(int idCounter)
{
return new OfferAttributes()
{
CreateDate = DateTime.Now,
Description = "Description",
DisplayName = "DisplayName",
DisplaySequence = idCounter,
FromList = false,
Id = idCounter,
OfferId = Guid.NewGuid(),
UserId = 1,
IsDelete = false,
Isactive = true,
IsRequired = false,
Max = 1,
Min = 1,
ParameterId = "ParameterId",
Type = "Type",
ValueTypeId = 1,
ValuesList = "ValuesList"
};
}
}