No Description

LigneCommandeServiceTest.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using AutoMapper;
  2. using AutoMapper.Configuration;
  3. using Backend.ApplicationCore.Interfaces.IRepositories;
  4. using Backend.ApplicationCore.Mapper;
  5. using Backend.ApplicationCore.Services;
  6. using Backend.Domain.Entities;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.VisualStudio.TestTools.UnitTesting;
  9. using NSubstitute;
  10. using System;
  11. using System.Collections.Generic;
  12. namespace Backend.MSTest
  13. {
  14. [TestClass]
  15. public class LigneCommandeServiceTest
  16. {
  17. private readonly ILigneCommandeRepository _LigneCommandeRepository;
  18. private readonly ILogger<LigneCommandeService> _log;
  19. private readonly IMapper _mapper;
  20. public LigneCommandeServiceTest()
  21. {
  22. _log = Substitute.For<ILogger<LigneCommandeService>>();
  23. _LigneCommandeRepository = Substitute.For<ILigneCommandeRepository>();
  24. var mapperCfg = new MapperConfigurationExpression();
  25. mapperCfg.AddProfile<AutoMapperProfile>();
  26. _mapper = new Mapper(new MapperConfiguration(mapperCfg));
  27. }
  28. [TestMethod]
  29. public void GetPrice_passing_listecommande_with_empty_elt_Return_1()
  30. {
  31. List<LigneCommande> list = new List<LigneCommande>();
  32. LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
  33. var result = ligneCommandeService.GetPrice(list);
  34. Assert.AreEqual(result.Result, 1);
  35. }
  36. [TestMethod]
  37. public void GetPrice_passing_listecommande_with_one_elt_Return_1()
  38. {
  39. List<LigneCommande> list = new List<LigneCommande>
  40. {
  41. new LigneCommande()
  42. };
  43. LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
  44. var result = ligneCommandeService.GetPrice(list);
  45. Assert.AreEqual(result.Result, 1);
  46. }
  47. [TestMethod]
  48. public void GetPrice_passing_listecommande_with_many_elt_Return_Fibonacci_number()
  49. {
  50. List<LigneCommande> list = new List<LigneCommande>
  51. {
  52. new LigneCommande{
  53. Prix = 5
  54. },
  55. new LigneCommande{
  56. Prix = 3
  57. },
  58. new LigneCommande{
  59. Prix = 2
  60. },
  61. new LigneCommande{
  62. Prix = 1
  63. }
  64. };
  65. LigneCommandeService ligneCommandeService = new LigneCommandeService(_log, _mapper, _LigneCommandeRepository);
  66. var result = ligneCommandeService.GetPrice(list);
  67. Assert.AreEqual(result.Result, 8);
  68. }
  69. }
  70. }

Powered by TurnKey Linux.