No Description

LigneCommandeServiceTest.cs 2.7KB

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

Powered by TurnKey Linux.