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 );
        }
Ejemplo n.º 2
0
        /// <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);
        }
        public void Person_Can_Issue_Maitenance_Request()
        {
            // Arrange
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(person, "Kvar", "Ne radi grijanje.", "Stan Mile, prvi kat.");

            RepairService serviceTypeForMock = new RepairService("Popravci grijanja i toplana");
            Mock<IRepairServicesRepository> repairServicesRepositoryMock = new Mock<IRepairServicesRepository>();
            repairServicesRepositoryMock.Setup(x => x.GetById(23)).Returns(serviceTypeForMock);

            RepairService serviceType = repairServicesRepositoryMock.Object.GetById(23);

            // Act
            Maintenance maintenance = new Maintenance(maintenanceRequest, Urgency.High, serviceType, building);

            // Assert
            Assert.AreEqual(maintenanceRequest, maintenance.MaintenanceRequest);
            Assert.AreEqual(StatusOfMaintenance.NotStarted, maintenance.StatusOfMaintenance);
            Assert.IsNotNull(maintenance.Urgency, "Hitnost nije definirana.");
            Assert.AreEqual(Urgency.High, maintenance.Urgency);
            Assert.IsNotNull(maintenance.ServiceType, "Usluga popravka nije definirana.");
            Assert.AreEqual(serviceType, maintenance.ServiceType);
        }