public void GetAll_WhenCalled_ReturnsAllPlants() { var data = new List <Plant> { new Plant("plant1", 1, DateTime.UtcNow) { Id = 1 }, new Plant("plant2", 2, DateTime.UtcNow) { Id = 2 }, }.AsQueryable(); var mockSet = new Mock <DbSet <Plant> >(); mockSet.As <IQueryable <Plant> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Plant> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Plant> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Plant> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <PlantAppDbContext>(); mockContext.Setup(m => m.Plants).Returns(mockSet.Object); var service = new PlantRepository(mockContext.Object); var plants = service.GetAll(); Assert.AreEqual("plant1", plants[0].Name); Assert.AreEqual("plant2", plants[1].Name); }
public void Get_WithPlantMatchingGuidInRepo_ShouldReturnMatchingPlant() { using (var context = new RamosiContext(options)) { // Arrange var plants = new List <Plant>() { new PlantBuilder() .WithGuid(guidOne) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidOne)), new PlantBuilder() .WithGuid(guidTwo) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidTwo)), new PlantBuilder() .WithGuid(guidThree) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidThree)), }; context.Plants.AddRange(plants); context.SaveChanges(); var repo = new PlantRepository(context); // Act var plant = repo.Get(guidTwo); // Assert Assert.AreEqual(guidTwo, plant.Guid); Assert.AreEqual(guidTwo, plant.PlantCharacteristic.Guid); } }
public ActionResult <List <Plant> > GetAllPlants() { List <Plant> plants = new List <Plant>(); plants = PlantRepository.GetAllPlants(); return(plants); }
public ActionResult <(string, string)> GetIncompatibilities(string plantGroupName, string plantName, string accountID) { var plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); if (plantGroup == null) { return(NotFound()); } var plant = PlantRepository.GetByName(plantName); if (plant == null) { return(NotFound()); } List <(Plant, List <IPlantRequirement>)> requirementList = plantGroup.GetAllIncompatibilities(plant); List <(string, string)> expandedList = new List <(string, string)>(); foreach ((Plant, List <IPlantRequirement>)reqPair in requirementList) { foreach (IPlantRequirement req in reqPair.Item2) { expandedList.Add((reqPair.Item1.Name, req.TypeOfReq())); } } return(Ok(expandedList)); }
public void DeletePlantFromPlantGroup(string gardenName, string plantGroupName, string plantName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (string.IsNullOrEmpty(plantGroupName)) { throw new ArgumentException("message", nameof(plantGroupName)); } if (string.IsNullOrEmpty(plantName)) { throw new ArgumentException("message", nameof(plantName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); Plant plant = PlantRepository.GetByName(plantName); //Not sure this is needed? plantGroup.DeletePlant(plant); PlantGroupRepository.DeletePlantFromPlantGroup(plantGroup, plant, accountID); }
public void AddPlantToPlantGroup(string gardenName, string plantGroupName, string plantName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (string.IsNullOrEmpty(plantGroupName)) { throw new ArgumentException("message", nameof(plantGroupName)); } if (string.IsNullOrEmpty(plantName)) { throw new ArgumentException("message", nameof(plantName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); Plant plant = PlantRepository.GetByName(plantName); plantGroup.AddPlant(plant); PlantGroupRepository.AddPlantToPlantGroup(plantGroup, plant, accountID); //should be update }
public IActionResult Plant(int id) { PlantRepository r = new PlantRepository(); Plant p = r.GetPlant(id); return(View(p)); }
public HomeController(ILogger <HomeController> logger, DataContext dataContext, PlantRepository plantRepository, UserManager <User> userManager) { _logger = logger; _dataContext = dataContext; _plantRepository = plantRepository; _userManager = userManager; }
public async Task Delete_WithNoMatchingPlantInRepo_ShouldNotDeleteExistingRecord() { using (var context = new RamosiContext(options)) { // Arrange var plant = new PlantBuilder() .WithGuid(guidOne) .WithName("Plant") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithNotes("This is a characteristic")) .WithPlantCollection(new List <PlantCollection> { new PlantCollectionBuilder().WithNickname("Part of the collection") }); context.Plants.Add(plant); context.SaveChanges(); var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentException>(() => repo.Delete(guidTwo), $"No entity of type Plant with guid {guidTwo} was found"); await repo.SaveChanges(); // Assert Assert.AreEqual(1, context.Plants.Count()); Assert.AreEqual(guidOne, context.Plants.First().Guid); } }
public void Delete_WhenCalled_DeletesPlantFromDatabase() { var data = new List <Plant> { new Plant("plant1", 1, DateTime.UtcNow), new Plant("plant2", 2, DateTime.UtcNow), }.AsQueryable(); var mockSet = new Mock <DbSet <Plant> >(); mockSet.As <IQueryable <Plant> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Plant> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Plant> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Plant> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <PlantAppDbContext>(); mockContext.Setup(m => m.Plants).Returns(mockSet.Object); var service = new PlantRepository(mockContext.Object); service.Delete(mockContext.Object.Plants.First()); mockSet.Verify(m => m.Remove(It.IsAny <Plant>()), Times.Once); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public async Task Create_WithPlant_ShouldSavePlantInDatabase() { using (var context = new RamosiContext(options)) { // Arrange var plant = new PlantBuilder() .WithName("Plant") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithNotes("This is a characteristic")) .WithPlantCollection(new List <PlantCollection> { new PlantCollectionBuilder().WithNickname("Part of the collection") }); var repo = new PlantRepository(context); // Act repo.Create(plant); await repo.SaveChanges(); // Assert Assert.AreEqual(1, context.Plants.Count()); var created = context.Plants.First(); Assert.AreEqual("Plant", created.Name); Assert.AreEqual("This is a characteristic", created.PlantCharacteristic.Notes); Assert.AreEqual(1, created.PlantCollection.Count); Assert.AreEqual("Part of the collection", created.PlantCollection.First().Nickname); } }
public Kwekerij(string bedrijfsnaam, string straat, string postcode, string plaats, string telefoonnummer, string faxnummer, string mobiel, string email, string iban, string btwNummer, string kvkNummer) { // Initialize Properties Bedrijfsnaam = bedrijfsnaam; Straat = straat; Postcode = postcode; Plaats = plaats; Telefoonnummer = telefoonnummer; Faxnummer = faxnummer; Mobiel = mobiel; Email = email; Iban = iban; BtwNummer = btwNummer; KvkNummer = kvkNummer; // Initialize Repositories with Contexts klantRepo = new KlantRepository(new KlantSQLiteContext()); bestellingRepo = new BestellingRepository(new BestellingSQLiteContext()); plantRepo = new PlantRepository(new PlantSQLiteContext()); // Initialize Lists Klanten = new ObservableCollection <Klant>(klantRepo.GetAll()); Planten = new ObservableCollection <Plant>(plantRepo.GetAll()); Bestellingen = new ObservableCollection <Bestelling>(bestellingRepo.GetAll()); // Bind foreach (Bestelling bestelling in Bestellingen) { bestelling.Klant = Klanten.Single(k => k.Id == bestelling.Klant.Id); foreach (Bestelregel bestelregel in bestelling.Bestelregels) { bestelregel.Plant = Planten.Single(p => p.Id == bestelregel.Plant.Id); } } // Initialialize Change Events in Observable Lists Klanten.CollectionChanged += ObservableListCollection_CollectionChanged; foreach (Klant klant in Klanten) { klant.PropertyChanged += ItemPropertyChanged; } Planten.CollectionChanged += ObservableListCollection_CollectionChanged; foreach (Plant plant in Planten) { plant.PropertyChanged += ItemPropertyChanged; } Bestellingen.CollectionChanged += ObservableListCollection_CollectionChanged; foreach (Bestelling bestelling in Bestellingen) { bestelling.PropertyChanged += ItemPropertyChanged; bestelling.Bestelregels.CollectionChanged += ObservableListCollection_CollectionChanged; foreach (Bestelregel bestelregel in bestelling.Bestelregels) { bestelregel.Leveringen.CollectionChanged += ObservableListCollection_CollectionChanged; } } }
public IActionResult PlantsByShadePreference(string id = "") { ViewData["Title"] = "Plants by Shade Preference"; PlantRepository r = new PlantRepository(); PlantsByAttributeViewModel model = r.GetPlantsByShadePreference(id); return(View(model)); }
public IActionResult PlantsByHabitat(string id = "") { ViewData["Title"] = "Plants by Habitat"; PlantRepository r = new PlantRepository(); PlantsByAttributeViewModel model = r.GetPlantsByHabitat(id); return(View(model)); }
//te doen - zorg ervoor dat de aantal en uploadsdatum te zien zijn voor andere gebruikers - zorg ook voor checks of ze er zijn wanneer je dit doet. public PlantsController(DataContext context, UserManager <User> userManager, UploadService upload, PlantRepository plantRepository) { _context = context; _userManager = userManager; _uploadService = upload; _plantRepository = plantRepository; }
public IActionResult PlantsByType() { ViewData["Title"] = "Plants by Plant Type"; PlantRepository r = new PlantRepository(); PlantsByAttributeViewModel model = r.GetPlantsByType(); return(View(model)); }
public ActionResult <Plant> GetPlantByName(string name) { var plant = PlantRepository.GetByName(name); if (plant != null) { return(plant); } return(NotFound()); }
public void Get_WithNoPlantsInRepo_ShouldReturnNull() { using (var context = new RamosiContext(options)) { // Arrange var repo = new PlantRepository(context); // Act var plant = repo.Get(guidOne); // Assert Assert.IsNull(plant); } }
public void GetAll_WithNoPlantsInRepo_ShouldReturnEmptyCollection() { using (var context = new RamosiContext(options)) { // Arrange var repo = new PlantRepository(context); // Act var plants = repo.Get(); // Assert Assert.IsFalse(plants.Any()); } }
public void Create_WithNullPlant_ShouldNotSavePlant() { using (var context = new RamosiContext(options)) { // Arrange var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentNullException>(() => repo.Create(null), "Entity of type Plant cannot be null"); // Assert Assert.IsFalse(context.Plants.Any()); } }
public async Task Delete_WithNoPlantsInRepo_ShouldNotModifyDatabase() { using (var context = new RamosiContext(options)) { // Arrange var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentException>(() => repo.Delete(guidOne), $"No entity of type Plant with guid {guidOne} was found"); await repo.SaveChanges(); // Assert Assert.IsFalse(context.Plants.Any()); } }
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()); }
public async Task Edit_WithPlantWithMatchingGuidInRepo_ShouldNotEditPlantCharacteristicOrPlantCollection() { using (var context = new RamosiContext(options)) { // Arrange var plants = new List <Plant>() { new PlantBuilder() .WithName("one") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithNotes("note one")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder().WithNickname("nickname one") }), }; context.Plants.AddRange(plants); context.SaveChanges(); var plant = new PlantBuilder() .WithName("changed one!") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithNotes("changed note one!")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder().WithNickname("changed nickname one!") }); var repo = new PlantRepository(context); // Act repo.Edit(plant); await repo.SaveChanges(); // Arrange Assert.AreEqual(1, context.Plants.Count()); var plantsInDb = context.Plants.ToList(); Assert.AreEqual(guidOne, plantsInDb[0].PlantCharacteristic.Guid); Assert.AreEqual("note one", plantsInDb[0].PlantCharacteristic.Notes); Assert.AreEqual(guidOne, plantsInDb[0].PlantCollection[0].Guid); Assert.AreEqual("nickname one", plantsInDb[0].PlantCollection[0].Nickname); } }
public List <Plant> FetchFordTree() { try { List <Plant> ret = PlantRepository.GetPlants(true); FISLogging.Log("[200-OK] Params: "); return(ret); } catch (Exception ex) { FISLogging.Log("[E] Exception Encountered: " + ex.Message); FISLogging.Log("[E-P] Params: "); FISLogging.Log("[E-ST] " + ex.StackTrace); HttpContext.Current.Response.StatusCode = 500; throw ex; } }
public static (AccessService, Mock <IGraphService>) Factory(QueueReceiverServiceContext context) { var personCreatedByCache = new PersonCreatedByCache(111) { Username = "******" }; var personRepository = new PersonRepository(context); var graphServiceMock = new Mock <IGraphService>(); var projectRepositoryMock = new Mock <IProjectRepository>(); var personProjectRepositoryMock = new Mock <IPersonProjectRepository>(); var personServiceLoggerMock = new Mock <ILogger <PersonService> >(); var personService = new PersonService(personRepository, graphServiceMock.Object, projectRepositoryMock.Object, personCreatedByCache, personProjectRepositoryMock.Object, personServiceLoggerMock.Object); var personProjectRepository = new PersonProjectRepository(context); var projectRepository = new ProjectRepository(context); var personUserGroupRepository = new PersonUserGroupRepository(context); var userGroupRepository = new UserGroupRepository(context); var personRestrictionRoleRepository = new PersonRestrictionRoleRepository(context); var restrictionRoleRepository = new RestrictionRoleRepository(context); var privilegeService = new PrivilegeService(restrictionRoleRepository, personRestrictionRoleRepository, userGroupRepository, personUserGroupRepository, personCreatedByCache); var personProjectHistoryRepository = new PersonProjectHistoryRepository(context); var plantRepository = new PlantRepository(context); var plantService = new PlantService(plantRepository); var AccessServiceloggerMock = new Mock <ILogger <AccessService> >(); var personProjectServiceLoggerMock = new Mock <ILogger <PersonProjectService> >(); var personProjectService = new PersonProjectService( personProjectRepository, projectRepository, privilegeService, personProjectHistoryRepository, personService, personProjectServiceLoggerMock.Object, personCreatedByCache); var service = new AccessService(personService, personProjectService, plantService, AccessServiceloggerMock.Object, context, personCreatedByCache); return(service, graphServiceMock); }
public void GetAll_WithPlantsInRepo_ShouldReturnAllPlants() { using (var context = new RamosiContext(options)) { // Arrange var plantsInRepo = new List <Plant>() { new PlantBuilder() .WithGuid(guidOne) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidOne)), new PlantBuilder() .WithGuid(guidTwo) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidTwo)), new PlantBuilder() .WithGuid(guidThree) .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidThree)), }; context.Plants.AddRange(plantsInRepo); context.SaveChanges(); var repo = new PlantRepository(context); // Act var plants = repo.Get(); // Assert Assert.AreEqual(3, plants.Count()); var results = plants.ToList(); Assert.AreEqual(guidOne, results[0].Guid); Assert.AreEqual(guidOne, results[0].PlantCharacteristic.Guid); Assert.AreEqual(guidTwo, results[1].Guid); Assert.AreEqual(guidTwo, results[1].PlantCharacteristic.Guid); Assert.AreEqual(guidThree, results[2].Guid); Assert.AreEqual(guidThree, results[2].PlantCharacteristic.Guid); } }
public async Task Delete_WithPlantsInRepo_ShouldOnlyDeletePlantWithMatchingGuid() { using (var context = new RamosiContext(options)) { // Arrange var plants = new List <Plant>() { new PlantBuilder() .WithGuid(guidOne).WithName("one"), new PlantBuilder() .WithGuid(guidTwo).WithName("two") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidTwo)), new PlantBuilder() .WithGuid(guidThree).WithName("three") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithGuid(guidThree)) }; context.Plants.AddRange(plants); context.SaveChanges(); var repo = new PlantRepository(context); // Act repo.Delete(guidTwo); await repo.SaveChanges(); // Assert Assert.AreEqual(2, context.Plants.Count()); var plantsInRepo = context.Plants.ToList(); Assert.AreEqual(guidOne, plantsInRepo[0].Guid); Assert.AreEqual("one", plantsInRepo[0].Name); Assert.AreEqual(guidThree, plantsInRepo[1].Guid); Assert.AreEqual("three", plantsInRepo[1].Name); } }
public PlantController() { IPlantRepository plantRepository = new PlantRepository(); _plantService = new PlantService(plantRepository); }
public PlantDomain(PlantRepository plantRepository) { this.plantRepository = plantRepository; }
public PlantsController(DataContext context, PlantRepository plantRepository) { this._dataContext = context; this._plantRepository = plantRepository; }
public PlantDomain(PlantRepository plantRepository) { this.plantRepository = plantRepository; }