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
            maintenance.SetContractor(contractor);

            // Assert
            var personSnapshot = new PersonSnapshot(contractor.LegalPerson);
            Assert.IsNotNull(maintenance.Contractor);
            Assert.AreEqual(personSnapshot.Oib, maintenance.Contractor.Oib, "Oibs aren't equal.");
            Assert.AreEqual(personSnapshot.FullName, maintenance.Contractor.FullName, "FullNames aren't equal.");
            Assert.AreEqual(personSnapshot.Address, maintenance.Contractor.Address, "Addresses aren't equal.");
            Assert.AreEqual(personSnapshot, maintenance.Contractor);
        }
        public void Can_Save_Maintenance_To_DB()
        {
            // Arrange
            var person = new PhysicalPerson("12345678901", "Ime", "Prezime");
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(
                person
                , "Kvar na grijanju"
                , "Grijanje ne radi"
                , "Prvi kat, stan 2");

            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            RepairService repairService = new RepairService("Popravak grijanja");

            Maintenance maintenance = new Maintenance(maintenanceRequest, Urgency.Normal, repairService, building);

            IMaintenancesRepository maintenancesRepository = new MaintenancesNHRepository(SessionFactory);

            // Act
            IList<Maintenance> maintenancesFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = session.BeginTransaction()) {
                    session.Save(person);
                    session.Save(city);
                    session.Save(legalPerson);
                    session.Save(cadastre);
                    session.Save(landRegistry);
                    session.Save(buildingManager);
                    session.Save(building);
                    session.Save(repairService);

                    maintenancesRepository.SaveOrUpdate(maintenance);

                    tx.Commit();
                }

                using (var tx = session.BeginTransaction()) {
                    maintenancesFromDb = maintenancesRepository.GetAll().ToList();
                    tx.Commit();
                }
            }

            // Assert
            Assert.IsTrue(maintenancesFromDb.Count == 1, "No Maintenance from database.");
        }
Exemplo n.º 3
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 /// <param name="maintenanceRequest">zahtjev za popravkom</param>
 /// <param name="urgency">hitnost</param>
 /// <param name="serviceType">tip servisa/usluge</param>
 /// <param name="building">zgrada za koju se prijavljuje kvar</param>
 public Maintenance(MaintenanceRequest maintenanceRequest, Urgency urgency, RepairService serviceType, Building building)
 {
     this.maintenanceRequest = maintenanceRequest;
     this.building = building;
     this.urgency = urgency;
     this.serviceType = serviceType;
     statusOfMaintenance = StatusOfMaintenance.NotStarted;
     maintenanceRemarks = new List<MaintenanceRemark>();
 }
        public void Can_Create_MaintenanceRequest()
        {
            // Arrange
            LegalPerson person = new LegalPerson("12345678901", "Mile");

            // Act
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(person, "Kvar", "Ne radi grijanje.", "Stan Mile, prvi kat.");

            // Assert
            Assert.IsNotNull(maintenanceRequest, "MaintenanceRequest was not created.");
        }
        public void Date_And_Time_Of_Request_Are_Current_After_Creation()
        {
            // Arrange
            LegalPerson person = new LegalPerson("12345678901", "Mile");
            DateTime theTimeBefore = DateTime.Now.AddMilliseconds(-1);

            // Act
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(person, "Kvar", "Ne radi grijanje.", "Stan Mile, prvi kat.");

            // Assert
            Assert.IsTrue(maintenanceRequest.DateTimeOfRequest > theTimeBefore);
            Assert.IsTrue(maintenanceRequest.DateTimeOfRequest < DateTime.Now.AddMilliseconds(1));
        }
        public ActionResult Create(int id, CreateModel createModel)
        {
            Person submitter = null;
            if(ModelState.IsValid) {
                submitter = personsRepository.GetPersonByUsername(User.Identity.Name);

                MaintenanceRequest maintenanceRequest = new MaintenanceRequest(
                    submitter,
                    createModel.MaintenanceRequest.Subject,
                    createModel.MaintenanceRequest.Description,
                    createModel.MaintenanceRequest.Location);

                RepairService repairService = repairServicesRepository.GetById(createModel.RepairService);
                Building building = buildingsRepository.GetById(id);

                Maintenance maintenance = new Maintenance(
                    maintenanceRequest,
                    createModel.Urgency,
                    repairService,
                    building);

                maintenancesRepository.SaveOrUpdate(maintenance);
                var url = Url.Action("details", "maintenance", new {Id = maintenance.Id}, "http");
                emailNotifier.NotifyOfMaintenanceCreation(maintenance, url);
                return RedirectToAction("index", new { Id = id });

            }

            IList<Building> buildings = null;
            submitter = personsRepository.GetPersonByUsername(User.Identity.Name);
            if (User.IsInRole("owner")) {
                buildings = buildingsRepository.GetBuildingsByOwner(submitter);
            } else if (User.IsInRole("buildingmanager")) {
                buildings = buildingsRepository.GetBuildingsByManager(submitter as LegalPerson);
            } else {
                return new HttpUnauthorizedResult();
            }

            var buildingsModel = Mapper.Map<IList<Building>, IList<BuildingListModel>>(buildings);
            var repairServicesModel = Mapper.Map<IEnumerable<RepairService>, IEnumerable<RepairServiceModel>>(repairServicesRepository.GetAll());
            createModel.RepairServices = new SelectList(repairServicesModel, "Id", "Name");
            createModel.Urgencies = new SelectList(new[] {
                new {Id = (int) Urgency.Low, Name = "Niska"},
                new {Id = (int) Urgency.Normal, Name = "Normalna"},
                new {Id = (int) Urgency.High, Name = "Visoka"}
                }, "Id", "Name");
            createModel.Roles = Roles.GetRolesForUser();

            return View(createModel);
        }
        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);
        }