daily pastebin goal
79%
SHARE
TWEET

Untitled

a guest Aug 16th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using DriversPermits;
  2. using DriversPermits.Data.Enitities;
  3. using DriversPermits.Services;
  4. using Microsoft.EntityFrameworkCore;
  5. using Moq;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using Xunit;
  11. using Xunit.Abstractions;
  12.  
  13. namespace DriversPermitsTests
  14. {
  15.     public class ContactServiceTests
  16.     {
  17.         private IList<Contact> _contacts;
  18.         private ContactService _contactService;
  19.         private readonly ITestOutputHelper _output;
  20.  
  21.         public ContactServiceTests(ITestOutputHelper output)
  22.         {
  23.             _output = output;
  24.             _contacts = new List<Contact>
  25.             {
  26.                 new Contact
  27.                 {
  28.                     FirstName = "Dan",
  29.                     LastName = "Giddins",
  30.                     Description = "Lazy - Slow",
  31.                     Email = "dan.giddins@email.com",
  32.                     PhoneNumber = 12345
  33.                 },
  34.                 new Contact
  35.                 {
  36.                     FirstName = "Len",
  37.                     LastName = "Noddons",
  38.                     Description = "Fast - Good",
  39.                     Email = "den.goddons@fmail.com",
  40.                     PhoneNumber = 67890
  41.                 }
  42.             };
  43.             var permitsContext = new PermitsContext(
  44.                 new DbContextOptionsBuilder<PermitsContext>()
  45.                 .UseInMemoryDatabase("ContactServiceTests")
  46.                 .Options);
  47.  
  48.             permitsContext.Contacts.AddRange(_contacts);
  49.             permitsContext.SaveChanges();
  50.  
  51.             _contactService = new ContactService(permitsContext);
  52.         }
  53.  
  54.         [Fact]
  55.         public async void ListAsync_ReturnsAllRecords()
  56.         {
  57.             var actual = await _contactService.ListAsync();
  58.             Assert.Equal(_contacts.Count(), actual.Count());
  59.             _contacts.OrderBy(x => x.Email);
  60.             actual.OrderBy(x => x.Email);
  61.             for (int i = 0; i < _contacts.Count(); i++)
  62.             {
  63.                 foreach (PropertyInfo p in typeof(Contact).GetProperties())
  64.                 {
  65.                     if (p.Name != "Id")
  66.                     {
  67.                         _output.WriteLine(p.GetValue(_contacts[i]).ToString());
  68.                         _output.WriteLine(p.GetValue(actual[i]).ToString());
  69.                         Assert.Equal(p.GetValue(_contacts[i]), p.GetValue(actual[i]));
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top