public void Can_Remove_Service_From_Contractor()
        {
            LegalPerson legalPersonForContractor1 = new LegalPerson("12345678902", "Contractor 1 d.o.o.");
            Contractor contractor1 = new Contractor(legalPersonForContractor1);
            LegalPerson legalPersonForContractor2 = new LegalPerson("12345678903", "Contractor 2 d.o.o.");
            Contractor contractor2 = new Contractor(legalPersonForContractor2);
            LegalPerson legalPersonForContractor3 = new LegalPerson("12345678904", "Contractor 3 d.o.o.");
            Contractor contractor3 = new Contractor(legalPersonForContractor3);

            Contractor[] contractors = new Contractor[] {
                contractor1,
                contractor2,
                contractor3
            };

            LegalPerson legalPersonForManager = new LegalPerson("12345678901", "Mile d.o.o.");

            BuildingManager buildingManager = new BuildingManager(legalPersonForManager, contractors);

            // Act
            buildingManager.RemoveContractor(contractor2);

            // Assert
            Assert.AreEqual(2, buildingManager.Contractors.Count);
            Assert.AreEqual(contractor1, buildingManager.Contractors[0]);
            Assert.AreEqual(contractor3, buildingManager.Contractors[1]);
        }
        public void Can_Add_Contractors_To_BuildingManager()
        {
            // Arrange
            LegalPerson legalPersonForContractor1 = new LegalPerson("12345678902", "Contractor 1 d.o.o.");
            Contractor contractor1 = new Contractor(legalPersonForContractor1);
            LegalPerson legalPersonForContractor2 = new LegalPerson("12345678903", "Contractor 2 d.o.o.");
            Contractor contractor2 = new Contractor(legalPersonForContractor2);

            Contractor[] contractors = new Contractor[] {
                contractor1,
                contractor2
            };

            LegalPerson legalPersonForContractor3 = new LegalPerson("12345678904", "Contractor 3 d.o.o.");
            Contractor contractor3 = new Contractor(legalPersonForContractor3);

            LegalPerson legalPersonForManager = new LegalPerson("12345678901", "Mile d.o.o.");

            // Act
            BuildingManager buildingManager = new BuildingManager(legalPersonForManager, contractors);
            buildingManager.AddContractor(contractor3);

            // Assert
            Assert.AreEqual(3, buildingManager.Contractors.Count);
            Assert.AreEqual(contractor1, buildingManager.Contractors[0]);
            Assert.AreEqual(contractor2, buildingManager.Contractors[1]);
            Assert.AreEqual(contractor3, buildingManager.Contractors[2]);
        }
        public void BuildingManager_Can_Set_Cotractor_For_Maitenance()
        {
            // Arrange
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(person, "Kvar", "Ne radi grijanje.", "Stan Mile, prvi kat.");

            RepairService serviceTypeForMock = new RepairService("Ličenje");
            Mock<IRepairServicesRepository> repairServicesRepositoryMock = new Mock<IRepairServicesRepository>();
            repairServicesRepositoryMock.Setup(x => x.GetById(23)).Returns(serviceTypeForMock);

            RepairService serviceType = repairServicesRepositoryMock.Object.GetById(23);
            Maintenance maintenance = new Maintenance(maintenanceRequest, Urgency.High, serviceType, building);

            LegalPerson legalPerson = new LegalPerson("12345678901", "Mile d.o.o.");
            Contractor contractor = new Contractor(legalPerson).AddRepairService(serviceType);

            BuildingManager buildingManager = maintenance.BuildingManager;
            buildingManager.AddContractor(contractor);

            // Act
            buildingManager.SetContractorForMaintenance(contractor, maintenance);

            // Assert
            Assert.IsNotNull(maintenance.Contractor);
            Assert.AreEqual(new PersonSnapshot(contractor.LegalPerson), maintenance.Contractor );
        }
        public void Can_Create_Contractor()
        {
            // Arrange
            LegalPerson legalPerson = new LegalPerson("12345678901", "Mile d.o.o.");

            // Act
            Contractor contractor = new Contractor(legalPerson);

            // Assert
            Assert.IsNotNull(contractor);
            Assert.AreEqual(legalPerson, contractor.LegalPerson);
            Assert.IsFalse(contractor.RepairServices.Any());
        }
        public void Can_Add_Services_To_Contractor()
        {
            // Arrange
            LegalPerson legalPerson = new LegalPerson("12345678901", "Mile d.o.o.");

            RepairService repairService1 = new RepairService("Ličenje");
            RepairService repairService2 = new RepairService("vodovodne cijevi");
            RepairService[] repairServices = new RepairService[] {
                repairService1,
                repairService2
            };

            // Act
            Contractor contractor = new Contractor(legalPerson, repairServices);
            RepairService repairService3 = new RepairService("parketi");
            contractor.AddRepairService(repairService3);

            // Assert
            Assert.AreEqual(3, contractor.RepairServices.Count);
            Assert.AreEqual(repairService1, contractor.RepairServices[0]);
            Assert.AreEqual(repairService2, contractor.RepairServices[1]);
            Assert.AreEqual(repairService3, contractor.RepairServices[2]);
        }
        public void Can_Remove_Service_From_Contractor()
        {
            // Arrange
            LegalPerson legalPerson = new LegalPerson("12345678901", "Mile d.o.o.");

            RepairService repairService1 = new RepairService("Ličenje");
            RepairService repairService2 = new RepairService("vodovodne cijevi");
            RepairService repairService3 = new RepairService("parketi");
            RepairService[] repairServices = new RepairService[] {
                repairService1,
                repairService2,
                repairService3
            };

            Contractor contractor = new Contractor(legalPerson, repairServices);

            // Act
            contractor.RemoveRepairService(repairService2);

            // Assert
            Assert.AreEqual(2, contractor.RepairServices.Count);
            Assert.AreEqual(repairService1, contractor.RepairServices[0]);
            Assert.AreEqual(repairService3, contractor.RepairServices[1]);
        }
 /// <summary>
 /// Brise izvodaca radoba
 /// </summary>
 /// <param name="contractor"></param>
 /// <returns>true ako je brisanje uspjelo, inace false</returns>
 public bool RemoveContractor(Contractor contractor)
 {
     return contractors.Remove(contractor);
 }
 /// <summary>
 /// Dodaje izvodaca radova
 /// </summary>
 /// <param name="contractor">izvodac radova</param>
 public void AddContractor(Contractor contractor)
 {
     contractors.Add(contractor);
 }
        /// <summary>
        /// Dodjeljuje izvodaca radova na popravak ili odrzavanje
        /// </summary>
        /// <param name="contractor">izvodac radova</param>
        /// <param name="maintenance">popravak ili odrzavanje</param>
        public void SetContractorForMaintenance(Contractor contractor, Maintenance maintenance)
        {
            var errors = new RulesException<BuildingManager>();

            if(!contractors.Contains(contractor)) {
                errors.ErrorForModel("Contractor is not working for BuildingManager, so it's invalid.");
            }

            if (!Equals(maintenance.BuildingManager)) {
                errors.ErrorForModel("This BuildingManager is not in charge of a builing in given maintenance.");
            }

            if (!contractor.RepairServices.Contains(maintenance.ServiceType)) {
                errors.ErrorForModel("This Contractor can't do needed service.");
            }

            if(errors.Errors.Any()) {
                throw errors;
            }

            maintenance.SetContractor(contractor);
        }
Esempio n. 10
0
 /// <summary>
 /// Postavlja izvodaca radova
 /// </summary>
 /// <param name="contractor"></param>
 internal void SetContractor(Contractor contractor)
 {
     this.contractor = new PersonSnapshot(contractor.LegalPerson);
     statusOfMaintenance = StatusOfMaintenance.InProgress;
 }