nassss

Untitled

Apr 24th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Moq;
  3. using RecordStore.Data;
  4. using RecordStore.Data.Models;
  5. using RecordStore.Services.Contracts;
  6. using RecordStore.Services.DTO;
  7. using RecordStore.Services.Mappers;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11.  
  12. namespace RecordStore.Services.Tests.ArtistServiceTests
  13. {
  14. [TestClass]
  15. public class GetArtist_Should
  16. {
  17. [TestMethod]
  18. public void GetCorrectArtist()
  19. {
  20. var options = TestUtils.GetOptions(nameof(GetCorrectArtist));
  21.  
  22. var artist = new Artist
  23. {
  24. Id = 1,
  25. Name = "TestArtist",
  26. Bio = "TestBio"
  27. };
  28. var artistDto = new ArtistDTO
  29. {
  30. Id = 1,
  31. Name = "TestArtist",
  32. Bio = "TestBio"
  33. };
  34.  
  35. var mockSongService = new Mock<ISongService>();
  36. var mockMapper = new Mock<IDTOMapper<Artist, ArtistDTO>>();
  37. mockMapper.Setup(x => x.MapFromEntityToDTO(It.IsAny<Artist>())).Returns(artistDto);
  38.  
  39. using (var arrangeContext = new RecordStoreContext(options))
  40. {
  41. arrangeContext.Add(artist);
  42. arrangeContext.SaveChanges();
  43. }
  44.  
  45. //Act & Assert
  46. using (var assertContext = new RecordStoreContext(options))
  47. {
  48. var sut = new ArtistService(assertContext, mockSongService.Object, mockMapper.Object);
  49. var result = sut.GetArtist(1);
  50.  
  51. Assert.AreEqual(artist.Id, result.Id);
  52. Assert.AreEqual(artist.Name, result.Name);
  53. Assert.AreEqual(artist.Bio, result.Bio);
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment