public void CreateManufacturerWithoutNameThrowsException() { var manufacturerRepo = new Mock <IManufacturerRepository>(); IManufacturerService manufacturerService = new ManufacturerService(manufacturerRepo.Object); var manufacturer = new Manufacturer() { Id = 1 }; var e = Assert.Throws <ArgumentException>(() => manufacturerService.Create(manufacturer)); Assert.Equal("Name cannot be null or empty", e.Message); }
public void CreateManufacturerEnsureRepositoryIsCalled() { var manufacturerRepo = new Mock <IManufacturerRepository>(); IManufacturerService manufacturerService = new ManufacturerService(manufacturerRepo.Object); var isCalled = false; var manufacturer = new Manufacturer() { Id = 1, Name = "Phantom" }; manufacturerRepo.Setup(x => x.Create(manufacturer)).Callback(() => isCalled = true).Returns(manufacturer); manufacturerService.Create(manufacturer); Assert.True(isCalled); }
public void Create(ManufacturerViewModel model) { var manufacturerModel = new ManufacturerModel { Name = model.Name, Details = model.Details.Select(x => new DetailModel { Price = x.Price, CarId = x.CarId, ManufacturerId = x.ManufacturerId, TypeId = x.TypeId }).ToList(), Cars = model.Cars.Select(x => new CarModel { Model = x.Model, ManufacturerId = x.ManufacturerId }).ToList() }; manufacturerService.Create(manufacturerModel); }