1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using AutoMapper;
- using AutoMapper.Configuration;
- using Backend.Data;
- using Backend.Data.Interfaces;
- using Backend.Services;
- using Backend.Services.Interface;
- using Backend.Services.Mapper;
- using Microsoft.Extensions.Logging;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using NSubstitute;
- using System;
- using System.Collections.Generic;
-
- namespace Backend.MSTest
- {
- [TestClass]
- public class LigneCommandeServiceTest
- {
- private readonly ILigneCommandeRepository _LigneCommandeRepository;
- private readonly ILogger<LigneCommandeService> _log;
- private readonly IMapper _mapper;
-
- public LigneCommandeServiceTest()
- {
- _log = Substitute.For<ILogger<LigneCommandeService>>();
- _LigneCommandeRepository = Substitute.For<ILigneCommandeRepository>();
-
- var mapperCfg = new MapperConfigurationExpression();
- mapperCfg.AddProfile<AutoMapperProfile>();
- _mapper = new Mapper(new MapperConfiguration(mapperCfg));
-
-
- }
-
- [TestMethod]
- public void GetPrice_passing_listecommande_with_empty_elt_Return_1()
- {
- List<LigneCommande> list = new List<LigneCommande>();
-
- LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
-
- var result = ligneCommandeService.GetPrice(list);
-
- Assert.AreEqual(result.Result, 1);
- }
-
- [TestMethod]
- public void GetPrice_passing_listecommande_with_one_elt_Return_1()
- {
- List<LigneCommande> list = new List<LigneCommande>
- {
- new LigneCommande()
- };
-
- LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
-
- var result = ligneCommandeService.GetPrice(list);
-
- Assert.AreEqual(result.Result, 1);
- }
-
- [TestMethod]
- public void GetPrice_passing_listecommande_with_many_elt_Return_Fibonacci_number()
- {
- List<LigneCommande> list = new List<LigneCommande>
- {
- new LigneCommande{
- Prix = 5
- },
- new LigneCommande{
- Prix = 3
- },
- new LigneCommande{
- Prix = 2
- },
- new LigneCommande{
- Prix = 1
- }
- };
-
- LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
-
- var result = ligneCommandeService.GetPrice(list);
-
- Assert.AreEqual(result.Result, 8);
- }
-
- }
- }
|