Ejemplo n.º 1
0
        public void HouseHoldCreateNotPassA()
        {
            //Arrange
            bool expected = false;
            bool actual   = false;
            //Act
            HouseHoldService hhs     = new HouseHoldService(hdao);
            HouseHold        request = new HouseHold(1000.00, "Testing address", 92868, false);
            int newHouse1            = hhs.CreateHouseHold(request);
            int newHouse2            = hhs.CreateHouseHold(request);

            if (newHouse2 > 0)
            {
                actual = true;
            }
            Console.WriteLine("First HID is " + newHouse1);
            Console.WriteLine("Second HID is " + newHouse2 + " if is 0 then test pass\nCreateHouseHold will return 0 when this address is already used");
            hhs.DeleteHouseHold(newHouse1);
            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void HouseHoldListingCreateNotPass()
        {
            //Arrange
            bool expected = false;
            //Act
            HouseHoldService hhs     = new HouseHoldService(hdao);
            HouseHold        request = new HouseHold(1000.00, "Testing address", 92868, false);

            int     newID  = hhs.CreateHouseHold(request);
            IResult result = hhs.CreateHouseHoldListing(newID + 1);
            bool    actual = result.IsSuccess;

            Console.WriteLine(result.Message);
            hhs.DeleteHouseHold(newID);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void HouseHoldCreateNotPassB()
        {
            //Arrange
            bool expected = false;
            bool actual   = false;
            //Act
            HouseHoldService hhs     = new HouseHoldService(hdao);
            HouseHold        request = new HouseHold(1000.00, "Testing address", 999999, false);
            int newID = hhs.CreateHouseHold(request);

            if (newID > 0)
            {
                actual = true;
            }
            Console.WriteLine("New HID is " + newID + " if is 0 then test pass\nCreateHouseHold will return 0 if this zip is not valid");
            hhs.DeleteHouseHold(newID);
            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        //Create a new HouseHold with an empty HouseHoldListing, if failed, return reasons that failed.
        // if successed return the new HouseHoldID
        public IResult CreateNewHouseHold(HouseholdCreationRequestDTO request)
        {
            String requester     = request.Requester;
            string streetAddress = request.StreetAddress;
            string city          = request.City;
            int    zip           = request.Zip;
            string suiteNumber   = request.SuiteNumber;
            double rent          = request.Rent;

            bool   ifValid = true;
            string message = "";

            ValidationService vs = new ValidationService();

            //Check input length for streetAddress
            IResult result = vs.LengthValidation(streetAddress, 200, 1);

            ifValid = IfUserExist(requester);

            if (ifValid)
            {
                if (!result.IsSuccess)
                {
                    ifValid  = false;
                    message += result.Message;
                }

                //Check input length for city
                result = vs.LengthValidation(city, 200, 1);
                if (!result.IsSuccess)
                {
                    ifValid  = false;
                    message += "\n" + result.Message;
                }

                //ZipCode for CA is from 90001 to 96162
                if (!vs.ZipValidation_CA(zip))
                {
                    ifValid  = false;
                    message += "\nInvalid ZipCode! This ZipCode does not exist in CA";
                }

                if (!vs.DecimalValidation(rent, 2))
                {
                    ifValid  = false;
                    message += "\nInvalid rent input! Should have no more than 2 decimal places";
                }
            }
            else
            {
                message += "\nThe User's ID doese not exist";
            }

            if (ifValid)
            {
                streetAddress = streetAddress + ", " + city + ", " + suiteNumber;
                //by defaut new household will be 'unavailable'
                HouseHold newHouseHold = new HouseHold(rent, streetAddress, zip, false);
                int       hId          = houseHoldService.CreateHouseHold(newHouseHold);

                if (hId > 0)
                {
                    message = hId.ToString();
                    IResult createEmptyHouseHoldListing = houseHoldService.CreateHouseHoldListing(hId);
                    ifValid = createEmptyHouseHoldListing.IsSuccess;
                    if (!ifValid)
                    {
                        message = createEmptyHouseHoldListing.Message;
                    }
                }
                else
                {
                    ifValid  = false;
                    message += "\nFailed to create new HouseHold! HouseHold Already exist";
                }
            }

            return(new CheckResult(message, ifValid));
        }