public async Task GetByIdShouldReturnCorrectEngine() { var options = new DbContextOptionsBuilder <NeedForCarsDbContext>() .UseInMemoryDatabase("GetEngineByIdDb") .Options; var context = new NeedForCarsDbContext(options); var enginesService = new EnginesService(context); var engine = new Engine { Name = "Name1", FuelType = Models.Enums.FuelType.Diesel, MaxHP = 100, Creator = "Creator" }; await context.Engines.AddAsync(engine); await context.SaveChangesAsync(); var result = enginesService.GetById(engine.Id); Assert.Equal(engine.Id, result.Id); }
public void GetEngineTest() { var uowMock = new Mock <IUnitOfWork>(); var gEngineMock = new Engine { Id = 5, DescElementSelector = "div .rc .s .st", LinkElementSelector = "div .rc .r a", Name = "Google", QueryUrl = "https://www.google.com/search?q=", ResultElementSelector = ".g", TitleElementSelector = "div .rc .r a" }; var id = 5; uowMock.Setup(u => u.Repository <Engine>().GetById(id, false)).Returns(gEngineMock); EnginesService enginesService = new EnginesService(uowMock.Object); OperationDetails od = enginesService.GetById(5); OperationDetails result = new OperationDetails(true, $"Движок с Id={id} найден", "EnginesService.GetById", EnginesService.MapEngineDTO(gEngineMock)); Assert.Equal(od, result); }