コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public ActionResult <List <Plant> > GetAllPlants()
        {
            List <Plant> plants = new List <Plant>();

            plants = PlantRepository.GetAllPlants();
            return(plants);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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
        }
コード例 #7
0
        public IActionResult Plant(int id)
        {
            PlantRepository r = new PlantRepository();
            Plant           p = r.GetPlant(id);

            return(View(p));
        }
コード例 #8
0
 public HomeController(ILogger <HomeController> logger, DataContext dataContext, PlantRepository plantRepository, UserManager <User> userManager)
 {
     _logger          = logger;
     _dataContext     = dataContext;
     _plantRepository = plantRepository;
     _userManager     = userManager;
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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;
                }
            }
        }
コード例 #13
0
        public IActionResult PlantsByShadePreference(string id = "")
        {
            ViewData["Title"] = "Plants by Shade Preference";
            PlantRepository            r     = new PlantRepository();
            PlantsByAttributeViewModel model = r.GetPlantsByShadePreference(id);

            return(View(model));
        }
コード例 #14
0
        public IActionResult PlantsByHabitat(string id = "")
        {
            ViewData["Title"] = "Plants by Habitat";
            PlantRepository            r     = new PlantRepository();
            PlantsByAttributeViewModel model = r.GetPlantsByHabitat(id);

            return(View(model));
        }
コード例 #15
0
 //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;
 }
コード例 #16
0
        public IActionResult PlantsByType()
        {
            ViewData["Title"] = "Plants by Plant Type";
            PlantRepository            r     = new PlantRepository();
            PlantsByAttributeViewModel model = r.GetPlantsByType();

            return(View(model));
        }
コード例 #17
0
        public ActionResult <Plant> GetPlantByName(string name)
        {
            var plant = PlantRepository.GetByName(name);

            if (plant != null)
            {
                return(plant);
            }
            return(NotFound());
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        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());
            }
        }
コード例 #20
0
        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());
            }
        }
コード例 #21
0
        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());
            }
        }
コード例 #22
0
        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());
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
ファイル: DataSource.asmx.cs プロジェクト: douyuagan/101
        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;
            }
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        public PlantController()
        {
            IPlantRepository plantRepository = new PlantRepository();

            _plantService = new PlantService(plantRepository);
        }
コード例 #29
0
ファイル: PlantDomain.cs プロジェクト: asr8320/MegaMine
 public PlantDomain(PlantRepository plantRepository)
 {
     this.plantRepository = plantRepository;
 }
コード例 #30
0
 public PlantsController(DataContext context, PlantRepository plantRepository)
 {
     this._dataContext     = context;
     this._plantRepository = plantRepository;
 }
コード例 #31
0
ファイル: PlantDomain.cs プロジェクト: Nootus/MegaMine
 public PlantDomain(PlantRepository plantRepository)
 {
     this.plantRepository = plantRepository;
 }