ObjectMapperUnitTest.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using AutoMapper;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Application.VaporRecoveryOnlineWatchHubApp.UnversalApiModels;
  4. using System;
  5. using Edge.Core.Database.Models;
  6. namespace VaporRecoveryOnlineWatchHubAppTest
  7. {
  8. [TestClass]
  9. public class ObjectMapperUnitTest
  10. {
  11. [TestMethod]
  12. public void TestMethod1()
  13. {
  14. AutoMapper.Mapper objMapper = new AutoMapper.Mapper(
  15. new MapperConfiguration(
  16. configure => { configure.AddProfile<AutoMapperProfile>(); }
  17. ));
  18. double liquidVolume = 328423.23;
  19. double airVolume = 91.23;
  20. DateTime dbEntityCreatTimeStamp = DateTime.Now;
  21. DateTime fuellingStartTime = DateTime.Now.Subtract(new TimeSpan(3, 1, 1));
  22. DateTime fuellingEndTime = DateTime.Now.Subtract(new TimeSpan(2, 1, 1));
  23. var dto = objMapper.Map<VRBoardNozzleTrxFlowData>(new GenericData()
  24. {
  25. IntProperty0 = 1,
  26. IntProperty1 = 99,
  27. IntProperty2 = 4,
  28. IntProperty3 = 24,
  29. StrProperty0 = "#1 dispendser 1",
  30. DoubleProperty0 = liquidVolume,
  31. DoubleProperty1 = airVolume,
  32. CreatedTimeStamp = dbEntityCreatTimeStamp,
  33. TimeStampProperty0 = fuellingStartTime,
  34. TimeStampProperty1 = fuellingEndTime,
  35. });
  36. Assert.AreEqual(true, dto.LiquidVolumeWithDecimal == liquidVolume);
  37. Assert.AreEqual(true, dto.VaporVolumeWithDecimal == airVolume);
  38. Assert.AreEqual(true, dto.TimeStamp == dbEntityCreatTimeStamp);
  39. Assert.AreEqual(true, dto.FuellingStartTime == fuellingStartTime);
  40. Assert.AreEqual(true, dto.FuellingEndTime == fuellingEndTime);
  41. var dbEntity = objMapper.Map<GenericData>(dto);
  42. Assert.AreEqual(true, dbEntity.Owner == AutoMapperProfile.VaporRecoveryOnlineWatchHubApp_MapToDbEntity_Owner);
  43. Assert.AreEqual(true, dbEntity.Type == AutoMapperProfile.VRBoardNozzleTrxFlowData_MapToDbEntity_Type);
  44. Assert.AreEqual(true, dto.LiquidVolumeWithDecimal == dbEntity.DoubleProperty0);
  45. Assert.AreEqual(true, dto.VaporVolumeWithDecimal == dbEntity.DoubleProperty1);
  46. Assert.AreEqual(true, dto.TimeStamp == dbEntity.CreatedTimeStamp);
  47. Assert.AreEqual(true, dto.FuellingStartTime == dbEntity.TimeStampProperty0);
  48. Assert.AreEqual(true, dto.FuellingEndTime == dbEntity.TimeStampProperty1);
  49. }
  50. }
  51. }