public void ItMapsHorse() { // Arrange var service = new HorseService(_fakeRepository); var horse = new HorseCreate { Name = "Test", ColorId = 1, Win = 2, Place = 3, Show = 4, Starts = 5, SireId = 6, DamId = 7 }; // Act service.Create(horse); var actual = _fakeRepository.AddCalledWith; // Assert Assert.Equal(horse.Name, actual.Name); Assert.Equal(horse.ColorId, actual.ColorId); Assert.Equal(horse.Win, actual.RaceWins); Assert.Equal(horse.Place, actual.RacePlace); Assert.Equal(horse.Show, actual.RaceShow); Assert.Equal(horse.Starts, actual.RaceStarts); Assert.Equal(horse.SireId, actual.SireId); Assert.Equal(horse.DamId, actual.DamId); }
public bool CreateHorse(HorseCreate model) { var entity = new Horse() { EmployeeId = _userId, HorseName = model.HorseName, Age = model.Age, Breed = model.Breed, Height = model.Height, Weight = model.Weight, Sex = model.Sex, Color = model.Color, AuctionId = model.AuctionId, //Notes = model.Notes, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Horses.Add(entity); if (entity.AuctionId != null) { var auction = ctx.Auctions.SingleOrDefault(a => a.AuctionId == entity.AuctionId); auction.Horses.Add(entity); } return(ctx.SaveChanges() == 1); } }
public Create() { _horse = new HorseCreate { Name = "Horse" }; _horseServiceMock = new Mock <IHorseService>(); _horseServiceMock.Setup(x => x.Create(It.IsAny <HorseCreate>())) .Verifiable(); _controller = new HorsesController(_horseServiceMock.Object); }
public bool CreateHorse(HorseCreate model) { var entity = new Horse() { Name = model.Name, ClientId = model.ClientId, }; using (var ctx = new ApplicationDbContext()) { ctx.Horses.Add(entity); return(ctx.SaveChanges() == 1); } }
public void Create(HorseCreate horse) { var horseEntity = new Horse { Name = horse.Name, ColorId = horse.ColorId, RaceWins = horse.Win, RacePlace = horse.Place, RaceShow = horse.Show, RaceStarts = horse.Starts, SireId = horse.SireId, DamId = horse.DamId }; _repository.Add(horseEntity); _repository.Save(); }
public ActionResult Create(HorseCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateHorseService(); if (service.CreateHorse(model)) { TempData["SaveResult"] = "The horse has been added."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Horse could not be created."); return(View(model)); }
public IActionResult Create([FromBody] HorseCreate horse) { _horseService.Create(horse); return(Accepted()); }