Demo entry 6663292

mc_1

   

Submitted by mc_1 on Nov 29, 2017 at 21:20
Language: C#. Code size: 873 Bytes.

private ApiContext _context;

public TestClothesRepository()
{
    var serviceProvider = new ServiceCollection()
        .AddEntityFrameworkInMemoryDatabase()
        .BuildServiceProvider();

    var optionsBuilder = new DbContextOptionsBuilder<ApiContext>();
    optionsBuilder.UseInMemoryDatabase(nameof(ClothingRental))
                  .UseInternalServiceProvider(serviceProvider);
    _context = new ApiContext(optionsBuilder.Options);

    _context.Cloths.AddRange(GetTestProducts());
    _context.SaveChanges();
}

[Fact]
public void Get_ShouldReturnAllProducts()
{
    var testClothes = GetTestProducts();

    IEnumerable<Cloth> clothes;
    using (var clothesRepository = new ClothesRepository(_context))
    {
        clothes = clothesRepository.GetAll(x => x.Id);
        Assert.Equal(testClothes.Count(), clothes.Count());
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).