public int Add(string name, int wateringPeriod, DateTime lastWateredOn, string username) { Plant plant = plantFactory.CreateInstance(name, wateringPeriod, lastWateredOn); plant.UserId = userRepository.GetByName(username).Id; plantRepository.Add(plant); return(plant.Id); }
public void Add_WhenCalled_AddsPlantToDatabase() { var mockSet = new Mock <DbSet <Plant> >(); var mockContext = new Mock <PlantAppDbContext>(); mockContext.Setup(m => m.Plants).Returns(mockSet.Object); var service = new PlantRepository(mockContext.Object); var plant = new Plant("plant1", 1, DateTime.UtcNow); service.Add(plant); mockSet.Verify(m => m.Add(It.IsAny <Plant>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }