예제 #1
0
        public void GetParcel_Success()
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <ParcelController>(Permissions.PropertyView);

            var service            = helper.GetService <Mock <IPimsService> >();
            var mapper             = helper.GetService <IMapper>();
            var expectedTestParcel = new Entity.Parcel(1, 45, 45);

            service.Setup(m => m.Parcel.Get(It.IsAny <int>())).Returns(expectedTestParcel);
            int expectedParcelId = 1;

            // Act
            var result = controller.GetParcel(expectedParcelId);

            // Assert
            var actionResult = Assert.IsType <JsonResult>(result);

            Assert.Null(actionResult.StatusCode);
            var actualResult = Assert.IsType <Model.ParcelModel>(actionResult.Value);

            Assert.Equal(mapper.Map <Model.ParcelModel>(expectedTestParcel), actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Parcel.Get(expectedParcelId), Times.Once());
        }
예제 #2
0
        public void DeleteParcel_Success()
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <ParcelController>(Permissions.PropertyView);

            var parcel  = new Entity.Parcel(1, 51, 25);
            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();

            service.Setup(m => m.Parcel.Remove(It.IsAny <Entity.Parcel>()));

            var model = mapper.Map <SModel.ParcelModel>(parcel);

            // Act
            var result = controller.DeleteParcel(1, model);

            // Assert
            var actionResult   = Assert.IsType <JsonResult>(result);
            var actualResult   = Assert.IsType <SModel.ParcelModel>(actionResult.Value);
            var expectedResult = mapper.Map <SModel.ParcelModel>(parcel);

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Parcel.Remove(It.IsAny <Entity.Parcel>()), Times.Once());
        }
예제 #3
0
        public void GetParcelsWithFilter_Success()
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <ParcelController>(Permissions.PropertyView);

            var parcel  = new Entity.Parcel(1, 51, 25);
            var parcels = new[] { parcel };
            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();

            service.Setup(m => m.Parcel.Get(It.IsAny <ParcelFilter>())).Returns(parcels);
            var filter = new ParcelFilter(1, 1, 1, 1);

            // Act
            var result = controller.GetParcels(filter);

            // Assert
            var actionResult   = Assert.IsType <JsonResult>(result);
            var actualResult   = Assert.IsType <SModel.ParcelModel[]>(actionResult.Value);
            var expectedResult = mapper.Map <SModel.ParcelModel[]>(parcels);

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Parcel.Get(It.IsAny <ParcelFilter>()), Times.Once());
        }
예제 #4
0
        public void GetProperties_OnlyParcels_Success(PropertyFilterModel filter)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <SearchController>(Permissions.PropertyView);

            var parcel1 = new Entity.Parcel(1, 51, 25)
            {
                Id = 1
            };
            var parcel2 = new Entity.Parcel(2, 51, 26)
            {
                Id = 2
            };
            var parcels = new[] { parcel1, parcel2 };

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();

            var items = parcels.Select(p => new ProjectProperty(new Entity.Views.Property(p)));

            service.Setup(m => m.Property.Get(It.IsAny <AllPropertyFilter>())).Returns(items);

            // Act
            var result = controller.GetProperties(filter);

            // Assert
            var actionResult   = Assert.IsType <JsonResult>(result);
            var actualResult   = Assert.IsType <PropertyModel[]>(actionResult.Value);
            var expectedResult = mapper.Map <PropertyModel[]>(parcels);

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Property.Get(It.IsAny <AllPropertyFilter>()), Times.Once());
        }
예제 #5
0
        public void GetProperties_All_Success(PropertyFilterModel filter, bool includeParcels, bool includeBuildings)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <SearchController>(Permissions.PropertyView);

            var parcel    = new Entity.Parcel(1, 51, 25);
            var parcels   = new[] { parcel };
            var building  = new Entity.Building(parcel, 51, 25);
            var buildings = new[] { building };

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();

            var items = parcels.Select(p => new Entity.Views.Property(p))
                        .Concat(buildings.Select(b => new Entity.Views.Property(b))).Select(x => new ProjectProperty(x));

            service.Setup(m => m.Property.Get(It.IsAny <AllPropertyFilter>())).Returns(items);

            // Act
            var result = controller.GetProperties(filter);

            // Assert
            var actionResult   = Assert.IsType <JsonResult>(result);
            var actualResult   = Assert.IsType <PropertyModel[]>(actionResult.Value);
            var expectedResult = mapper.Map <PropertyModel[]>(parcels).Concat(mapper.Map <PropertyModel[]>(buildings));

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Property.Get(It.IsAny <AllPropertyFilter>()), Times.Once());
            Assert.Equal(includeParcels, filter.IncludeParcels);
            Assert.Equal(includeBuildings, filter.IncludeBuildings);
        }
예제 #6
0
        public void ExportPropertiesAllFields_ExcelX_Success(PropertyFilterModel filter)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <PropertyController>(Permissions.PropertyView);
            var headers    = helper.GetService <Mock <Microsoft.AspNetCore.Http.IHeaderDictionary> >();

            headers.Setup(m => m["Accept"]).Returns(ContentTypes.CONTENT_TYPE_EXCELX);

            var parcel    = new Entity.Parcel(1, 51, 25);
            var parcels   = new[] { parcel };
            var building  = new Entity.Building(parcel, 51, 25);
            var buildings = new[] { building };

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();
            var items   = parcels.Select(p => new Entity.Views.Property(p)).Concat(buildings.Select(b => new Entity.Views.Property(b)));
            var page    = new Paged <Entity.Views.Property>(items, filter.Page, filter.Quantity);

            service.Setup(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>())).Returns(page);

            // Act
            var result = controller.ExportPropertiesAllFields(filter);

            // Assert
            var actionResult = Assert.IsType <FileStreamResult>(result);

            Assert.Equal(ContentTypes.CONTENT_TYPE_EXCELX, actionResult.ContentType);
            Assert.NotNull(actionResult.FileDownloadName);
            Assert.True(actionResult.FileStream.Length > 0);
            service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>()), Times.Once());
        }
예제 #7
0
        /// <summary>
        /// Create a new instance of a ParcelFiscal.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parcel"></param>
        /// <param name="fiscalYear"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Entity.ParcelFiscal CreateFiscal(this PimsContext context, Entity.Parcel parcel, int fiscalYear, Entity.FiscalKeys key = Entity.FiscalKeys.Market, decimal value = 1)
        {
            var evaluation = CreateFiscal(parcel, fiscalYear, key, value);

            context.ParcelFiscals.Add(evaluation);
            return(evaluation);
        }
예제 #8
0
        /// <summary>
        /// Creates a new instance of a Building.
        /// </summary>
        /// <param name="parcel"></param>
        /// <param name="id"></param>
        /// <param name="projectNumber"></param>
        /// <param name="name"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="agency"></param>
        /// <returns></returns>
        public static Entity.Building CreateBuilding(Entity.Parcel parcel, int id, string projectNumber = null, string name = null, int lat = 0, int lng = 0, Entity.Agency agency = null)
        {
            projectNumber ??= $"p{id}";
            agency ??= parcel.Agency;
            var address          = EntityHelper.CreateAddress(++parcel.AddressId, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.AdministrativeArea, parcel.Address.Province, parcel.Address.Postal);
            var predominateUse   = EntityHelper.CreateBuildingPredominateUse("use");
            var constructionType = EntityHelper.CreateBuildingConstructionType("type");
            var occupantType     = EntityHelper.CreateBuildingOccupantType("occupant");
            var classification   = EntityHelper.CreatePropertyClassification("classification");

            return(new Entity.Building(parcel, lat, lng)
            {
                Id = id,
                ProjectNumber = projectNumber,
                AgencyId = agency.Id,
                Agency = agency,
                Name = name,
                AddressId = address.Id,
                Address = address,
                Classification = classification,
                ClassificationId = classification.Id,
                Description = $"description-{id}",
                BuildingPredominateUse = predominateUse,
                BuildingPredominateUseId = predominateUse.Id,
                BuildingConstructionType = constructionType,
                BuildingConstructionTypeId = constructionType.Id,
                BuildingOccupantType = occupantType,
                BuildingOccupantTypeId = occupantType.Id,
                CreatedById = Guid.NewGuid(),
                CreatedOn = DateTime.UtcNow,
                UpdatedById = Guid.NewGuid(),
                UpdatedOn = DateTime.UtcNow,
                RowVersion = new byte[] { 12, 13, 14 }
            });
        }
예제 #9
0
        /// <summary>
        /// Create a new instance of a Parcel.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="pid"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="agency"></param>
        /// <returns></returns>
        public static Entity.Parcel CreateParcel(this PimsContext context, int pid, double lat = 0, double lng = 0, Entity.Agency agency = null)
        {
            agency ??= context.Agencies.FirstOrDefault() ?? EntityHelper.CreateAgency(pid);
            var address        = context.CreateAddress(pid, "1234 Street", null, "V9C9C9");
            var classification = context.PropertyClassifications.FirstOrDefault(s => s.Id == 1) ?? EntityHelper.CreatePropertyClassification("classification");

            var parcel = new Entity.Parcel(pid, lat, lng)
            {
                Id               = pid,
                Agency           = agency,
                AgencyId         = agency.Id,
                Address          = address,
                AddressId        = address.Id,
                Classification   = classification,
                ClassificationId = classification.Id,
                Description      = $"description-{pid}",
                CreatedById      = Guid.NewGuid(),
                CreatedOn        = DateTime.UtcNow,
                UpdatedById      = Guid.NewGuid(),
                UpdatedOn        = DateTime.UtcNow,
                RowVersion       = new byte[] { 12, 13, 14 }
            };

            context.Parcels.Add(parcel);
            return(parcel);
        }
예제 #10
0
 /// <summary>
 /// Create a new List with new instances of ParcelEvaluations.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="startDate"></param>
 /// <param name="count"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static List <Entity.ParcelEvaluation> CreateEvaluations(Entity.Parcel parcel, DateTime startDate, int count, Entity.EvaluationKeys key = Entity.EvaluationKeys.Assessed, decimal value = 1)
 {
     for (var i = 0; i < count; i++)
     {
         parcel.Evaluations.Add(CreateEvaluation(parcel, startDate.AddYears(i), key, value));
     }
     return(parcel.Evaluations as List <Entity.ParcelEvaluation>);
 }
예제 #11
0
 /// <summary>
 /// Create a new List with new instances of ParcelFiscal.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="startFiscalYear"></param>
 /// <param name="count"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static List <Entity.ParcelFiscal> CreateFiscals(Entity.Parcel parcel, int startFiscalYear, int count, Entity.FiscalKeys key = Entity.FiscalKeys.Market, decimal value = 1)
 {
     for (var i = startFiscalYear; i < (startFiscalYear + count); i++)
     {
         parcel.Fiscals.Add(CreateFiscal(parcel, i, key, value));
     }
     return(parcel.Fiscals as List <Entity.ParcelFiscal>);
 }
예제 #12
0
 /// <summary>
 /// Create a new List with new instances of ParcelFiscal.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="fiscalYears"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static List <Entity.ParcelFiscal> CreateFiscals(Entity.Parcel parcel, int[] fiscalYears, Entity.FiscalKeys key = Entity.FiscalKeys.Market, decimal value = 1)
 {
     foreach (var fiscalYear in fiscalYears)
     {
         parcel.Fiscals.Add(CreateFiscal(parcel, fiscalYear, key, value));
     }
     return(parcel.Fiscals as List <Entity.ParcelFiscal>);
 }
예제 #13
0
        public void ThrowBadRequestIfNull_ArgumentException(string message)
        {
            // Arrange
            Entity.Parcel parcel = null;

            // Act
            // Assert
            Assert.Throws <ArgumentException>(() => parcel.ThrowBadRequestIfNull(message));
        }
예제 #14
0
        public void ThrowBadRequestIfNull_WithNull()
        {
            // Arrange
            Entity.Parcel parcel = null;

            // Act
            // Assert
            Assert.Throws <BadRequestException>(() => parcel.ThrowBadRequestIfNull("test"));
        }
예제 #15
0
 /// <summary>
 /// Create a new List with new instances of Buildings.
 /// Adds the buildings to the specified 'parcel'.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="startId"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static List <Entity.Building> CreateBuildings(Entity.Parcel parcel, int startId, int count)
 {
     for (var i = startId; i < (startId + count); i++)
     {
         var building = CreateBuilding(parcel, i);
         parcel.Buildings.Add(new Entity.ParcelBuilding(parcel, building));
     }
     return(parcel.Buildings.Select(pb => pb.Building).ToList());
 }
예제 #16
0
        /// <summary>
        /// Make a query to determine if the parcel PID and PIN are unique.
        /// - No two parcels should have the same PID (exception below)
        /// - No two parcels should have the same PIN
        /// - A Crown Land parcel without a Title will have a PID=0 and a unique PIN.
        /// </summary>
        /// <param name="parcels"></param>
        /// <param name="parcel"></param>
        /// <exception type="DbUpdateException">The PID and PIN must be unique.</exception>
        public static void ThrowIfNotUnique(this DbSet <Entity.Parcel> parcels, Entity.Parcel parcel)
        {
            var alreadyExists = parcels.Any(p => p.Id != parcel.Id && ((parcel.PID > 0 && p.PID == parcel.PID) || (parcel.PIN != null && p.PIN == parcel.PIN)));

            if (alreadyExists)
            {
                throw new DbUpdateException("PID and PIN values must be unique.");
            }
        }
예제 #17
0
        public void CopyValues_ArgumentNullException()
        {
            // Arrange
            var o1 = new Entity.Parcel(1, 1, 1);

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => o1.CopyValues((Entity.Parcel)null));
        }
예제 #18
0
        /// <summary>
        /// Make a query to determine if the building names are unique.
        /// - No two buildings should have the same name on a parcel.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parcel"></param>
        /// <param name="building"></param>
        /// <exception type="DbUpdateException">The name within a parcel should be unique.</exception>
        public static void ThrowIfNotUnique(this PimsContext context, Entity.Parcel parcel, Entity.Building building)
        {
            var parcelBuildings = context.Parcels.Where(p => p.Id == parcel.Id).SelectMany(p => p.Buildings.Select(b => b.Building.Name)).Distinct().ToArray();
            var alreadyExists   = parcelBuildings.Contains(building.Name);

            if (alreadyExists)
            {
                throw new DbUpdateException("A building name must be unique on the parcel.");
            }
        }
예제 #19
0
        public void ThrowBadRequestIfNull_WithObject()
        {
            // Arrange
            var parcel = new Entity.Parcel();

            // Act
            parcel.ThrowBadRequestIfNull("test");

            // Assert
            Assert.NotNull(parcel);
        }
예제 #20
0
 /// <summary>
 /// A parcel can only be updated or removed if not within an active project or user has admin-properties permission
 /// </summary>
 /// <param name="service"></param>
 /// <param name="parcel"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static void ThrowIfNotAllowedToUpdate(this BaseService service, Entity.Parcel parcel, ProjectOptions options)
 {
     if (parcel.ProjectNumber != null)
     {
         var project = service.GetContext().Projects
                       .Include(p => p.Workflow)
                       .FirstOrDefault(p => p.ProjectNumber == parcel.ProjectNumber);
         if (project != null && !project.IsProjectEditable(service.GetUser(), options))
         {
             throw new NotAuthorizedException("Cannot update or delete a parcel that is within an active project.");
         }
     }
 }
예제 #21
0
        /// <summary>
        /// Make a query to determine if the parcel PID and PIN are unique.
        /// - No two parcels should have the same PID (exception below)
        /// - No two parcels should have the same PIN
        /// - A Crown Land parcel without a Title will have a PID=0 and a unique PIN.
        /// </summary>
        /// <param name="parcels"></param>
        /// <param name="parcel"></param>
        /// <exception type="DbUpdateException">The PID and PIN must be unique.</exception>
        public static void ThrowIfNotUnique(this DbSet <Entity.Parcel> parcels, Entity.Parcel parcel)
        {
            if (parcel.PropertyTypeId == (int)Entity.PropertyTypes.Subdivision)
            {
                return;
            }
            var alreadyExists = parcels.Any(p => p.Id != parcel.Id && ((parcel.PID > 0 && p.PID == parcel.PID) || (parcel.PIN != null && p.PIN == parcel.PIN)));

            if (alreadyExists)
            {
                throw new DbUpdateException("PID and PIN values must be unique.");
            }
        }
예제 #22
0
 /// <summary>
 /// Create a new instance of a ParcelFiscal.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="fiscalYear"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Entity.ParcelFiscal CreateFiscal(Entity.Parcel parcel, int fiscalYear, Entity.FiscalKeys key = Entity.FiscalKeys.Market, decimal value = 1)
 {
     return(new Entity.ParcelFiscal()
     {
         ParcelId = parcel.Id,
         Parcel = parcel,
         FiscalYear = fiscalYear,
         Key = key,
         Value = value,
         CreatedById = Guid.NewGuid(),
         CreatedOn = DateTime.UtcNow,
         RowVersion = new byte[] { 12, 13, 14 }
     });
 }
예제 #23
0
 /// <summary>
 /// Create a new instance of a ParcelEvaluations.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="date"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Entity.ParcelEvaluation CreateEvaluation(Entity.Parcel parcel, DateTime date, Entity.EvaluationKeys key = Entity.EvaluationKeys.Assessed, decimal value = 1)
 {
     return(new Entity.ParcelEvaluation()
     {
         ParcelId = parcel.Id,
         Parcel = parcel,
         Date = date,
         Key = key,
         Value = value,
         CreatedById = Guid.NewGuid(),
         CreatedOn = DateTime.UtcNow,
         RowVersion = new byte[] { 12, 13, 14 }
     });
 }
예제 #24
0
        public void Not_Equal_Null1()
        {
            // Arrange
            Entity.Parcel parcel1 = null;
            var           parcel2 = EntityHelper.CreateParcel(1);

            var comparer = new DeepPropertyCompare <Entity.Parcel>();

            // Act
            var result = comparer.Equals(parcel1, parcel2);

            // Assert
            Assert.False(result);
        }
예제 #25
0
        public void Not_Equal_Null2()
        {
            // Arrange
            var parcel1 = EntityHelper.CreateParcel(1);

            Entity.Parcel parcel2 = null;

            var comparer = new ShallowPropertyCompare();

            // Act
            var result = comparer.Equals(parcel1, parcel2);

            // Assert
            Assert.False(result);
        }
예제 #26
0
        public void CopyValues()
        {
            // Arrange
            var o1 = new Entity.Parcel(1, 1, 1)
            {
                Description = "test"
            };
            var o2 = new Entity.Parcel(2, 2, 2);

            // Act
            o1.CopyValues(o2);

            // Assert
            o2.PID.Should().Be(o1.PID);
            o2.Description.Should().Be(o1.Description);
            o2.Location.Should().NotBe(o1.Location);
        }
예제 #27
0
파일: BuildingHelper.cs 프로젝트: bcgov/PSP
        /// <summary>
        /// Creates a new instance of a Building.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parcel"></param>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="agency"></param>
        /// <returns></returns>
        public static Entity.Building CreateBuilding(this PimsContext context, Entity.Parcel parcel, int id, string projectNumber = null, string name = null, int lat = 0, int lng = 0, Entity.Agency agency = null)
        {
            name ??= $"l{id}";
            agency ??= parcel?.Agency ?? context.Agencies.FirstOrDefault() ?? EntityHelper.CreateAgency(id);
            var address = (parcel == null ? EntityHelper.CreateAddress(context, id, "1234 Street", null, "V9C9C9") :
                           EntityHelper.CreateAddress(id, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.AdministrativeArea, parcel.Address.Province, parcel.Address.Postal));
            var predominateUse   = context.BuildingPredominateUses.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingPredominateUse("use");;
            var constructionType = context.BuildingConstructionTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingConstructionType("type");
            var occupantType     = context.BuildingOccupantTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingOccupantType("occupant");
            var classification   = context.PropertyClassifications.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreatePropertyClassification("classification");

            var building = new Entity.Building(parcel, lat, lng)
            {
                Id                         = id,
                Name                       = name,
                ProjectNumbers             = projectNumber,
                AgencyId                   = agency.Id,
                Agency                     = agency,
                AddressId                  = address.Id,
                Address                    = address,
                Classification             = classification,
                ClassificationId           = classification.Id,
                Description                = $"description-{id}",
                BuildingPredominateUse     = predominateUse,
                BuildingPredominateUseId   = predominateUse.Id,
                BuildingConstructionType   = constructionType,
                BuildingConstructionTypeId = constructionType.Id,
                BuildingOccupantType       = occupantType,
                BuildingOccupantTypeId     = occupantType.Id,
                CreatedById                = Guid.NewGuid(),
                CreatedOn                  = DateTime.UtcNow,
                UpdatedById                = Guid.NewGuid(),
                UpdatedOn                  = DateTime.UtcNow,
                RowVersion                 = new byte[] { 12, 13, 14 }
            };

            if (parcel != null)
            {
                var parcelBuilding = new Entity.ParcelBuilding(parcel, building);
            }
            context.Buildings.Add(building);
            return(building);
        }
예제 #28
0
        public void GetHashCode_Success()
        {
            // Arrange
            var date = DateTime.UtcNow;
            var o1   = new Entity.Parcel(1, 1, 1)
            {
                CreatedOn = date
            };
            var o2 = new Entity.Parcel(1, 1, 1)
            {
                CreatedOn = date
            };

            var comparer = new ShallowPropertyCompare <Entity.Parcel>();

            // Act
            var result1 = comparer.GetHashCode(o1);
            var result2 = comparer.GetHashCode(o2);

            // Assert
            result1.Should().Be(result2);
        }
예제 #29
0
        /// <summary>
        /// Creates a new instance of a Building.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parcel"></param>
        /// <param name="id"></param>
        /// <param name="localId"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="agency"></param>
        /// <returns></returns>
        public static Entity.Building CreateBuilding(this PimsContext context, Entity.Parcel parcel, int id, string projectNumber = null, string localId = null, int lat = 0, int lng = 0, Entity.Agency agency = null)
        {
            localId ??= $"l{id}";
            agency ??= parcel.Agency;
            var address          = EntityHelper.CreateAddress(id, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.City, parcel.Address.Province, parcel.Address.Postal);
            var predominateUse   = context.BuildingPredominateUses.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingPredominateUse("use");;
            var constructionType = context.BuildingConstructionTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingConstructionType("type");
            var occupantType     = context.BuildingOccupantTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingOccupantType("occupant");
            var classification   = context.PropertyClassifications.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreatePropertyClassification("classification");

            var building = new Entity.Building(parcel, lat, lng)
            {
                Id                         = id,
                ProjectNumber              = projectNumber,
                LocalId                    = localId,
                AgencyId                   = agency.Id,
                Agency                     = agency,
                AddressId                  = address.Id,
                Address                    = address,
                Classification             = classification,
                ClassificationId           = classification.Id,
                Description                = $"description-{id}",
                BuildingPredominateUse     = predominateUse,
                BuildingPredominateUseId   = predominateUse.Id,
                BuildingConstructionType   = constructionType,
                BuildingConstructionTypeId = constructionType.Id,
                BuildingOccupantType       = occupantType,
                BuildingOccupantTypeId     = occupantType.Id,
                CreatedById                = Guid.NewGuid(),
                CreatedOn                  = DateTime.UtcNow,
                UpdatedById                = Guid.NewGuid(),
                UpdatedOn                  = DateTime.UtcNow,
                RowVersion                 = new byte[] { 12, 13, 14 }
            };

            parcel.Buildings.Add(building);
            context.Buildings.Add(building);
            return(building);
        }
예제 #30
0
        public void ExportProperties_Excel_Query_Success(Uri uri)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <PropertyController>(Permissions.PropertyView, uri);
            var headers    = helper.GetService <Mock <Microsoft.AspNetCore.Http.IHeaderDictionary> >();

            headers.Setup(m => m["Accept"]).Returns(ContentTypes.CONTENT_TYPE_EXCEL);

            var parcel1 = new Entity.Parcel(1, 51, 25)
            {
                Id = 1
            };
            var parcel2 = new Entity.Parcel(2, 51, 26)
            {
                Id = 2
            };
            var parcels = new[] { parcel1, parcel2 };

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();
            var items   = parcels.Select(p => new Entity.Views.Property(p));
            var page    = new Paged <Entity.Views.Property>(items);

            service.Setup(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>())).Returns(page);

            // Act
            var result = controller.ExportProperties();

            // Assert
            var actionResult = Assert.IsType <FileStreamResult>(result);

            Assert.Equal(ContentTypes.CONTENT_TYPE_EXCELX, actionResult.ContentType);
            Assert.NotNull(actionResult.FileDownloadName);
            Assert.True(actionResult.FileStream.Length > 0);
            service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>()), Times.Once());
        }