internal static void SetCommonListingData(Listing listing,
                                                  string agencyId       = "XNWXNW",
                                                  StatusType statusType = StatusType.Available,
                                                  string description    =
                                                  "Don't pass up an opportunity like this! First to inspect will buy! Close to local amenities and schools. Features lavishly appointed bathrooms, modern kitchen, rustic outhouse.Don't pass up an opportunity like this! First to inspect will buy! Close to local amenities and schools. Features lavishly appointed bathrooms, modern kitchen, rustic outhouse.",
                                                  string title = "SHOW STOPPER!!!")
        {
            SetFeatures(listing, tags: CreateDefaultTags());
            listing.Address = FakeAddress.CreateAFakeAddress();
            listing.Agents  = FakeAgent.CreateFakeAgents().ToList();
            SetFloorPlans(listing);
            SetImages(listing);
            SetInspections(listing);
            SetLandDetails(listing);
            SetLinks(listing);
            SetVideos(listing);

            listing.AgencyId   = agencyId;
            listing.CreatedOn  = new DateTime(2009, 1, 1, 12, 30, 00, DateTimeKind.Utc);
            listing.UpdatedOn  = listing.CreatedOn;
            listing.StatusType = statusType;
            SetSourceStatus(listing);
            listing.Description = description;
            listing.Title       = title;
        }
Exemplo n.º 2
0
        public static T CreateAFakeListing <T>(string id             = null,
                                               StatusType statusType = StatusType.Unknown) where T : Listing, new()
        {
            // NBuilder fails to return the last enum type, here :(
            // var statusType = GetRandom.Enumeration<StatusType>();

            var values      = EnumHelper.GetValues(typeof(StatusType));
            var randomIndex = _random.Next(0, values.Length);

            if (statusType == StatusType.Unknown)
            {
                statusType = (StatusType)values.GetValue(randomIndex);
                if (statusType == StatusType.Unknown)
                {
                    statusType = StatusType.Available;
                }
            }

            var createdOn = GetRandom.DateTime(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow.AddDays(-1));

            createdOn = DateTime.SpecifyKind(createdOn, DateTimeKind.Utc);

            var updatedOn = GetRandom.DateTimeFrom(DateTime.UtcNow.AddDays(-1));

            updatedOn = DateTime.SpecifyKind(updatedOn, DateTimeKind.Utc);

            // Yep, copied from FakeCommonListingHelpers because that is method is (correctly) internal :/
            var listing = Builder <T> .CreateNew()
                          .With(x => x.Id, id ?? $"listing-{GetRandom.Int()}")
                          .With(x => x.AgencyId, $"Agency-{GetRandom.String(6)}")
                          .With(x => x.StatusType, statusType)           // NOTE: SourceStatus is defined AFTER this instance is created.
                          .With(x => x.Address, FakeAddress.CreateAFakeAddress())
                          .With(x => x.Agents, FakeAgent.CreateFakeAgents())
                          .With(x => x.LandDetails, CreateLandDetails())
                          .With(x => x.Features, CreateFeatures())
                          .With(x => x.CreatedOn, createdOn)
                          .With(x => x.UpdatedOn, updatedOn)
                          .With(x => x.Images, CreateMedia(GetRandom.Int(1, 21)))
                          .With(x => x.FloorPlans, CreateMedia(GetRandom.Int(0, 3)))
                          .With(x => x.Documents, CreateMedia(GetRandom.Int(0, 4)))
                          .With(x => x.Inspections, CreateInspections(GetRandom.Int(0, 4)))
                          .With(x => x.Videos, CreateMedia(GetRandom.Int(0, 3), "application/octet-stream"))
                          .Do(x =>
            {
                if (x is ResidentialListing residentialListing)
                {
                    // Skip first enumeration -> Unknown.
                    var index = GetRandom.Int(1, Enum.GetValues(typeof(PropertyType)).Length);
                    residentialListing.PropertyType    = (PropertyType)Enum.GetValues(typeof(PropertyType)).GetValue(index);
                    residentialListing.AuctionOn       = CreateDateTimeAsUtcKind(100);
                    residentialListing.BuildingDetails = CreateBuildingDetails();
                    residentialListing.Pricing         = CreateSalePricing(residentialListing.StatusType);
                }
                else if (x is RentalListing rentalListing)
                {
                    var index = GetRandom.Int(1, Enum.GetValues(typeof(PropertyType)).Length);
                    rentalListing.PropertyType    = (PropertyType)Enum.GetValues(typeof(PropertyType)).GetValue(index);
                    rentalListing.AvailableOn     = CreateDateTimeAsUtcKind(1000);
                    rentalListing.BuildingDetails = CreateBuildingDetails();
                    rentalListing.Pricing         = CreateRentalPricing(rentalListing.StatusType);
                }
                else if (x is LandListing landListing)
                {
                    var index = GetRandom.Int(1, Enum.GetValues(typeof(CategoryType)).Length);
                    landListing.CategoryType = (CategoryType)Enum.GetValues(typeof(CategoryType)).GetValue(index);
                    landListing.AuctionOn    = CreateDateTimeAsUtcKind(100);
                    landListing.Estate       = Builder <LandEstate> .CreateNew().Build();
                    landListing.Pricing      = CreateSalePricing(landListing.StatusType);
                }
                else if (x is RuralListing ruralListing)
                {
                    var index = GetRandom.Int(1, Enum.GetValues(typeof(Core.Rural.CategoryType)).Length);
                    ruralListing.CategoryType    = (Core.Rural.CategoryType)Enum.GetValues(typeof(Core.Rural.CategoryType)).GetValue(index);
                    ruralListing.AuctionOn       = CreateDateTimeAsUtcKind(100);
                    ruralListing.Pricing         = CreateSalePricing(ruralListing.StatusType);
                    ruralListing.RuralFeatures   = Builder <RuralFeatures> .CreateNew().Build();
                    ruralListing.BuildingDetails = CreateBuildingDetails();
                }
            }).Build();

            FakeCommonListingHelpers.SetSourceStatus(listing);

            return(listing);
        }