Esempio n. 1
0
        public async Task GetAllForMakeShouldReturnAllModelsForMake()
        {
            var options = new DbContextOptionsBuilder <NeedForCarsDbContext>()
                          .UseInMemoryDatabase("ModelGetAllDb")
                          .Options;

            var context = new NeedForCarsDbContext(options);

            var makesService  = new MakesService(context);
            var modelsService = new ModelsService(context, makesService);

            var make = new Make
            {
                Name        = "Make",
                Description = "Desc"
            };

            await context.Makes.AddAsync(make);

            await context.SaveChangesAsync();

            var model1 = new Model
            {
                Name        = "Model1",
                Description = "Desc",
                MakeId      = make.Id
            };
            var model2 = new Model
            {
                Name        = "Model2",
                Description = "Desc",
                MakeId      = make.Id
            };

            await context.Models.AddAsync(model1);

            await context.Models.AddAsync(model2);

            await context.SaveChangesAsync();

            var result = modelsService.GetAllForMake(make.Id).Count();

            Assert.Equal(2, result);
        }